diff options
author | Philipp Gesang <phg@phi-gamma.net> | 2015-11-21 16:35:59 +0100 |
---|---|---|
committer | Philipp Gesang <phg@phi-gamma.net> | 2015-11-21 16:35:59 +0100 |
commit | ce17332266dff01cfb9f83edbf10b7e080a770ca (patch) | |
tree | fc842ed016caa9f5d20de15b8f9a706c009de5e9 /lualibs-lua.lua | |
parent | 4295a3eb51db73a87774d59fb3a38a54690319f7 (diff) | |
download | lualibs-ce17332266dff01cfb9f83edbf10b7e080a770ca.tar.gz |
sync with Context as of 2015-11-21
Diffstat (limited to 'lualibs-lua.lua')
-rw-r--r-- | lualibs-lua.lua | 34 |
1 files changed, 24 insertions, 10 deletions
diff --git a/lualibs-lua.lua b/lualibs-lua.lua index 1a2a987..cb61829 100644 --- a/lualibs-lua.lua +++ b/lualibs-lua.lua @@ -129,22 +129,36 @@ local print, select, tostring = print, select, tostring local inspectors = { } -function setinspector(inspector) -- global function - inspectors[#inspectors+1] = inspector +function setinspector(kind,inspector) -- global function + inspectors[kind] = inspector end function inspect(...) -- global function for s=1,select("#",...) do local value = select(s,...) - local done = false - for i=1,#inspectors do - done = inspectors[i](value) - if done then - break + if value == nil then + print("nil") + else + local done = false + -- type driven (table) + local kind = type(value) + local inspector = inspectors[kind] + if inspector then + done = inspector(value) + if done then + break + end + end + -- whatever driven (token, node, ...) + for kind, inspector in next, inspectors do + done = inspector(value) + if done then + break + end + end + if not done then + print(tostring(value)) end - end - if not done then - print(tostring(value)) end end end |