cocos2d-x + Lua(2) C++和lua数据通讯之间的互调(3)
来源:未知 责任编辑:责任编辑 发表时间:2014-05-10 12:17 点击:次
p> lua_pushstring(ls, keyName);
p> lua_gettable(ls, -2);
p> const char* valueString = lua_tostring(ls, -1);
p>
p> lua_pop(ls, -1);
p>
p> return valueString;
p>}
p>//执行Lua表,返回表结构
p>const char* PublicSendLuaData::getLuaVarTable(const char* luaFileName,const char* varName){
p> lua_State* ls = CCLuaEngine::defaultEngine()->getLuaStack()->getLuaState();
p>
p> int isOpen = luaL_dofile(ls, getFileFullPath(luaFileName));
p> if(isOpen!=0){
p> CCLOG("Open Lua Error: %i", isOpen);
p> return NULL;
p> }
p>
p> lua_getglobal(ls, varName);
p>
p> int it = lua_gettop(ls);
p> lua_pushnil(ls);
p>
p> string result="";
p>
p> while(lua_next(ls, it))
p> {
p> string key = lua_tostring(ls, -2);
p> string value = lua_tostring(ls, -1);
p>
p> result=result+key+":"+value+"\t";
p>
p> lua_pop(ls, 1);
p> }
p> lua_pop(ls, 1);
p>
p> return result.c_str();
p>}
p>
p>//带参执行Lua方法有返回值
p>const char* PublicSendLuaData::callLuaFuncParReturn(const char* luaFileName,const char* functionName,CCArray* arraypar,CCArray* arraypartype){
p> lua_State* ls = CCLuaEngine::defaultEngine()->getLuaStack()->getLuaState();
p>
p> int isOpen = luaL_dofile(ls, getFileFullPath(luaFileName));
p> if(isOpen!=0){
p> CCLOG("Open Lua Error: %i", isOpen);
p> return NULL;
p> }
p>
p> lua_getglobal(ls, functionName);
p> int countnum = arraypar->count();
p> if(countnum>0)
p> {
p> for (int i = 0; i<arraypar->count(); i++) {
p> CCString* typestr = (CCString*)arraypartype->objectAtIndex(i);
p> CCString* strnr = (CCString*)arraypar->objectAtIndex(i);
p> if(typestr->isEqual(CCString::create("string")))
p> {
p> lua_pushstring(ls, strnr->getCString());
p> }
相关新闻>>
最新推荐更多>>>
- 发表评论
-
- 最新评论 更多>>