lua-users home
lua-l archive

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

you can do this using tagmethods.

it is very easy to just deny any writeaccess to global variables, or if you
just want to protect your variables and still allow "new" global variables
by the user, you can do so by keeping the read-only ones in a seperate table
and set up tagmethods that first look in your readonly table and then in the
writable globals table. (This has been discussed before on this list, look
for "Read only variables")

another "easy" way is to clone the globals table, call the users script and
then reset the globals table from the copy.


> -----Original Message-----
> From:
> []On Behalf Of Matt Holmes
> Sent: Wednesday, April 24, 2002 7:22 PM
> To: Multiple recipients of list
> Subject: Protecting variables
> In my game engine, I register certain methods to Lua in a table
> so that they
> can be called by my scripts. For instance, I may push a method called
> 'TestMethod' to the global table variable 'this'. So for
> instance, the user
> can do this:
> this:TestMethod();
> My mechanism for doing this works perfect.
> What I want to know is, is there a way to protect those variables so that
> they cannot be reset by a user. For instance, I do not want them
> to be able
> to do this:
> this = {} or this.TestMethod = function() end
> Is this possible?
> Also, when invoking a C method that is a member of a table with the ':'
> operator, is 'self' still passed as the first argument? Or is that only
> passed to table functions written in Lua?
> Thanks,
> Matt