From a4a63bb0d1e47ee3f230dedf3731ae2e7e556796 Mon Sep 17 00:00:00 2001 From: Alexey Kopytov Date: Sun, 24 Dec 2017 10:26:49 +0300 Subject: [PATCH] Support LuaJIT cdata and ctype values in Inspector:putValue(). Add special handling for cdata and ctype types provided by LuaJIT: use tostring() to print values of those types, which either provides a more meaningful default type description (e.g. 'ctype' instead of '') or a user-defined value as described at http://luajit.org/ext_ffi_api.html#tostring --- inspect.lua | 3 ++- spec/inspect_spec.lua | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/inspect.lua b/inspect.lua index ae5b430..c13a8cd 100644 --- a/inspect.lua +++ b/inspect.lua @@ -296,7 +296,8 @@ function Inspector:putValue(v) if tv == 'string' then self:puts(smartQuote(escape(v))) - elseif tv == 'number' or tv == 'boolean' or tv == 'nil' then + elseif tv == 'number' or tv == 'boolean' or tv == 'nil' or + tv == 'cdata' or tv == 'ctype' then self:puts(tostring(v)) elseif tv == 'table' then self:putTable(v) diff --git a/spec/inspect_spec.lua b/spec/inspect_spec.lua index 1e4a9e0..dadeb89 100644 --- a/spec/inspect_spec.lua +++ b/spec/inspect_spec.lua @@ -71,7 +71,8 @@ describe( 'inspect', function() if is_luajit then it('works with luajit cdata', function() - assert.equals('{ , , }', inspect({ ffi.new("int", 1), ffi.typeof("int"), ffi.typeof("int")(1) })) + assert.equals('{ cdata: PTR, ctype, cdata: PTR }', + inspect({ ffi.new("int", 1), ffi.typeof("int"), ffi.typeof("int")(1) }):gsub('(0x%x+)','PTR')) end) end