[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: RE: deny table modification
- From: "Thijs Schreijer" <thijs@...>
- Date: Fri, 21 Dec 2012 08:55:59 +0100
> Hello,
>
> I use from the C API a set of tables for storing function pointers in it.
> On the Lua side, I can call the function from the table, but I would like
> to deny any modification on the table from the Lua script.
To prevent modifications on the table (that is the table CONTENTS), you can
use a proxy table, with some metamethods
>
> I use a luaL_newlib and a lua_setglobal for setting my function table, but
> the script can set the global variable to nil or something else. Can I
> deny this, so that the table can not be overwritten?
To prevent modifying the global that HOLDS the table itself, you could use a
similar approach on the global table (_G, _ENV, and the likes). But that
would have a penalty on all global lookups instead of just your table.
Thijs