lua-users home
lua-l archive

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


I would like to efficiently escape from a running 4.0 lua function.

This does not seem possible with 4.0 or 4.1 alpha. I would like to avoid using a continuously active linehook since it can have a significant cost. 

function empty_linehook() end

    j = 0
    for i = 1, 5000000 do 
        j= j + 1
    end

Runtime for the above code   seconds
no linehook                  9.14
using empty_linehook        47.00

The callhook is too coarse for my needs.

I would like to use a signal as is done in lua.c but it seems
using a signal to alter a linehook while remaining in a single
function does not work.

In lua.c the signal handler laction is called.
It sets the linehook to the c function lstop by 
calling lua_setlinehook.
lua_setlinehook changes the value of L->linehook.

---------------------------------------------------------------------
The problem is the main byte code interpreter loop in 
luaV_execute in file lvm.c.

The following copy is done before the byte code interpreter loop 
is entered. Any change to L->linehook during the loop is never seen.
const lua_Hook linehook = L->linehook;
----------------------------------------------------------------------
 
Does anyone have a suggestion for how to escape efficiently from a 
running lua function ?


Dan Hiepler


Get 250 color business cards for FREE!
http://businesscards.lycos.com/vp/fastpath/