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

Method SetPtrMethods

library/LuaWrapper.cpp:1187–1221  ·  view source on GitHub ↗

* Set metatable properties common to all actual DF object references. */

Source from the content-addressed store, hash-verified

1185 * Set metatable properties common to all actual DF object references.
1186 */
1187void LuaWrapper::SetPtrMethods(lua_State *state, int meta_idx, int read_idx)
1188{
1189 lua_getfield(state, LUA_REGISTRYINDEX, DFHACK_COMPARE_NAME);
1190 lua_setfield(state, meta_idx, "__eq");
1191
1192 lua_rawgetp(state, LUA_REGISTRYINDEX, &DFHACK_TYPETABLE_TOKEN);
1193 lua_pushvalue(state, meta_idx);
1194 lua_pushcclosure(state, meta_ptr_tostring, 2);
1195 lua_setfield(state, meta_idx, "__tostring");
1196
1197 EnableMetaField(state, read_idx, "_type");
1198 EnableMetaField(state, read_idx, "_kind");
1199
1200 EnableMetaField(state, read_idx, "_field");
1201
1202 lua_getfield(state, LUA_REGISTRYINDEX, DFHACK_SIZEOF_NAME);
1203 lua_setfield(state, meta_idx, "sizeof");
1204 EnableMetaField(state, read_idx, "sizeof");
1205
1206 lua_getfield(state, LUA_REGISTRYINDEX, DFHACK_NEW_NAME);
1207 lua_setfield(state, meta_idx, "new");
1208 EnableMetaField(state, read_idx, "new");
1209
1210 lua_getfield(state, LUA_REGISTRYINDEX, DFHACK_DELETE_NAME);
1211 lua_setfield(state, meta_idx, "delete");
1212 EnableMetaField(state, read_idx, "delete");
1213
1214 lua_getfield(state, LUA_REGISTRYINDEX, DFHACK_ASSIGN_NAME);
1215 lua_setfield(state, meta_idx, "assign");
1216 EnableMetaField(state, read_idx, "assign");
1217
1218 lua_getfield(state, LUA_REGISTRYINDEX, DFHACK_DISPLACE_NAME);
1219 lua_setfield(state, meta_idx, "_displace");
1220 EnableMetaField(state, read_idx, "_displace");
1221}
1222
1223/**
1224 * Add a __pairs/__ipairs metamethod using iterator on the top of stack.

Callers

nothing calls this directly

Calls 5

lua_getfieldFunction · 0.85
lua_setfieldFunction · 0.85
lua_rawgetpFunction · 0.85
lua_pushvalueFunction · 0.85
lua_pushcclosureFunction · 0.85

Tested by

no test coverage detected