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

Method Push

library/LuaApi.cpp:398–443  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

396static int DFHACK_MATINFO_TOKEN = 0;
397
398void 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
445static int dfhack_matinfo_find(lua_State *state)
446{

Callers

nothing calls this directly

Calls 8

lua_pushnilFunction · 0.85
lua_rawgetpFunction · 0.85
lua_setmetatableFunction · 0.85
lua_pushintegerFunction · 0.85
lua_setfieldFunction · 0.85
lua_pushstringFunction · 0.85
validMethod · 0.80
isValidMethod · 0.45

Tested by

no test coverage detected