static int ForEachMob(lua_State* L) {
lua_pushnil(L);
while (lua_next(L, -2) != 0) {
int ref = luaL_ref(L, LUA_REGISTRYINDEX);
if (lua_pcall(L, 0, 0, 0) != LUA_OK) {
const char* err = lua_tostring(L, -1);
#ifdef _DEBUG
#ifndef WIN32
printf("Lua Error: %s\n", err); // TODO: Log this error. Or maybe just add it to the Lua script? See below.
#else
OutputDebugStringA("Lua Error: "); OutputDebugStringA(err); OutputDebugStringA("\n"); // TODO: Log this error. Or maybe just add it to the Lua script? See below.
#endif // !WIN32
lua_pop(L, 1);
luaL_unref(L, LUA_REGISTRYINDEX, ref);
return 1; // Return an error code here? Or maybe just add it to the Lua script so that we don't need to return anything? For now I'm returning an error code here and printing out the message above in debug builds only.
#endif // _DEBUG
} else {
luaL_unref(L, LUA_REGISTRYINDEX
创作工场
免责声明:
以上内容除特别注明外均来源于网友提问,创作工场回答,未经许可,严谨转载。
点击这里>>使用🔥专业版,更聪明、更完整、更原创!