Fix ComponentTest in la-test can not load lua file under iOS & Android

This commit is contained in:
XiaoFeng 2015-11-03 15:49:46 +08:00
parent f76b941415
commit 3223a97b26
1 changed files with 6 additions and 1 deletions

View File

@ -139,7 +139,12 @@ bool ComponentLua::loadAndExecuteScript()
lua_State *l = engine->getLuaStack()->getLuaState();
// load script
int error = luaL_loadfile(l, _scriptFileName.c_str());
auto fileUtils = FileUtils::getInstance();
std::string fullPathOfScript = fileUtils->fullPathForFilename(_scriptFileName);
Data data = fileUtils->getDataFromFile(fullPathOfScript);
int error = LUA_ERRFILE;
if(data.getSize() > 0)
error = engine->getLuaStack()->luaLoadBuffer(l, (const char*)data.getBytes(), (int)data.getSize(), fullPathOfScript.c_str());
if (error)
{
CCLOG("ComponentLua::loadAndExecuteScript: %s", lua_tostring(l, -1));