| 2156 | } |
| 2157 | |
| 2158 | int LuaParser::_EventZone( |
| 2159 | std::string package_name, |
| 2160 | QuestEventID evt, |
| 2161 | Zone *zone, |
| 2162 | std::string data, |
| 2163 | uint32 extra_data, |
| 2164 | std::vector<std::any> *extra_pointers, |
| 2165 | luabind::adl::object *l_func |
| 2166 | ) { |
| 2167 | const char *sub_name = LuaEvents[evt]; |
| 2168 | int start = lua_gettop(L); |
| 2169 | |
| 2170 | try { |
| 2171 | int npop = 2; |
| 2172 | PushErrorHandler(L); |
| 2173 | if(l_func != nullptr) { |
| 2174 | l_func->push(L); |
| 2175 | } else { |
| 2176 | lua_getfield(L, LUA_REGISTRYINDEX, package_name.c_str()); |
| 2177 | lua_getfield(L, -1, sub_name); |
| 2178 | npop = 3; |
| 2179 | } |
| 2180 | |
| 2181 | lua_createtable(L, 0, 0); |
| 2182 | //push self |
| 2183 | Lua_Zone l_zone(zone); |
| 2184 | luabind::adl::object l_zone_o = luabind::adl::object(L, l_zone); |
| 2185 | l_zone_o.push(L); |
| 2186 | lua_setfield(L, -2, "self"); |
| 2187 | |
| 2188 | auto arg_function = ZoneArgumentDispatch[evt]; |
| 2189 | arg_function(this, L, zone, data, extra_data, extra_pointers); |
| 2190 | |
| 2191 | RunningQuest q; |
| 2192 | |
| 2193 | q.zone = zone; |
| 2194 | |
| 2195 | quest_manager.StartQuest(q); |
| 2196 | |
| 2197 | if(lua_pcall(L, 1, 1, start + 1)) { |
| 2198 | std::string error = lua_tostring(L, -1); |
| 2199 | AddError(error); |
| 2200 | quest_manager.EndQuest(); |
| 2201 | lua_pop(L, npop); |
| 2202 | return 0; |
| 2203 | } |
| 2204 | quest_manager.EndQuest(); |
| 2205 | |
| 2206 | if(lua_isnumber(L, -1)) { |
| 2207 | int ret = static_cast<int>(lua_tointeger(L, -1)); |
| 2208 | lua_pop(L, npop); |
| 2209 | return ret; |
| 2210 | } |
| 2211 | |
| 2212 | lua_pop(L, npop); |
| 2213 | } catch(std::exception &ex) { |
| 2214 | AddError( |
| 2215 | fmt::format( |
nothing calls this directly
no test coverage detected