MCPcopy Create free account
hub / github.com/DFHack/dfhack / Invoke

Method Invoke

library/LuaTools.cpp:1701–1737  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1699}
1700
1701void 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
1739void DFHack::Lua::Event::Make(lua_State *state, void *key, Owner *owner)
1740{

Callers

nothing calls this directly

Calls 11

AssertCoreSuspendFunction · 0.85
lua_gettopFunction · 0.85
lua_checkstackFunction · 0.85
lua_settopFunction · 0.85
lua_rawgetpFunction · 0.85
lua_isuserdataFunction · 0.85
lua_touserdataFunction · 0.85
lua_getuservalueFunction · 0.85
set_dfhack_outputFunction · 0.85
dfhack_event_invokeFunction · 0.85
on_invokedMethod · 0.80

Tested by

no test coverage detected