-
(Under Linux)cannot find ‘dlsym’ ‘dlopen’ ‘dlerror’ ‘dlclose’
需要同时链接”dl“库
-
(Under Linux)编译lua报错luaconf.h:275:31: error: readline/readline.h: No such file or directory
需要下载并安装GNU Readline Library
-
PANIC: unprotected error in call to Lua API (unable to get ModuleFileName)
1: 不推荐的解决方式:将Project Properties->Configuration Properties->General下的Character Set从unicode改成multi-set;
2: 彻底的解决方式,参考此链接:http://lua-users.org/lists/lua-l/2006-06/msg00427.html -
如何将Lua文本文件转化为Lua块文件(chunk file)
调用LuaAPI – lua_dump
关于lua_dump: about lua_dump: Dumps a function as a binary chunk. Receives a Lua function on the top of the stack and produces a binary chunk that, if loaded again, results in a function equivalent to the one dumped. As it produces parts of the chunk, lua_dump calls function writer (see lua_Writer) with the given data to write them.
-
如何在C中调用Lua脚本层的库函数
void BeginLuaLibCall( lua_State *L, const string &libName, const string &functionName ) { lua_pushstring( L, libName.c_str() ); lua_gettable( L, LUA_GLOBALSINDEX ); lua_pushstring( L, functionName.c_str() ); lua_gettable( L, -2 ); } void EndLuaLibCall( lua_State *L ) { lua_pop( L, -1 ); }
示例:调用table.getn(该函数用来获取一个table的size)
// 利用上面的函数 BeginLuaLibCall( L, "table", "getn" ); // 假设你的脚本中有一个table变量myTable,获取它到栈顶 lua_getglobal( L, "myTable" ); // 执行table.getn( t ) lua_call( L, 1, 1 ); // 打印结果 std::cout << lua_tonumber( L, -1 ) ) << std::endl; // 将结果弹出栈 lua_pop( L, -1 ); // 将名叫“table”的table弹出栈 EndLuaLibCall( L);
Recent Comments