lua-users home
lua-l archive

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

If you want to say b.a and get something back, you pretty much have to return a userdata. The only other option is to write and b.ay which should be fine if you never want b.a by itself and some people might argue even represents better encapsulation.

But let's assume we're going to build a userdata to represent b.a. Then it needs to do two things:

1. It should be implemented as a more or less conventional userdata- consiting-of-just-a-pointer.

2. It's environment table needs to hold a reference to the userdata representing b.

If you access b.a a lot you may also want to store a reference from b's userdata to b.a's userdata but that's not required. The reference from b.a's userdata to b's userdata is required in order to avoid having the latter get collected while the former is still alive.