execute script with full file path

This commit is contained in:
yinjimmy 2014-12-24 02:18:29 +08:00
parent ca932a38e4
commit 24648db2b5
1 changed files with 14 additions and 4 deletions

View File

@ -274,10 +274,20 @@ int LuaStack::executeString(const char *codes)
int LuaStack::executeScriptFile(const char* filename) int LuaStack::executeScriptFile(const char* filename)
{ {
std::string code("require \""); CCAssert(filename, "CCLuaStack::executeScriptFile() - invalid filename");
code.append(filename);
code.append("\""); FileUtils *utils = FileUtils::getInstance();
return executeString(code.c_str()); std::string fullPath = utils->fullPathForFilename(filename);
Data data = utils->getDataFromFile(fullPath);
int rn = 0;
if (!data.isNull())
{
if (luaLoadBuffer(_state, (const char*)data.getBytes(), (int)data.getSize(), fullPath.c_str()) == 0)
{
rn = executeFunction(0);
}
}
return rn;
} }
int LuaStack::executeGlobalFunction(const char* functionName) int LuaStack::executeGlobalFunction(const char* functionName)