Merge branch '0.9.0'

This commit is contained in:
Guillaume Maury 2011-08-02 03:49:36 +08:00
commit f86da27a38
5 changed files with 36 additions and 1 deletions

View File

@ -65,6 +65,8 @@ public:
// execute a schedule function
virtual bool executeSchedule(const char* pszFuncName, ccTime t) = 0;
// add a search path
virtual bool addSearchPath(const char* pszPath) = 0;
};
/**

View File

@ -81,3 +81,9 @@ bool LuaEngine::executeSchedule(const char* pszFuncName, ccTime t)
{
return CCLuaScriptModule::sharedLuaScriptModule()->executeSchedule(pszFuncName, t);
}
bool LuaEngine::addSearchPath(const char* pszPath)
{
return CCLuaScriptModule::sharedLuaScriptModule()->addSearchPath(pszPath);
}

View File

@ -49,6 +49,8 @@ public:
// execute a schedule function
virtual bool executeSchedule(const char* pszFuncName, cocos2d::ccTime t);
// add a search path
virtual bool addSearchPath(const char* pszPath);
};
#endif // __LUA_ENGINE_H__

View File

@ -100,6 +100,23 @@ CCLuaScriptModule::~CCLuaScriptModule()
}
/*************************************************************************
Add a path to find lua files in (equivalent to LUA_PATH)
*************************************************************************/
bool CCLuaScriptModule::addSearchPath(const std::string& path)
{
lua_getglobal( d_state, "package" );
lua_getfield( d_state, -1, "path" ); // get field "path" from table at top of stack (-1)
const char* cur_path = lua_tostring( d_state, -1 ); // grab path string from top of stack
lua_pop( d_state, 1 ); // get rid of the string on the stack we just pushed on line 5
lua_pushfstring(d_state, "%s;%s/?.lua", cur_path, path.c_str());
lua_setfield( d_state, -2, "path" ); // set the field "path" in table at -2 with value at top of stack
lua_pop( d_state, 1 ); // get rid of package table from top of stack
return 0; // all done!
}
/*************************************************************************
Execute script file
*************************************************************************/

View File

@ -60,7 +60,15 @@ public:
@brief Destructor for LuaScriptModule class.
*/
virtual ~CCLuaScriptModule();
/*************************************************************************
Seting Functions
*************************************************************************/
/**
@brief Add a path to find lua files in
@param path to be added to the Lua path
*/
bool addSearchPath(const std::string& path);
/*************************************************************************
Script Execution Functions