|
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 errorNothing, because complex.enter resets it. But you probably may need touse some kind of protected call to complex.eval, which of course complicatesmatters.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.
But do I understand it correctly that all complex values inside that function would be created as temporary values? If so, what are the requirements for writing such "pure" functions? Is the following sufficient? - does not write to global variables - does not call non-pure functions- does not create non-temporary objects with references to temporary objects
- does not yield
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.
This is the part I don't understand. Garbage collection of the temporary array
will happen at some distant future time. How can "complex" ensure that temporary values will not be reused before that, or that when the table is collected it will not damage those values? Or is that not important?
Like I said, the scheme I outlined is not pretty but I think it can avoid allocating temporaries.
That's why I want to understand the details. Thank you for explaining them.