lua-users home
lua-l archive

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

Michael Grubb <lua <at>> 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
do so.

If you need to iterate over the data structure, then you'll
also have to write an iterator method.