[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: How to cast a table knowing its name?
- From: "Adam D. Moss" <adam@...>
- Date: Fri, 24 Sep 2004 19:39:09 +0100
Jilani Khaldi wrote:
how to write in Lua something like this:
and have a new table (newtab) which has all the data of the table
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!).