qcode
  • 创作工场专业版,一问多答!更智能、更完整、更原创
  • 这是一个超强内容创作平台,它会写文章、做设计、绘图、敲代码,有问必答!
🔥点击使用-高级专业版🔥

static int IterateOverMobs(lua_State* L)

时间2023-03-22 23:47:19 提问来自 上海市上海市 的网友 分类创作 浏览448
lua_pushnil(L); while (lua_next(L, -2) != 0) { if (lua_isuserdata(L, -1)) { Mob* mob = static_cast<Mob*>(lua_touserdata(L, -1)); if (mob != nullptr && lua_pcall(L, 1, 0, 0) != 0) { #if defined(_DEBUG) || defined(_EQDEBUG) Log.Out(Logs::General, Logs::Lua, "Error running ForEachMob iterator function: %s", lua_tostring(L,-1)); //error message should be on top of the stack from lua. if its not print a general error. Shouldn't happen unless there is an actual bug in Lua code. #endif lua_pop(L,-1);//pop the error msg from the stack since we are not going to propagate it back up to C code. The Lua code needs to handle it itself if its gonna handle errors at all. } } else { //not a Mob object so skip it and leave it on the stack for next iteration of loop to find. This could happen if someone passed something other than a Mob object into this function call in Lua land ie: ForEachMob({}) or something like that.. lua_pop(L,-1);//Remove value but keep key for next iteration } }//end while loop over table elements return 0;//no return values.. all work done by side effect of iter func call above... }

点击这里,进行内容创作

创作工场 免责声明:
以上内容除特别注明外均来源于网友提问,创作工场回答,未经许可,严谨转载。
点击这里>>使用🔥专业版,更聪明、更完整、更原创!

上一篇 static int ForEachMob(lua_State* L) { 下一篇 作为一名新时代青年大学生,我们能够为经济社会发展绿色转型做些什么