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

Function freeze_table

library/LuaWrapper.cpp:76–97  ·  view source on GitHub ↗

* Wrap a table so that it can't be modified. */

Source from the content-addressed store, hash-verified

74 * Wrap a table so that it can't be modified.
75 */
76static void freeze_table(lua_State *state, bool leave_metatable = false, const char *name = NULL)
77{
78 // rv = {}; setmetatable(rv, { __index = in, __newindex = change_error, __metatable = name })
79 int base = lua_gettop(state);
80 lua_newtable(state);
81 lua_swap(state);
82 lua_setfield(state, base, "__index");
83 lua_getfield(state, LUA_REGISTRYINDEX, DFHACK_CHANGEERROR_NAME);
84 lua_setfield(state, base, "__newindex");
85 lua_newtable(state);
86 lua_swap(state);
87 lua_dup(state);
88 lua_setmetatable(state, base);
89 if (name)
90 {
91 lua_pushstring(state, name);
92 lua_setfield(state, -2, "__metatable");
93 }
94 // result: [frozen table] [metatable]
95 if (!leave_metatable)
96 lua_pop(state, 1);
97}
98
99static void LookupInTable(lua_State *state, LuaToken *tname)
100{

Callers 2

FillEnumKeysFunction · 0.85
DoAttachFunction · 0.85

Calls 7

lua_gettopFunction · 0.85
lua_swapFunction · 0.85
lua_setfieldFunction · 0.85
lua_getfieldFunction · 0.85
lua_dupFunction · 0.85
lua_setmetatableFunction · 0.85
lua_pushstringFunction · 0.85

Tested by

no test coverage detected