lua-users home
lua-l archive

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

> On Aug 18, 2015, at 8:18 PM, 云风 Cloud Wu <> wrote:
> Lua is a embedded language, it uses powerful userdata to wrap the c object as the lua object. But sometimes it's not enough.
> For example, if we have a C struct like this :
> struct foo {
>   struct foo1 foo1;
>   struct foo2 *foo2;
> };
> We can use userdata to store struct foo in lua variables : 
> struct foo * f = lua_newuserdata(L, sizeof(*f));
> How to reference sub struct foo1/foo2 in lua ? maybe we can give the userdata a metatable, implementing an __index metamethod.
> But foo.foo1 or foo.foo2 should be a new userdata. It needs more complex and expensive way :


1. Why do you want to “reference sub struct foo1/foo2” in Lua? What does “reference” mean in this context? What operations do you wish to perform in Lua on foo1/foo2?

2. Why should foo1/foo2 "be new userdata"? What operations do you expect to be able to do on them in Lua if they *are* new userdata?

You still have not really made clear the problem you are trying to solve. What you have presented is your partial solution to a (hidden) problem, and wish to discuss ways to make that solution work (which, as others have noted, may not be possible or even desirable).