lua-users home
lua-l archive

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


As Mike pointed out in [1] the call chain 'FFI -> C -> lua_*()'  with
the same lua_State is "no-no" at present.
With this in mind what is the best strategy to solve the following problem.

Let say, I  have a mathematical function implemented as a pure Lua
function foo_L(x) and I need to compute its definite integral (aka
quadrature) using standard quadrature algorithms implemented in C (GSL
Gauss-Kronrod, NETLIB, etc). All these integrators expect a pointer to
a C-function bar_C( double x, void* aux) to repeatedly compute the
integrand (aux points to the structure that stores extra parameters).
I can make bar_C a wrapper that calls back Lua function foo_L. Calls
to bar_C are in a inner loop. Is it possible somehow to trace bar_C
and  foo_L calls and eliminate overhead of calling Lua function from
C??

Of course, one radical way of solving (eliminating) the problem is to
reimplement Gauss-Kronrod or any other quadrature algorithm in pure
Lua. With LuaJIT-2.0 stellar run-time performance it could give C
implementation run for its money.  Of course, this is the last resort
solution, for it means porting big chunks of numeric library to Lua
and who has time for that:-)

Any  suggestion is appreciated.
--Leo--

[1]  http://lua-users.org/lists/lua-l/2011-01/msg01291.html