lua-users home
lua-l archive

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


On 06.05.2011 15:21, Luiz Henrique de Figueiredo wrote:
indirect("afunc(x)")

afunc(42) called
nil

Can anybody explain why the output is nil instead of 42?

Because you did not return anything in the call. Try
	indirect("return afunc(x)")

Or add "return" automatically inside indirect before calling loadstring:

  function indirect(str)
      local result = loadstring("return "..str)()
      print(tostring(result))
  end

Ah, yes.I didn't realize that the loadstring parameter constitutes a chunk. It's clear now. Thanks!

Bernd

--
Bernd Eggink
http://sudrala.de