[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: luajit ffi - calling a luajit function via a C function pointer?
- From: Paul Bonser <misterpib@...>
- Date: Thu, 10 Feb 2011 18:19:42 -0600
On Thu, Feb 10, 2011 at 12:51 PM, Geoff Leyland
> On 11/02/2011, at 7:12 AM, Mike Pall wrote:
>> So what magical things does that C++ code do and why can this not
>> be written in Lua? No, you don't have to answer that, better work
>> on fixing it.
> One use case is calling Lua functions from numerical libraries. For example, ipopt  is a C++/FORTRAN library that finds a local minimum of a nonlinear optimisation problem. ipopt calls a set of user-defined functions to evaluate objective functions, constraints and various derivatives. Rima has an interface to ipopt now, so in that case ipopt is calling Lua functions repeatedly.
> You're right, someone *could* rewrite ipopt in Lua, but, for me at least, that seems about as hard as rewriting LuaJIT would be, and anyway, maybe next week I'll want to use couenne . I don't expect any magic from LuaJIT to help in this situation, but I think it does occur legitimately.
If I understand correctly, someone could use ipopt from within LuaJIT,
with callbacks written in Lua (as soon as Mike finishes adding
callbacks to the FFI), and then they would get close to the same
performance if the entire thing was written in C, right?
Also, in Shawn's case, if he could call into his C/C++ main loop using
the FFI, after also using the (as yet unimplemented) callback
functionality to register his Lua callbacks with the C/C++ code, then
he would also reap the benefits of having his lua code JITed?
If my understanding of this is correct, then I'm very much looking
forward to being able to use the FFI callback functionality.
>  https://projects.coin-or.org/Ipopt
>  https://projects.coin-or.org/Couenne