mirror of
https://github.com/appgurueu/modlib.git
synced 2024-12-23 13:52:29 +01:00
Add Minetest Luon: ItemStack and AreaStore support
This commit is contained in:
parent
407a2d55ed
commit
e29183f574
@ -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
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
|
||||||
|
}
|
||||||
|
}
|
2
test.lua
2
test.lua
@ -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)
|
||||||
|
Loading…
Reference in New Issue
Block a user