lua-users home
lua-l archive

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


On 6/5/07, Jason Perkins <starkos@gmail.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:

  table.insert(days, "Frankday")

Any suggestions?

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,

Jason