From 24648db2b5bc9762e0acf06d4e432cffa8956349 Mon Sep 17 00:00:00 2001 From: yinjimmy Date: Wed, 24 Dec 2014 02:18:29 +0800 Subject: [PATCH] execute script with full file path --- .../lua-bindings/manual/CCLuaStack.cpp | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) 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)