lua-users home
lua-l archive

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


> How would you prevent these temporary values from escaping into other parts
> of Lua state?

You're only supposed to call complex.eval after complex.enter.

> If eval gives control to Lua, then it may yield or call debug hook,
> keeping active reference to the temporary values for undefined amount
> of time.

If your metamethods do that, then my scheme does not work. :-)

> What happens with the internal counter on error

Nothing, because complex.enter resets it. But you probably may need to
use some kind of protected call to complex.eval, which of course complicates
matters.

> and what happens when argument to "eval" calls another function?

If it's a pure Lua function, then everything should be ok, as long as
the function has no side effects.

> Can arrays appear anywhere in the expression? I.e. would something like
>     complex.eval(some_matrix_fn { a * a, a * b, -a * b, -b * b })
> work?

Again, if some_matrix_fn is pure Lua, I think it's ok.

Like I said, the scheme I outlined is not pretty but I think it can avoid
allocating temporaries.