lua-users home
lua-l archive

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

On Mon, Nov 13, 2006 at 09:41:35AM -0600, Michael Grubb wrote:
> After doing a great amount of reading and experimentation I decided  
> that the existing methods for creating read-only tables in Lua 5.1  
> was untenable.
> For such a simple thing it seemed rather ridiculous to have to use an  
> empty proxy-table along with or instead of redefinitions of the  
> several table related functions.
> It seemed that there should be a simpler solution.  So I went about  
> poking around in the code and came up with a solution that works for  
> me.  You can find the patch below that adds Read-Only table support  
> to Lua-5.1.1.

Why does it seem ridiculous?  It's very simple; if it doesn't feel
simple, that may just be a symptom of not yet being comfortable with
the language.

That said, I do find a problem with proxy tables: they "break" pairs(),
operator #, and so on, so the resulting table is not transparently
interchangeable with the original.  This isn't specific to this use,
but to all uses of proxy tables, so I think it's sort of a flawed
paradigm as is ...

(One thing that proxy tables can do, which this patch can not, is C-like
const, where the same object can have both const and non-const references
at the same time.  Your version is more like "immutable tables", which
can't be changed at all short of rawset.)

Glenn Maynard