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

Method lua_insert2

library/include/DataIdentity.h:422–440  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

420 return true;
421 }
422 virtual bool lua_insert2(lua_State* state, int fname_idx, void* ptr, int idx, int val_index) const
423 {
424 using VT = typename T::value_type;
425 VT tmp{};
426 auto id = (type_identity*)lua_touserdata(state, DFHack::LuaWrapper::UPVAL_ITEM_ID);
427 auto pitem = DFHack::LuaWrapper::get_object_internal(state, id, val_index, false);
428 bool useTemporary = (!pitem && id->isPrimitive());
429
430 if (useTemporary)
431 {
432 pitem = &tmp;
433 id->lua_write(state, fname_idx, pitem, val_index);
434 }
435
436 if (id != item || !pitem)
437 DFHack::LuaWrapper::field_error(state, fname_idx, "incompatible object type", "insert");
438
439 return insert(ptr, idx, pitem);
440 }
441
442 protected:
443 virtual int item_count(void *ptr, CountMode) const { return (int)((T*)ptr)->size(); }

Callers

nothing calls this directly

Calls 3

lua_touserdataFunction · 0.85
insertFunction · 0.85
lua_writeMethod · 0.80

Tested by

no test coverage detected