summaryrefslogtreecommitdiff
path: root/test/save.lua
diff options
context:
space:
mode:
authorLua Team <team@lua.org>1998-07-11 12:00:00 +0000
committerrepogen <>1998-07-11 12:00:00 +0000
commit377347776f1f3d820f92151f70bec667f96d5e6b (patch)
treecdb3ba26158df33547dfe765547177afcee119d1 /test/save.lua
parent4f8c5d0f284e1f4da717aea5008915f185cd2e05 (diff)
downloadlua-github-3.1.tar.gz
Lua 3.13.1
Diffstat (limited to 'test/save.lua')
-rw-r--r--test/save.lua44
1 files changed, 41 insertions, 3 deletions
diff --git a/test/save.lua b/test/save.lua
index f16bdf20..ce2e5b34 100644
--- a/test/save.lua
+++ b/test/save.lua
@@ -1,4 +1,44 @@
-dofile("dump.lua")
+-- dump global environment
+
+function savevar (n,v)
+ if v == nil then return end
+ if type(v)=="userdata" or type(v)=="function" then return end
+ -- if type(v)=="userdata" or type(v)=="function" then write("\t-- ") end
+ write(n,"=")
+ if type(v) == "string" then write(format("%q",v))
+ elseif type(v) == "table" then
+ if v.__visited__ ~= nil then
+ write(v.__visited__)
+ else
+ write("{}\n")
+ v.__visited__ = n
+ local r,f
+ r,f = next(v,nil)
+ while r ~= nil do
+ if r ~= "__visited__" then
+ if type(r) == 'string' then
+ savevar(n.."."..r,f)
+ else
+ savevar(n.."["..r.."]",f)
+ end
+ end
+ r,f = next(v,r)
+ end
+ end
+ else write(tostring(v)) end
+ write("\n")
+end
+
+function save ()
+ write("\n-- global environment\n")
+ local n,v = nextvar(nil)
+ while n ~= nil do
+ savevar(n,v)
+ n,v = nextvar(n)
+ end
+end
+
+-- ow some examples
a = 3
x = {a = 4, b = "name", l={4,5,67}}
@@ -6,6 +46,4 @@ x = {a = 4, b = "name", l={4,5,67}}
b = {t=5}
x.next = b
-
save()
-