lua-users home
lua-l archive

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

I am new to Lua and this list and hope you can help me with a little
problem. I need to call a function that is held in a string. So I use
loadstring to convert the string into a function call. However it seems
that the arguments are not passed to the add-function in the example:

x,y,z,n = 0,0,0,0

function add(m)
  x = x + m
  return x

function mul(m)
  x = x * m
  return x

function call(f,n)
  x = 5
  y = loadstring("return "..f)
  z = y()


As result I would expect 17 because when calling "y()" n has a value of 12.

Please note that this is part of a bigger project and I have just
simplified the problem. So do not wonder why I want to add 5 + 12 in such
a strange way.


...using RiscLua 4.14, built from Lua 5.1.3