lua-users home
lua-l archive

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

The reason is quite simple actually. Lua normalizes returns. If a function does not return enough values to fill all of the variables, then those variables get filled with nil:

function foo()
  return 1,2;

local a,b,c = foo();

a and b will be 1 and 2, respectively, as expected, but c will be nil. It can't be "nothing" ... it's a variable.

You're encountering something similar:

function foo()

local bar = foo();

The first prints nil, because bar IS nil. A variable can't be nothing. foo(), however, returns nothing. When you run tostring() on it, nothing is passed to it. It is the same as doing tostring(), which is illegal. That is why the error arises.

-- Matthew P. Del Buono a.k.a. Shirik