lua-users home
lua-l archive

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

I am storing a c++ object in a lua user data, and binding a meta table to it for lookup on method calls. The user data stores the pointer for the c++ object instance, and some other information such as whether lua will handle the freeing of the object or not, and the meta table, of course.

What I would like to do is allow a user to add lua variables to these c++ objects wrapped by a user data and accessed through the meta table.

Currently a user can call, for instance:
obj = createSomeObject()

I'd like the user to be able to say:
obj.x = 6

I'm not sure if this can be achieved, though, since obj is simply a user data, and a lookup in the meta table will reveal nothing regarding x. I could, on an unfound interface, modify the metatable, I guess ... I'm not really sure though, and was wondering what others though of as a good solution, if they have one.

Discover how everyone & everything in our world's connected: