aboutsummaryrefslogtreecommitdiff
path: root/src/syslua/lx/lxinit.lua
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2017-04-19 15:34:04 +0200
committerAlex Auvolat <alex@adnab.me>2017-04-19 15:34:04 +0200
commite53a39d9ec28b24ea0d408f1500e987d005cd651 (patch)
tree639c93f2a17aabee7759cd16645b4d7da693ae4c /src/syslua/lx/lxinit.lua
parentd4a89538d381bb62b4c7c864b09d3d8274cf0bdb (diff)
downloadkogata-e53a39d9ec28b24ea0d408f1500e987d005cd651.tar.gz
kogata-e53a39d9ec28b24ea0d408f1500e987d005cd651.zip
Lua shell :)
Diffstat (limited to 'src/syslua/lx/lxinit.lua')
-rw-r--r--src/syslua/lx/lxinit.lua48
1 files changed, 33 insertions, 15 deletions
diff --git a/src/syslua/lx/lxinit.lua b/src/syslua/lx/lxinit.lua
index 6b23aa8..1c8d116 100644
--- a/src/syslua/lx/lxinit.lua
+++ b/src/syslua/lx/lxinit.lua
@@ -3,20 +3,38 @@ print "Lua eXtended helpers for Kogata v1"
do
local old_tostring = tostring
function tostring(x)
- if type(x) == "table" then
- if next(x) == nil then
- return '{}'
- end
- local q = '{\n '
- for k, v in pairs(x) do
- if q:len() > 4 then
- q = q .. ',\n '
- end
- q = q .. k .. ': ' .. tostring(v):gsub('\n', '\n ')
- end
- return q .. '\n}'
- else
- return old_tostring(x)
- end
+ local seen = {}
+ function aux(x)
+ if type(x) == "table" then
+ if next(x) == nil then
+ return '{}'
+ end
+
+ if seen[x] then
+ return '...'
+ end
+ seen[x] = true
+
+ local q = '{\n '
+ for k, v in pairs(x) do
+ if q:len() > 4 then
+ q = q .. ',\n '
+ end
+ q = q .. k .. ': ' .. aux(v):gsub('\n', '\n ')
+ end
+ return q .. '\n}'
+ else
+ return old_tostring(x)
+ end
+ end
+ return aux(x)
end
end
+
+
+function string.split(str, sep)
+ local sep, fields = sep or ":", {}
+ local pattern = string.format("([^%s]*)", sep)
+ str:gsub(pattern, function(c) fields[#fields+1] = c end)
+ return fields
+end