lua-users home
lua-l archive

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

is there some preferred / recommended way, to ask for the type of a
userdata inside some Lua program?

I would like a e. g. like a Lua function "testudata( udata, type)"
corresponding to luaL_testudata, so that I could write something like
this in Lua:

      if not testudata( variable, 'FILE*') then print ('not a file...') end

Or should I best present a "tostring metafunction" for each of my
userdata, which is programmed similar to f_tostring in liolib.c, which
returns some string 'file ...' for files? and then analyse the start
of the returnd string, if I check tostring, so like this e. g.:

    type= tostring( variable)
    if string.sub( type, 1, 4) ~= 'file' then print ('not a file...') end