lua-users home
lua-l archive

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

Hash: SHA1

Jeff Wise wrote:
>>From my diagnostic messages inside the function, r_table contains the
> expected data, but data_table (in the mainline) does not.  Is the assignment
> statement transferring all values from the function to the mainline?

Your supplied code should work --- something else must be going wrong. Can you
give more context?

One thing to bear in mind: the only thing the assignment is transferring is a
pointer. Let me expand:

function mt()
	local t = {}       -- creates a new table, t points at it = 1          -- alters table
	return t           -- returns pointer to table

t1 = mt()                  -- t1 now points at the table mt() created
t2 = t1                    -- t2 now points at the *same* table

That is, the table is being created in exactly one place, and then you're just
manipulating pointers to the table. If you call mt() multiple times, each time
it'll create a new, distinct, table. If you alter, you'll notice that has changed too, because t1 and t2 are both pointing at the same table.

> CONFIDENTIALITY NOTICE:  This E-mail message and all attachments, which
> originated from Sealy Management Company Inc...

You might want to do something about that...

- --
┌── ─── ───────────────────
│ "There does not now, nor will there ever, exist a programming language in
│ which it is the least bit hard to write bad programs." --- Flon's Axiom
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla -