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

Function dfhack_event_invoke

library/LuaTools.cpp:1646–1684  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1644}
1645
1646static void dfhack_event_invoke(lua_State *L, int base, bool from_c)
1647{
1648 int event = base+1;
1649 int num_args = lua_gettop(L)-event;
1650
1651 int errorfun = base+2;
1652 lua_pushcfunction(L, dfhack_onerror);
1653 lua_insert(L, errorfun);
1654
1655 int argbase = base+3;
1656
1657 // stack: |base| event errorfun (args)
1658
1659 if (!from_c)
1660 {
1661 // Invoke the NULL key first
1662 lua_rawgetp(L, event, NULL);
1663
1664 if (lua_isnil(L, -1))
1665 lua_pop(L, 1);
1666 else
1667 do_invoke_event(L, argbase, num_args, errorfun);
1668 }
1669
1670 lua_pushnil(L);
1671
1672 // stack: |base| event errorfun (args) key || cb (args)
1673
1674 while (lua_next(L, event))
1675 {
1676 // Skip the NULL key in the main loop
1677 if (is_null_userdata(L, -2))
1678 lua_pop(L, 1);
1679 else
1680 do_invoke_event(L, argbase, num_args, errorfun);
1681 }
1682
1683 lua_settop(L, base);
1684}
1685
1686static int dfhack_event_call(lua_State *state)
1687{

Callers 2

dfhack_event_callFunction · 0.85
InvokeMethod · 0.85

Calls 7

lua_gettopFunction · 0.85
lua_rawgetpFunction · 0.85
do_invoke_eventFunction · 0.85
lua_pushnilFunction · 0.85
lua_nextFunction · 0.85
is_null_userdataFunction · 0.85
lua_settopFunction · 0.85

Tested by

no test coverage detected