lua-users home
lua-l archive

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


The reason?  It could be used with userdata, to provide more
information of the entity than just "userdata" does. For example, it
could provide "enum/SDL_INIT", telling that the entity is an
enumaration of logical type SDL_INIT.

I always create "class" property for my userdata objects to return class
name.

Instead I suggest to add a "__next" methamethod to userdata,
for iterate userdata with next() functions.

Today with "__len" I can iterate my userdata as
for i=1,#ud do ...ud[i]... end

But I hope you can add way to iterate userdata with
next(), pairs() and ipairs() functions.

for example
meta = { G={}}
meta.__index=meta.G
meta.__next=meta.G (or function what returned keys array or iterator function)
setmetatable(ud,meta)
for k,v in pairs(ud) do ... end

Best regards,
Vyacheslav Kalitkin