lua-users home
lua-l archive

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


On 30 August 2016 at 11:02, Jerome Vuarand <jerome.vuarand@gmail.com> wrote:
> If you really need preemption, then I think you should look at how
> signal handling is done in the stock interpreter. It installs a one
> time hook on call, return and count=1. I'm not sure how thread safe
> that is, I can only guess it's safe enough to call from a signal
> handler if the stock interpreter does it. But does that translate to
> the kind of preemption you want to use?

One of the more interesting things you can do here is inject a hook
that calls lua_yield.
This means your top level "lua_resume" (or lua_pcallk) will return,
and you can perform some operation before proceeding.

You need to know which coroutine is running; there is no safe way to
find this out.
Note that the official lua interpreter also suffers due to this,
Ctrl+C will *not* interrupt a coroutine:

$ lua
Lua 5.3.3  Copyright (C) 1994-2016 Lua.org, PUC-Rio
> while  true do end
^Cinterrupted!
stack traceback:
stdin:1: in main chunk
[C]: in ?
> coroutine.wrap(function() while true do end end)()
^C^C
$

Annoyingly you can't return any parameters from the lua_yield in a
debug hook. See http://lua-users.org/lists/lua-l/2015-12/msg00094.html