[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Ask userdata type from Lua
- From: bil til <biltil52@...>
- Date: Fri, 30 Jun 2023 20:30:59 +0200
Hi,
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
??