static int ForEachMob(lua_State* L) {
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...
}
创作工场
免责声明:
以上内容除特别注明外均来源于网友提问,创作工场回答,未经许可,严谨转载。
点击这里>>使用🔥专业版,更聪明、更完整、更原创!