diff --git a/cocos/scripting/lua-bindings/manual/CCLuaStack.cpp b/cocos/scripting/lua-bindings/manual/CCLuaStack.cpp index 5a918d57eb..8a33aa1434 100644 --- a/cocos/scripting/lua-bindings/manual/CCLuaStack.cpp +++ b/cocos/scripting/lua-bindings/manual/CCLuaStack.cpp @@ -274,10 +274,20 @@ int LuaStack::executeString(const char *codes) int LuaStack::executeScriptFile(const char* filename) { - std::string code("require \""); - code.append(filename); - code.append("\""); - return executeString(code.c_str()); + CCAssert(filename, "CCLuaStack::executeScriptFile() - invalid filename"); + + FileUtils *utils = FileUtils::getInstance(); + 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)