static int forEachCreature(lua_State* L) { RoomData* room = reinterpret_cast<RoomData*>(lua_touserdata(L, 1)); CreatureManager* creatureMgr = room->GetCreatureMgr(); //pass each creature to the given function for (auto& it : *creatureMgr->GetContainer()) { lua_pushvalue(L, -1); lua_pushlightuserdata(L, static_cast<void*>(&it.second)); //call each iteration, throwing an exception if something happened if (lua_pcall(L, 1, 0, 0) != LUA_OK) { std::ostringstream os; os << "Lua error: "; os << lua_tostring(L, -1); throw(std::runtime_error(os.str())); } } return 0; }
static int getCreatureMgr(lua_State* L) { RoomData* room = reinterpret_cast<RoomData*>(lua_touserdata(L, 1)); lua_pushlightuserdata(L, reinterpret_cast<void*>(room->GetCreatureMgr()) ); return 1; }