[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Prevent table insertions?
- From: "Jason Perkins" <starkos@...>
- Date: Wed, 6 Jun 2007 12:54:49 -0400
On 6/5/07, Jason Perkins <email@example.com> wrote:
I'm looking to find a way to prevent new values from being entered
into a table. I tried the read-only table approach from PIL
(http://www.lua.org/pil/13.4.5.html) which works as advertised.
However, I can still insert values like:
Thanks to Patrick and Luis for the suggestions. I think I am going to
replace table.insert(), and have it check the object metatable for an
"__insert" metamethod. I'll also add a "__remove" metamethod and check
it from the appropriate table functions.
Just as an FYI, I'll be using these metamethods to generate "type
safe" collections, and also to synchronize a Lua table with an
internal C vector.
Thanks again for the suggestions,