lua-users home
lua-l archive

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


On 01/06/2013 13.24, Dirk Laurie wrote:
E.g.

     myfunc(x)

returns a table with the same keys as x. When called with
an anonymous table, e.g.

    myfunc{1,2,3,4,5}

it is OK to modify the table and return it, but when called with
a table that already has a name, one must make a new copy
in case that name is referenced later.

Is there a way of diagnosing this difference?

I don't know if it's possible to tell them apart, but if your non-literal tables are created by code you could mark them with a special field (e.g. dup_me=true) or with an empty metatable if they have none, or reference them from a table.
(not very elegant and not always applicable, I know)

--
  Enrico