[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Nested userdata
- From: Mark Hamburg <mark@...>
- Date: Tue, 17 Feb 2009 17:02:40 -0800
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 b.ax 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-
2. It's environment table needs to hold a reference to the userdata
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.