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

Function dfhack_event_newindex

library/LuaTools.cpp:1603–1635  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1601}
1602
1603static int dfhack_event_newindex(lua_State *L)
1604{
1605 luaL_checktype(L, 1, LUA_TUSERDATA);
1606 if (is_null_userdata(L, 2))
1607 luaL_argerror(L, 2, "Key NULL is reserved in events.");
1608
1609 lua_settop(L, 3);
1610 lua_getuservalue(L, 1);
1611 bool new_nil = lua_isnil(L, 3);
1612
1613 lua_pushvalue(L, 2);
1614 lua_rawget(L, 4);
1615 bool old_nil = lua_isnil(L, -1);
1616 lua_settop(L, 4);
1617
1618 lua_pushvalue(L, 2);
1619 lua_pushvalue(L, 3);
1620 lua_rawset(L, 4);
1621
1622 int delta = 0;
1623 if (old_nil && !new_nil) delta = 1;
1624 else if (new_nil && !old_nil) delta = -1;
1625
1626 if (delta != 0)
1627 {
1628 auto obj = (EventObject *)lua_touserdata(L, 1);
1629 obj->item_count += delta;
1630 if (obj->owner)
1631 obj->owner->on_count_changed(obj->item_count, delta);
1632 }
1633
1634 return 0;
1635}
1636
1637static void do_invoke_event(lua_State *L, int argbase, int num_args, int errorfun)
1638{

Callers

nothing calls this directly

Calls 10

luaL_checktypeFunction · 0.85
is_null_userdataFunction · 0.85
luaL_argerrorFunction · 0.85
lua_settopFunction · 0.85
lua_getuservalueFunction · 0.85
lua_pushvalueFunction · 0.85
lua_rawgetFunction · 0.85
lua_rawsetFunction · 0.85
lua_touserdataFunction · 0.85
on_count_changedMethod · 0.80

Tested by

no test coverage detected