当在Android中运行时,Lua C函数没有被调用。

我有这种情况。在我继续讲述我的问题之前,请查看以下代码(我在标题中无法正确定义)。

我的Lua初始化代码:

luaState = luaL_newstate();
luaL_openlibs(luaState);
RegisterFunctions(luaState);

我的Lua加载代码:

try {
        luaL_dofile(luaState, scriptPath.c_str());
    }
    catch (...) {
        std::cout << "LUA ERROR: Could not load file " << std::endl;

    }
    loaded_.push_back(filename);

我定义C函数的部分:

int testFunction(lua_State* L)
{
    std::cout << "Test" << std::endl;
    return 0;
}
void RegisterFunctions(lua_State* L)
{
    lua_register(L, "testFunction", testFunction);

}

我的Lua脚本:

test = {};

function test:testCallback(me)
    testFunction();
end

这些代码在Android中能够正确构建和运行。然而,当testFunction()被调用时,它没有进入我定义的C函数。除此之外,一切都运行正常。我也在IOS上进行了测试,在IOS上,它也能进入testFunction。这个问题只发生在Android上,我很茫然。如果有任何建议,我将不胜感激。

点赞