I'm interested in this also :-) My Lua loads the base, string, table,
and debug libraries, as well as a fairly large library of functions
that are specific to the application.
Somehow, I was sure that the first reply to this thread will come from you :)
I was thinking that it would be a good idea to have a way to
make some of these tables "constant" or read only.
Which is exactly what I'm trying to do too. "Tables without RAM" is something I've been looking forward to implement, but I still don't have the required knowledge of Lua source code, nor the time to look deeper into it (right now). The metatables idea was the best I could come up with.
We'd have to come up with some way of defining the tables
at compile time, with the obvious disadvantage of not being
able to modify them later.
Yes, but the advantage of having them occupy less (or no) RAM far outweighs this disadvantage. Defining the tables at compile time isn't too difficult either.
I'll have to take a look at the table definintion code to see
if there's a way to macro-ize the results of the library init
I'm a bit lost here, sorry. I didn't quite understand what you mean by "macro-ize the results".
The main problem (as I see it) is that Lua doesn't have the concept of a "read-only table". You can of course implement something with (almost) similar semantics with metamethods, but that would still require (at least) a table that rakes RAM space. In my oppinion, the "memory efficient read-only table" (for want a better term) type won't be a table at all, but rather a number type with special semantics, in that it represents the actual value (pointer) of the linear list of symbols in the Flash, and it also can be queried for keys just as a table can, triggering a code that searches the Flash for the key in a predefined way (a simple linear search would probably do, although a binary search isn't a bad idea). The idea is simple, but I have some (quite interesting) problems with it:
1. we need to define the full semantics
2. I don't really know how to fully implement it :)
3. I don't know how to test it (is there a test package for Lua that would test the behaviour of its data types?)