[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: deny table modification
- From: Philipp Kraus <philipp.kraus@...>
- Date: Fri, 21 Dec 2012 12:33:46 +0100
Am 21.12.2012 um 08:55 schrieb Thijs Schreijer:
>> 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.
For my understanding, after reading the Lua documentation: The global table
is a "lookup table" for data in e special memory block? Will this memory block
be prevented for write access or can each Lua script modify items of this table?
Phil