lua-users home
lua-l archive

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


Jeff Wise wrote:
> My main routine calls my function.  The function's purpose is to
> build a table.  Debug statements within the function seem to indicate
> that it is performing as expected.  However, when I use the table in
> the mainline, the table is apparently not passed.  The function's
> table is defined as a local variable.  Here is the statement:    
> 
>    data_table = conv(bytes)
> 
> and the function looks like this:
> 
>   function conv(data)
>   local r_table = {}
>   ...
> 
>   return r_table
>   end
> 
>> 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?  

Here is a test I did:
-- test.lua
function conv(data)
	local r_table = {}
	print("conv: "..tostring(r_table).." ("..type(r_table)..")")
	return r_table
end
data_table = conv(bytes)
print("main: "..tostring(data_table).." ("..type(data_table)..")")
-- end of test.lua

# lua test.lua
conv: table: 00336C20 (table)
main: table: 00336C20 (table)

The problem probably lies in the ... in your example My guess is that
it's changing the content of the local variable. Put a statement like
"print(r_table)" before you return r_table.