Add Minetest Luon: ItemStack and AreaStore support

This commit is contained in:
Lars Mueller 2021-07-11 16:07:54 +02:00
parent 407a2d55ed
commit e29183f574
3 changed files with 32 additions and 0 deletions

@ -9,4 +9,5 @@ load"raycast"
load"wielditem_change" load"wielditem_change"
load"colorspec" load"colorspec"
load"schematic" load"schematic"
load"luon"
return _ENV return _ENV

29
minetest/luon.lua Normal file

@ -0,0 +1,29 @@
-- Localize globals
local getmetatable, AreaStore, ItemStack
= getmetatable, AreaStore, ItemStack
-- Metatable lookup for classes specified in lua_api.txt, section "Class reference"
local AreaStoreMT = getmetatable(AreaStore())
local ItemStackMT = getmetatable(ItemStack"")
local metatables = {
[AreaStoreMT] = {name = "AreaStore", method = AreaStoreMT.to_string},
[ItemStackMT] = {name = "ItemStack", method = ItemStackMT.to_table},
-- TODO expand
}
(...).luon = modlib.luon.new{
aux_write = function(_, value)
local type = metatables[getmetatable(value)]
if type then
return type.name, type.method(value)
end
end,
aux_read = {
AreaStore = function(...)
local store = AreaStore()
store:from_string(...)
return store
end,
ItemStack = ItemStack
}
}

@ -238,6 +238,8 @@ end
if not _G.minetest then return end if not _G.minetest then return end
assert(minetest.luon:read_string(minetest.luon:write_string(ItemStack"")))
-- colorspec -- colorspec
local colorspec = minetest.colorspec local colorspec = minetest.colorspec
local function test_from_string(string, number) local function test_from_string(string, number)