lua-users home
lua-l archive

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


On Tue, 18 Dec 2001, Paul Swanson wrote:

> I have implemented many extensions to the Lua language, including the
> following:
>
> tableA + tableB => modified tableA with "defaults" provided by tableB
> arrayA .. arrayB => modified arrayA with arrayB as elements nA .. nA+B
> nil + tableA => duplicate of tableA
>
> I suppose I can emulate this behaviour by using copytagmethods() for every
> new tag/object I create, but that seems like a lot of effort to work
> around an unnecessary restriction.

If those tables have non-default tags, you already had to copy the tag
methods to the new tags, didn't you?


> I have also been considering other extensions as well (which would not be
> possible without tag methods for basic types, including tables).  For
> instance:  "string1" ^ "string2" would always generate an error, with
> absolutely no way to override it.

Lua 4.0 already forbids the redefinition of '^' for strings.
In the new version you can override the "pow" operator, in the
same way you could override the tag method `number-pow' in Lua 4.0.

It is important to remember that Lua 4.0 already forbids many tag methods
for basic types: the only tag methods you can set for strings are settable,
gettable, and function. Numbers also allow few tag methods. So I guess the
main restriction of the new version is about tag methods for basic tables.
But we have a problem here. Lua 4.0 forbids the re-definition of
gettable/settable for basic tables. With meta-tables, I see no way to
restrict such re-definitions once you get access to the default meta-table.
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?

-- Roberto