lua-users home
lua-l archive

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

Adam D. Moss wrote:

Jilani Khaldi wrote:

Hi All,
how to write in Lua something like this:
and have a new table (newtab) which has all the data of the table "table_name"

Write a function called 'tab' ('table' is already taken
by the lua's standard optional table library) which uses
the string of its first parameter as an index into the
globals table. That'll fetch a table with that name, if
it exists. Then return a new table with a shallow copy
of the table you just fetched (or simply return that
table itself, which will return a reference instead of
a copy -- that might be okay or desirable depending on
what you want to do with the returned table).

If you want more detail then ask. :) (I know that some
people on this list will gleefully write exactly the
function that anyone asks for if it's half-interesting
to do so, but writing such relatively simple things
yourself is a perfect way to learn Lua!).

Welll begore asking I have already tried many ways. Just to wonder why when I set:
lg = globals()

I get an error. Do I have to import some library to use globals()?


Jilani Khaldi
M€TA (Manuale Economico & Tecnico dell'Architetto)