lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


I've changed the logic so that the pretty-printer tries to get the
__tostring metafield regardless for value type so this should now work
as expected for all values supporting a metatable and having a
__tostring method.  Your simple example seems to work for me now:

>  ffi=require"ffi" t=ffi.metatype("struct{int a;}",{__tostring=function(x) return "custom tostring " .. x.a end})
>  t
ctype<struct 95>
>  {t, t(2)}
{ ctype<struct 95>, custom tostring 2,  }
>

I'm attaching the modified sources so that they can be used and tested
by anyone interested.  If I don't get any complaints after a while
I'll make a new release (unless I forget it).

On Sun, Jul 1, 2012 at 9:41 PM, Justin Cormack
<justin@specialbusservice.com> wrote:
> On Sun, Jul 1, 2012 at 7:23 PM, Dimitris Papavasiliou <dpapavas@gmail.com>
> wrote:
>>
>>
>> I'm not familiar with LuaJIT.  From what I understand these aren't
>> userdata values.  Are cdata new kinds of values introduced by LuaJIT?
>>
>
> Yes, much like userdata but created via the ffi interface rather than the C
> interface.
>
> The absolute simplest example is
>
>>  ffi=require"ffi"
>>  t=ffi.metatype("struct{int a;}",{__tostring=function(x) return "custom
>> tostring " .. x.a end})
>>  a=t(2)
>>  a
>>  print(a)
> custom tostring 2
>>  type(a)
> "cdata"
>
>

Attachment: luaprompt.tar.gz
Description: GNU Zip compressed data