aboutsummaryrefslogtreecommitdiff
path: root/helpers.lua
diff options
context:
space:
mode:
Diffstat (limited to 'helpers.lua')
-rw-r--r--helpers.lua25
1 files changed, 24 insertions, 1 deletions
diff --git a/helpers.lua b/helpers.lua
index ef3752a..6a8175f 100644
--- a/helpers.lua
+++ b/helpers.lua
@@ -223,4 +223,27 @@ function advtrains.pos_median(pos1, pos2)
end
function advtrains.abs_ceil(i)
return math.ceil(math.abs(i))*math.sign(i)
-end \ No newline at end of file
+end
+
+function advtrains.serialize_inventory(inv)
+ local ser={}
+ local liszts=inv:get_lists()
+ for lisztname, liszt in pairs(liszts) do
+ ser[lisztname]={}
+ for idx, item in ipairs(liszt) do
+ local istring=item:to_string()
+ if istring~="" then
+ ser[lisztname][idx]=istring
+ end
+ end
+ end
+ return minetest.serialize(ser)
+end
+function advtrains.deserialize_inventory(sers, inv)
+ local ser=minetest.deserialize(sers)
+ if ser then
+ inv:set_lists(ser)
+ return true
+ end
+ return false
+end