繁体   English   中英

嵌入式Lua C ++:如何从C ++端加载多个lua模块

[英]embedded Lua C++ : how can i load multiple lua modules from C++ side

在我的应用程序中,我想在加载lua脚本之前在Lua中加载一个基本库。

例:

testLib.lua

A = 5
B = 6

function foo(a,b)
    return a+b
end

test.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模块?

我在这里先向您的帮助表示感谢

你需要先绑定函数foo。

http://lua-users.org/wiki/BindingCodeToLua

显示了如何在绑定c数学函数的示例中执行此操作

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM