lua-users home
lua-l archive

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


Hi Patrick,

i'm not sure how can I achieve that with debug hooks. I can set a callback to be called when every ,say, 10 instructions are executed, but then I need to see how much time they were executing and then execute other lua thread (lua_state). How can I do this from within the called callback function? if I return from this function the same lua_State will continue execution...

Thanks,
Ivan

2008/7/31 Patrick Donnelly <batrick.donnelly@gmail.com>
On Thu, Jul 31, 2008 at 4:07 AM, Ivan Gagis <igagis@gmail.com> wrote:
> Hi All,
>
> I saw some discussion about different implementations of threads in lua, but
> no one talked about green threads.
>
> In my opinion introducing the green treads would be a very good alternative
> to all implementations of threads (with native OS threads) existing at the
> moment and coroutines.
>
> I think that introducing some function which allows to execute a specified
> number of opcodes from lua script would allow implementing the green treads
> to any developer who uses lua.
> For example, there is a C API function lua_pcall(L, ....) which calls a lua
> function and does not return until the lua function returns.
> I propose to untroduce a new function lua_pexec(L, numOpcodes, ....) which
> will execute a specified number of opcodes and return, the current
> instruction pointer will be saved in lua state L, so when calling the
> function for subsecquent times it will continue executing the lua program.
>
> Of course, there are some difficulties to introducing such a function (or a
> set of functions):
> - For example, the lua "exceptions" mechanism will not work (
> longjump()/throw ), so, it will be necessary to introduce some kind of
> language built-in exception throwing/catching ability, mayme add new lua
> opcodes for that.
> - calling a lua function from a C implementation of another lua function is
> not good, as it may cause the lua_pexec() to block for a long time. Thus,
> some of the lua std lib functions will need to be rewritten in the mix of
> lua and native calls instead of complete native implementation.
> - Maybe introduce a "multistep compilation" of lua scripts. For example if
> lua program calls a require() function it may need to read a .lua file and
> build a bytecode from from it which is a time consuming operation. So it
> would be good to read the .lua file by small portions and compile them while
> giving other green threads to execute between two consequent .lua file
> reads.
> - ... much other things I mussed.
>
> I think that it would be good if Lua will be moving towards the introduction
> of such abilities.
>
> Thanks,
> Ivan
>

This is already possible using debug hooks from C; it will also be
possible in pure Lua in 5.2 (assuming the new coco like functionality
is added).

--
-Patrick Donnelly

"One of the lessons of history is that nothing is often a good thing
to do and always a clever thing to say."

-Will Durant