lua-users home
lua-l archive

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


Hi all,

I have been using lua 4 for some time and love it. I wanted to give a try to lua 5 however there is something that bugs me.

I have actually already used lua 5, but only as a standalone language. I think the language itself is even better than lua 4 used to be, particularly because each function now can have its own global variable environment.

Now, what interests me is to embed it and particularly to create my own new types (userdata or lightuserdata). And here is my problem, in lua 4, I think it was very very simple to do that with tags and tag methods. In particular, it was very easy to test the type of a userdata in C by simply looking at its tag.

But with lua 5, there aren't any more tags, so how do I check easily what is the type of my userdata ? I know I could look into the methatable for some custom entry that I would call "type" for example, but it looks overly complicated and inefficient. Furthermore, there aren't any unified way to generate new type values (like the lua_newtag function) so two libraries may accidentally generate two different kind of userdata with the same "type" value in their metatable, so it would not be safe either. Probably I have missed something ...

Another question : I see that there are light userdata, which are much like the userdata in lua 4, except that they don't have tags. The documentation doesn't seem clear about these light userdata, can I associate a metatable to them or not ? If not, how can we use them since there are absolutely no way we could test the type of these light userdata without metatable nor tag.

Vincent Penne.