lua_pushinteger void lua_pushinteger (lua_State *L, lua_Integer n); 把n作为一个数字压栈。 lua_pushlightuserdata void lua_pushlightuserdata (lua_State *L, void *p); 把一个 light userdata 压栈。 userdata 在 Lua 中表示一个 C 值。 li
void lua_pushinteger(lua_State *L, lua_Integer n) void lua_pushlstring(lua_State *L,constchar* s,size_t l) void lua_pushstring(lua_State *L,constchar *s) constchar* lua_pushvfstring(lua_State *L,constchar *fmt,va_list argp) constchar* lua_pushfstring(lua_State *L,constchar *...
function:C 函数(函数指针)。 最佳实践:使用该函数可以将自定义的 C 函数注册为 Lua 函数,以便在 Lua 环境中调用。 注意事项: 通过lua_pushcfunction函数将 C 函数压入堆栈后,可以使用lua_setglobal或其他相应的函数将其绑定到全局变量或其他表中,以供 Lua 脚本调用。 注册的 C 函数必须具有特定的函数签名(lu...
lua_pushinteger(L, 123); // 推送一个整数 lua_pushstring(L, "hello"); // 推送一个字符串 // 检查栈的大小 if (lua_gettop(L) > MAX_STACK_SIZE) { lua_pop(L, lua_gettop(L)); // 弹出所有数据 fprintf(stderr, "Stack overflow!\n"); return; } ...
lua_pushinteger(L, argc); /* 1st argument */ lua_pushlightuserdata(L, argv); /* 2nd argument */ status = lua_pcall(L, 2, 1, 0); /* do the call */ result = lua_toboolean(L, -1); /* get result */ report(L, status); ...
博客地址:构建Lua解释器Part1:虚拟机的基础--Lua基本数据结构、栈和基于栈的C函数调用的设计与实现 特此感谢。 一、基本数据结构 Lua的基本类型,包括lua_Integer、lua_Number、lu_byte、lua_CFunction等,最典型的是其能够代表任何基本类型的TValue结构了。现在我们将逐一分析这些类型。
void lua_pushstring (lua_State *L, const char *s); 1. 2. 3. 4. 5. 6. 7. 查询栈里面的元素 int lua_is* (lua_State * L, int index); 1. 获取栈内给定位置的元素值 xxx lua_toXXX(lua_State * L, int index); 1. 这里面的xxx可以是nil, boolean, string,integer等等。
首先在C语言中实现add函数,并将其编译成一个动态链接库(例如add.so)。 #include <lua.h> #include <lauxlib.h> int add(lua_State *L) { int a = lua_tointeger(L, 1); int b = lua_tointeger(L, 2); lua_pushinteger(L, a + b); return 1; } 复制代码 在Lua中使用require加载动态链接库...
(L, -1, "x"); /\* push result of t.x (2nd arg) \*/ lua\_remove(L, -2); /\* remove 't' from the stack \*/ lua\_pushinteger(L, 14); /\* 3rd argument \*/ lua\_call(L, 3, 1); /\* call 'f' with 3 arguments and 1 result \*/ lua\_setglobal(L, "a"); ...
lua_pushstring void lua_pushstring (lua_State *L, const char *s); 把指针s指向的以零结尾的字符串压栈。 Lua 对这个字符串做一次内存拷贝(或是复用一个拷贝),因此s处的内存在函数返回后,可以释放掉或是重用于其它用途。字符串中不能包含有零字符;第一个碰到的零字符会认为是字符串的结束。