lua-users home
lua-l archive

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


Why change the language when you can already do the equivalent to tail
recursions?
just have the function return the function it would like to call as tail
call.
the only additional thing you need is a "main" function that does the actual
calling.

look at this:

function State_A()
  ...
  return State_B
end

function main()
state = State_A
  while state do state = state() end
end

if you need arguments, you can do it like that:

function State_B(arg1, arg2)
  ...
  return State_A, {"foo", "bar"}
end

function main()
state = State_A
  while state do
    state, args = call(state,args)
  end
end

-Peter