Last active
August 12, 2023 01:16
-
-
Save lethosor/993338b9e99acb8c41797dce3ef9a6ea to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static int internal_listStructFields(lua_State *L) | |
{ | |
if (Lua::IsDFObject(L, 1) != Lua::OBJ_TYPE) | |
luaL_argerror(L, 1, "type expected"); | |
if (!lua_getmetatable(L, 1)) | |
luaL_error(L, "failed to retrieve type metatable"); | |
lua_rawgetp(L, 2, &DFHACK_IDENTITY_FIELD_TOKEN); | |
auto tid = static_cast<type_identity*>(lua_touserdata(L, 3)); | |
auto sid = dynamic_cast<struct_identity*>(tid); | |
if (!sid) | |
luaL_argerror(L, 1, "not a struct"); | |
lua_newtable(L); | |
for (auto psid = sid; psid; psid = psid->getParent()) | |
for (const struct_field_info *field = psid->getFields(); field && field->mode != struct_field_info::END; field++) | |
{ | |
// Core::print("%-16s off=%4zu: %s\n", field->name, field->offset, field->type ? field->type->getFullName().c_str() : "NULL"); | |
lua_pushstring(L, field->name); | |
lua_newtable(L); | |
Lua::TableInsert(L, "name", field->name); | |
Lua::TableInsert(L, "offset", field->offset); | |
if (field->type) { | |
Lua::TableInsert(L, "type_name", field->type->getFullName()); | |
lua_pushstring(L, "type"); | |
lua_rawgetp(L, LUA_REGISTRYINDEX, &DFHACK_TYPEID_TABLE_TOKEN); | |
lua_rawgetp(L, -1, field->type); | |
lua_remove(L, -2); // TYPEID_TABLE | |
lua_settable(L, -3); | |
} | |
lua_settable(L, -3); | |
// // Lua::TableInsert(L, "type", field->type); | |
// // push_object_internal(L, field->type, NULL, false); | |
// // push_adhoc_pointer(L, NULL, field->type); | |
// // if (lua_getmetatable(L, -1)) | |
// // lua_remove(L, -2); | |
// lua_pushstring(L, "type"); | |
// // lua_pushlightuserdata(L, field->type); | |
// // LookupInTable(L, field->type, &DFHACK_TYPEID_TABLE_TOKEN); | |
// lua_rawgetp(L, LUA_REGISTRYINDEX, &DFHACK_TYPEID_TABLE_TOKEN); | |
// lua_rawgetp(L, -1, field->type); | |
// // lua_rawgetp(L, LUA_REGISTRYINDEX, &DFHACK_TYPETABLE_TOKEN); | |
// // lua_rawgetp(L, -1, field->type); | |
// // lua_pushstring(L, field->type ? field->type->getFullName().c_str() : ""); | |
// // lua_rawget(L, -2); | |
// lua_remove(L, -2); | |
// lua_settable(L, -3); | |
} | |
// Core::print("DFHACK_IDENTITY_FIELD_TOKEN %p\n", &DFHACK_IDENTITY_FIELD_TOKEN); | |
// Core::print("DFHACK_TYPETABLE_TOKEN %p\n", &DFHACK_TYPETABLE_TOKEN); | |
// Core::print("DFHACK_TYPEID_TABLE_TOKEN %p\n", &DFHACK_TYPEID_TABLE_TOKEN); | |
// Core::print("DFHACK_ENUM_TABLE_TOKEN %p\n", &DFHACK_ENUM_TABLE_TOKEN); | |
// Core::print("DFHACK_PTR_IDTABLE_TOKEN %p\n", &DFHACK_PTR_IDTABLE_TOKEN); | |
// Core::print("DFHACK_EMPTY_TABLE_TOKEN %p\n", &DFHACK_EMPTY_TABLE_TOKEN); | |
// Core::print("%p\n", &DFHACK_TYPEID_TABLE_TOKEN); | |
// lua_rawgetp(L, LUA_REGISTRYINDEX, &DFHACK_TYPETABLE_TOKEN); | |
return 1; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment