Re: Fast restart of luajit engine

  • From: Paul Emmerich <emmericp@xxxxxxxxxxxxx>
  • To: luajit@xxxxxxxxxxxxx
  • Date: Fri, 21 Oct 2016 09:32:04 +0100

Hi,


On 21.10.16 07:12, hanoh haim wrote:

I would like calll a luajit script from a C program. The LuaJit will
call back program API.
  I understand that if I call the luaJit without an exit it has context
and start smartly doing JIT in that context.
My question can I exit/restart the script (going back to main program
stack) with the context saved, so restart would savethe JIT and be fast?

You can use ffi callbacks for that:
http://luajit.org/ext_ffi_semantics.html#callback

However, the overhead will be around 100-200 cycles per call IIRC.

The better solution would be to really commit to a LuaJIT solution here:
Write your main loop in Lua and call into C to integrade your old code instead.


This program would run in many threads in parallel, so there is a need
for a context for each of them (might have different LUA script)

Simply creating one Lua state per thread works very well for such applications in my experience.


 Paul

Other related posts: