lua-users home
lua-l archive

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


On 13 April 2011 03:25, Mike Pall <mikelu-1104@mike.de> wrote:
> I wrote:
>> You'll be able to do this with reasonable efficiency with the
>> planned metatables for cdata objects.
>
> Support for ctype metamethods has just been committed to LuaJIT
> git HEAD. Here are the docs:
>
> http://luajit.org/ext_ffi_tutorial.html#metatype
> http://luajit.org/ext_ffi_api.html#ffi_metatype
>
> Have fun -- feedback welcome!
>
> --Mike
>
>

It seems you can't apply a metatype to a pointer:

LuaJIT 2.0.0-beta6 -- Copyright (C) 2005-2011 Mike Pall. http://luajit.org/
JIT: ON CMOV SSE2 SSE3 AMD fold cse dce fwd dse narrow loop abc fuse
> ffi=require"ffi"
> ffi.cdef[[ struct foo { int bar;}]]
> foo_mt={}
> foo_new = ffi.metatype ( "struct foo*" , foo_mt )
stdin:1: bad argument #1 to 'metatype' (invalid C type)
stack traceback:
        [C]: in function 'metatype'
        stdin:1: in main chunk
        [C]: ?

Will metamethods on a struct activate when I do it on a pointer to
them? (Otherwise, I would like to request some sort of automatic
de-referencing)

Daurn.