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

Function FillBitfieldKeys

library/LuaWrapper.cpp:1562–1595  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1560}
1561
1562static void FillBitfieldKeys(lua_State *state, int ix_meta, int ftable, bitfield_identity *eid)
1563{
1564 // Create a new table attached to ftable as __index
1565 lua_newtable(state);
1566 int base = lua_gettop(state);
1567 lua_newtable(state);
1568
1569 auto bits = eid->getBits();
1570
1571 for (int i = 0; i < eid->getNumBits(); i++)
1572 {
1573 if (bits[i].name)
1574 AssociateId(state, base+1, i, bits[i].name);
1575 if (bits[i].size > 1)
1576 i += bits[i].size-1;
1577 }
1578
1579 lua_pushvalue(state, base+1);
1580 lua_pushinteger(state, -1);
1581 lua_pushinteger(state, eid->getNumBits()-1);
1582 lua_pushcclosure(state, wtype_ipairs, 3);
1583 lua_setfield(state, ix_meta, "__ipairs");
1584
1585 lua_pushinteger(state, 0);
1586 lua_setfield(state, ftable, "_first_item");
1587
1588 lua_pushinteger(state, eid->getNumBits()-1);
1589 lua_setfield(state, ftable, "_last_item");
1590
1591 SaveInTable(state, eid, &DFHACK_ENUM_TABLE_TOKEN);
1592
1593 lua_setfield(state, base, "__index");
1594 lua_setmetatable(state, ftable);
1595}
1596
1597static void RenderType(lua_State *state, const compound_identity *node)
1598{

Callers 1

RenderTypeFunction · 0.85

Calls 6

lua_gettopFunction · 0.85
lua_pushvalueFunction · 0.85
lua_pushintegerFunction · 0.85
lua_pushcclosureFunction · 0.85
lua_setfieldFunction · 0.85
lua_setmetatableFunction · 0.85

Tested by

no test coverage detected