简体   繁体   中英

Call Lua script in xcode, an error occured

I have added all lua source files in xcode, then build successfully, but have error when run. after load the lua file, it comes out the error when use pcall method. Here is the code:

p_lua_stack_ = luaL_newstate();
luaL_openlibs(p_lua_stack_);
FilePathManager *m = [FilePathManager sharedInstance];
int r = luaL_loadfile(p_lua_stack_, [[m llkFacadeFilePath] UTF8String]);
DLog(@"%@", [m llkFacadeFilePath]);
DPRINT("%d", r);
//DPRINT("%d", lua_pcall(p_lua_stack_, 0, 0, 0));
int cr = lua_pcall(p_lua_stack_, 0, 0, 0);
LuaStateUtil *util = LuaStateUtil::GetSharedInstancePointer();
util->PrintPcallReturnValue(cr);  //print return value info
DPRINT("%s", lua_tostring(p_lua_stack_, -1)); //when run to this line, the output is...

The output is:...4-489C-4A40-8582-F734FAAC428D/LLK.app/llk_facade.lua:1: attempt to call global 'module' (a nil value)

Then I am totally confused because "module" is a library method of Lua. Who can help me, please?

maybe this question read a little hard, i'm not good at English.

如果是Lua 5.2,则需要通过定义LUA_COMPAT_MODULE来启用module

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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