【问题标题】:embedded Lua C++ : how can i load multiple lua modules from C++ side嵌入式 Lua C++:如何从 C++ 端加载多个 lua 模块
【发布时间】:2012-03-13 18:50:34
【问题描述】:

在我的应用程序中,我想在加载 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 模块?

提前感谢您的帮助

【问题讨论】:

    标签: c++ module lua loading


    【解决方案1】:

    您需要先绑定函数 foo。

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

    在绑定 c 数学函数的示例中展示了如何做到这一点

    【讨论】:

    • 嗨,Markus,感谢重播。问题是,我不想重新编译 C++ 模块。脚本位于 SD 卡上。所以绑定函数是没有选择的。
    猜你喜欢
    • 2015-05-18
    • 2011-05-30
    • 2012-04-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-23
    • 1970-01-01
    • 2011-05-02
    相关资源
    最近更新 更多