[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Read-Only Tables Patch
- From: Bret Victor <bret@...>
- Date: Tue, 14 Nov 2006 02:10:30 +0000 (UTC)
Michael Grubb <lua <at> dailyvoid.com> writes:
> My goal with this patch was to provide a mechanism for "publishing"
> immutable data structures from C to Lua.
If your immutable C-side data comes from a C struct,
you should just use Lua userdata, and don't even bother
with Lua tables at all.
Create a full userdata that contains or points to the C data
structure. Give it an __index metamethod that looks up
whatever needs looking up. Lua code will be unable to
modify the data structure, because there's no method to
If you need to iterate over the data structure, then you'll
also have to write an iterator method.