在我的应用程序中,我想在加载 lua 脚本之前在 Lua 中加载一个基础库。
例子:
测试库.lua
A = 5
B = 6
function foo(a,b)
return a+b
end
测试.lua
c = foo(A,B)
在我的 C++ 模块中,我想做这样的事情
// load the lib
luaL_loadbuffer(L, libText, libSize, "testLib");
// run it so that the globals are known
lua_pcall(L,0,0,0);
// load the main script that uses the lib function and variables
luaL_loadbuffer(L, progText, progSize, "testLib");
// run it
lua_pcall(L,0,0,0);
这里我得到一个错误,函数'foo'是未知的
有没有办法在同一个 lua 状态下加载多个 Lua 模块?
提前感谢您的帮助
最佳答案
关于c++ - 嵌入式 Lua C++ : how can i load multiple lua modules from C++ side,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9411809/