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

Method IsDFObject

library/LuaWrapper.cpp:430–459  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

428}
429
430Lua::ObjectClass Lua::IsDFObject(lua_State *state, int val_index)
431{
432 if (lua_isnil(state, val_index))
433 return Lua::OBJ_NULL;
434 if (lua_islightuserdata(state, val_index))
435 return lua_touserdata(state, val_index) ? Lua::OBJ_VOIDPTR : OBJ_NULL;
436
437 Lua::ObjectClass cls;
438
439 if (lua_istable(state, val_index))
440 {
441 cls = Lua::OBJ_TYPE;
442 lua_pushvalue(state, val_index);
443 LookupInTable(state, &DFHACK_TYPEID_TABLE_TOKEN);
444 }
445 else if (lua_isuserdata(state, val_index))
446 {
447 if (!lua_getmetatable(state, val_index))
448 return Lua::OBJ_INVALID;
449 cls = Lua::OBJ_REF;
450 LookupInTable(state, &DFHACK_TYPETABLE_TOKEN);
451 }
452 else
453 return Lua::OBJ_INVALID;
454
455 bool ok = !lua_isnil(state, -1);
456 lua_pop(state, 1);
457
458 return ok ? cls : Lua::OBJ_INVALID;
459}
460
461static const char *const primitive_types[] = {
462 "string",

Callers

nothing calls this directly

Calls 5

lua_touserdataFunction · 0.85
lua_pushvalueFunction · 0.85
LookupInTableFunction · 0.85
lua_isuserdataFunction · 0.85
lua_getmetatableFunction · 0.85

Tested by

no test coverage detected