*/#define TValuefields Value value_;lu_byte tt_ typedef struct TValue{TValuefields;}TValue; Value中包含各种实际类型需要用到的变量,其中GCobject用于存储需要被gc类型的地址,目前string, userdata, table, function, thread是需要gc的类型,其他几个字段分别用于存储lightuserdata指针,c导出的函数地址,整数,浮...
#define EXPORT_LUNA_FUNCTION_BEGIN(obj) \ const char* obj::name = #obj;\ luna<obj>::TMethod obj::methods[] = { #define EXPORT_LUNA_MEMBER_INT(obj, member) \ {#member, nullptr}, #define EXPORT_LUNA_FUNCTION(obj, func) \ {#func, &obj::func}, #define EXPORT_LUNA_FUNCTION_END(o...
LUALIB_API int (luaL_loadfilex) (lua_State *L, const char *filename, const char *mode); #define luaL_loadfile(L,f) luaL_loadfilex(L,f,NULL) LUALIB_API int (luaL_loadbufferx) (lua_State *L, const char *buff, size_t sz, const char *name, const char *mode); LUALIB_API i...
如上图所示,我们现在有一个test.lua的脚本,里面定义了两个local变量和一个函数,那么这个test.lua本身里面所有的代码就是一个chunk,这个chunk实际上也是一个function类型,我们称之为top-level function。test.lua脚本里,定义了一个foo函数,我们在编译的过程中,chunk因为也是一个function,因此会有一个FuncState结构和它...
那么,如果这个函数时我们自己写的CFunction呢,还能这么如愿么,看下面的代码: 例4 [C]例4 1//filename:funct.c23#defineLUA_LIB4#include <lua.h>5#include <lualib.h>6#include <lauxlib.h>78staticint_c_l_testfunc(lua_State*L)9{10unsignedcharargc, index;11constchar*typename;12if((argc = lua...
** #("function") = 8, #("__newindex") = 10.) */ #if !defined(LUAI_MAXSHORTLEN) #define LUAI_MAXSHORTLEN 40 #endif 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. /* ** checks whether short string exists and reuses it or creates a new one ...
#define luaL_dofile(L, fn) \(luaL_loadfile(L, fn) || lua_pcall(L, 0, LUA_MULTRET, 0)) 1. 2. LUA_MULTRET也是宏定义,值为-1,表示函数有多个返回值(Lua规则,pil 24.2--堆栈)。 扩展开来就是以下两句: 复制 luaL_loadfile(L, fn);lua_pcall(L, 0, LUA_MULTRET, 0); ...
lua_CFunction f; /* light C functions */ lua_Integer i; /* integer numbers */ lua_Number n; /* float numbers */ } Value; #define TValuefields Value value_; int tt_ typedef struct lua_TValue { TValuefields; } TValue; #define LUA_TNIL 0 ...
要实现c和lua之间的交互,先了解下lua中基本类型与c中类型怎么对应的。lua中有八种基本类型:nil、boolean、number、string、table、function、userdata、thread,其中,userdata分轻量用户数据(lightuserdata)和完成用户数据(userdata)两种。这些类型都可以压入栈中,在c中统一用TValue结构表示,是一个{值,类型}结构。
程序用一个巧妙的宏定义完成了检测,#define后面加上一个#号表示将参数字符串化,将其转换成一个字符串常量 if (LoadInteger(S) != LUAC_INT) if (LoadNumber(S) != LUAC_NUM) LUAC_INT : LUAC_NUM: 题目中给了一个lua5.33打包的elf文件和一个被魔改的 luac文件 ...