lua-users home
lua-l archive

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


Roberto Ierusalimschy wrote:
> 
> It is important to remember that Lua 4.0 already forbids many tag methods
> for basic types:

I never understood why this was not allowed.

> the only tag methods you can set for strings are settable, gettable,
> and function.

Why?  Just to generate errors?  Ok, setting the index methods will not
do very much (it will never be called) but why issue an error?  Why not
allow the arithmetic operators on strings?  Afaics there's nothing that
would break.  These checks are only limiting the use, they do not protect
anything.

> But if you change the gettable/settable for all tables, you can break
> the security of lots of C code. (For instance, you can intercept accesses
> to the registry table.) So, what to do?

C code has to use rawget/set when it does not want tag method invocation!
C code has to be aware that get/settable may invoke tag methods as do a
lot of other functions.

If you want to protect the registry[1] give it a private method table that
cannot be accessed by Lua code.

Ciao, ET.


[1] against sloppy code the uses get/settable instead of rawget/set