author | Francesco Abbate <francesco.bbt@gmail.com> | 2013年02月04日 21:46:49 +0100 |
---|---|---|
committer | Francesco Abbate <francesco.bbt@gmail.com> | 2013年02月04日 21:46:49 +0100 |
commit | 858c66cac8902ad7fd32d10ae82bb885f9774904 (patch) | |
tree | d9d5e118f3cc21336da56263470a6ffd3462f47d /iter.lua | |
parent | fe5cea0c67ac178d6476beb64f2bd5fcf4acb0f0 (diff) | |
parent | 9b63ca608ee573a2588ad14a3a46a5ca9f00f9a2 (diff) | |
download | gsl-shell-858c66cac8902ad7fd32d10ae82bb885f9774904.tar.gz |
-rw-r--r-- | iter.lua | 14 |
@@ -20,6 +20,7 @@ local cat = table.concat local fmt = string.format +local tostring = tostring do local ffi = require('ffi') @@ -61,6 +62,13 @@ end local max_depth = 3 +local function cdata_tos(t, deep) + local tp = gsl_type and gsl_type(t) or 'cdata' + if tp ~= 'cdata' and t.show then + return (deep and t:show() or fmt("<%s: %p>", tp, t)) + end +end + tos = function (t, depth) local tp = type(t) if tp == 'table' then @@ -92,9 +100,9 @@ tos = function (t, depth) end end elseif tp == 'cdata' then - local tpext = gsl_type and gsl_type(t) or tp - if tpext ~= 'cdata' and t.show then - return (depth == 0 and t:show() or fmt("<%s: %p>", tpext, t)) + local ok, s = pcall(cdata_tos, t, depth == 0) + if ok and type(s) == 'string' then + return s end end return tostring(t) |