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

Method push_object_internal

library/LuaWrapper.cpp:202–239  ·  view source on GitHub ↗

* Push the pointer using given identity. */

Source from the content-addressed store, hash-verified

200 * Push the pointer using given identity.
201 */
202void LuaWrapper::push_object_internal(lua_State *state, const type_identity *type, void *ptr, bool in_method)
203{
204 /*
205 * If NULL pointer or no type, push something simple
206 */
207
208 if (!ptr || !type)
209 {
210 if (!ptr)
211 lua_pushnil(state);
212 else
213 lua_pushlightuserdata(state, ptr);
214
215 return;
216 }
217
218 /*
219 * Resolve actual class using vtable
220 */
221
222 if (type->type() == IDTYPE_CLASS)
223 {
224 const virtual_identity *class_vid = virtual_identity::get(virtual_ptr(ptr));
225 if (class_vid)
226 type = class_vid;
227 }
228
229 /*
230 * Resolve metatable by identity, and push the object
231 */
232
233 lua_pushlightuserdata(state, const_cast<type_identity*>(type)); // () -> type
234
235 if (!LookupTypeInfo(state, in_method)) // type -> metatable?
236 BuildTypeMetatable(state, type); // () -> metatable
237
238 push_object_ref(state, ptr); // metatable -> userdata
239}
240
241static void fetch_container_details(lua_State *state, int meta, const type_identity **pitem, int *pcount)
242{

Callers

nothing calls this directly

Calls 5

lua_pushnilFunction · 0.85
lua_pushlightuserdataFunction · 0.85
BuildTypeMetatableFunction · 0.85
getFunction · 0.50
typeMethod · 0.45

Tested by

no test coverage detected