lua-users home
lua-l archive

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


Am 12.08.2013 16:43 schröbte Andrew Starks:
On Sat, Aug 10, 2013 at 6:16 AM, John Hind <john.hind@zen.co.uk> wrote:
I like this a lot.

One possible extension is to follow the lead of luaL_checkudata surfacing
this test in Lua. So if a type is defined using a userdata with a metatable
stored under a type name in the registry (as the C API encourages):

type(x, "mytype")

checks if type is a userdata or table with a metatable equal to the table
stored in the registry under the key "mytype".

This allows for the test to work even if a "type" metavalue is not defined.

John,

Thanks man!

I love your idea. It's actually the problem that I set out to solve,
before I learned I would need the C-API to solve it.

No need for the C API if you have the debug module available:

    > print( debug.getregistry()["FILE*"], debug.getmetatable( io.stdin ) )
    table: 0x7446d0	table: 0x7446d0


[...]

- Andrew


Philipp