| 1699 | } |
| 1700 | |
| 1701 | void DFHack::Lua::Event::Invoke(color_ostream &out, lua_State *state, void *key, int num_args) |
| 1702 | { |
| 1703 | AssertCoreSuspend(state); |
| 1704 | |
| 1705 | int base = lua_gettop(state) - num_args; |
| 1706 | |
| 1707 | if (!lua_checkstack(state, num_args+4)) |
| 1708 | { |
| 1709 | out.printerr("Stack overflow in Lua::InvokeEvent"); |
| 1710 | lua_settop(state, base); |
| 1711 | return; |
| 1712 | } |
| 1713 | |
| 1714 | lua_rawgetp(state, LUA_REGISTRYINDEX, key); |
| 1715 | |
| 1716 | if (!lua_isuserdata(state, -1)) |
| 1717 | { |
| 1718 | if (!lua_isnil(state, -1)) |
| 1719 | out.printerr("Invalid event object in Lua::InvokeEvent"); |
| 1720 | lua_settop(state, base); |
| 1721 | return; |
| 1722 | } |
| 1723 | |
| 1724 | auto obj = (EventObject *)lua_touserdata(state, -1); |
| 1725 | lua_insert(state, base+1); |
| 1726 | |
| 1727 | if (obj->owner) |
| 1728 | obj->owner->on_invoked(state, num_args, true); |
| 1729 | |
| 1730 | lua_getuservalue(state, base+1); |
| 1731 | lua_replace(state, base+1); |
| 1732 | |
| 1733 | color_ostream *cur_out = Lua::GetOutput(state); |
| 1734 | set_dfhack_output(state, &out); |
| 1735 | dfhack_event_invoke(state, base, true); |
| 1736 | set_dfhack_output(state, cur_out); |
| 1737 | } |
| 1738 | |
| 1739 | void DFHack::Lua::Event::Make(lua_State *state, void *key, Owner *owner) |
| 1740 | { |
nothing calls this directly
no test coverage detected