| 396 | static int DFHACK_MATINFO_TOKEN = 0; |
| 397 | |
| 398 | void Lua::Push(lua_State *state, const MaterialInfo &info) |
| 399 | { |
| 400 | if (!info.isValid()) |
| 401 | { |
| 402 | lua_pushnil(state); |
| 403 | return; |
| 404 | } |
| 405 | |
| 406 | lua_newtable(state); |
| 407 | lua_rawgetp(state, LUA_REGISTRYINDEX, &DFHACK_MATINFO_TOKEN); |
| 408 | lua_setmetatable(state, -2); |
| 409 | |
| 410 | lua_pushinteger(state, info.type); |
| 411 | lua_setfield(state, -2, "type"); |
| 412 | lua_pushinteger(state, info.index); |
| 413 | lua_setfield(state, -2, "index"); |
| 414 | |
| 415 | #define SETOBJ(name) { \ |
| 416 | Lua::PushDFObject(state, info.name); \ |
| 417 | lua_setfield(state, -2, #name); \ |
| 418 | } |
| 419 | SETOBJ(material); |
| 420 | if (info.plant) SETOBJ(plant); |
| 421 | if (info.creature) SETOBJ(creature); |
| 422 | if (info.inorganic) SETOBJ(inorganic); |
| 423 | if (info.figure) SETOBJ(figure); |
| 424 | #undef SETOBJ |
| 425 | |
| 426 | if (info.mode != MaterialInfo::Builtin) |
| 427 | { |
| 428 | lua_pushinteger(state, info.subtype); |
| 429 | lua_setfield(state, -2, "subtype"); |
| 430 | } |
| 431 | |
| 432 | const char *id = "builtin"; |
| 433 | switch (info.mode) |
| 434 | { |
| 435 | case MaterialInfo::Plant: id = "plant"; break; |
| 436 | case MaterialInfo::Creature: id = "creature"; break; |
| 437 | case MaterialInfo::Inorganic: id = "inorganic"; break; |
| 438 | default: break; |
| 439 | } |
| 440 | |
| 441 | lua_pushstring(state, id); |
| 442 | lua_setfield(state, -2, "mode"); |
| 443 | } |
| 444 | |
| 445 | static int dfhack_matinfo_find(lua_State *state) |
| 446 | { |
nothing calls this directly
no test coverage detected