lua-users home
lua-l archive

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


Hi. 

Last week we move our code to 5.1 lua. And now I see that our
internal exception handling stops working. Handler in principle tries to find in local
variables name 'finally' type function and calls it.

Lua code:

function a()
  local a=1
  local b=2
  local finally=function(err)
    print(err)
  end
  error("X")
  finally=nil
end
a()


Piece of pascal function registered by lua_atpanic:

level := 0;
while lua_getstack(L, level, @ar)<>0 do begin //Starting from actual level
  i := 1;
  p := lua_getlocal(L, @ar, i);
  while p<>nil do begin
    if Copy(p, 1, 7)='finally' then begin //All variables starting with 'finally'
      if lua_isfunction(L, -1) then begin
        lua_pushstring(L, PChar(s)); //Parameter Exception.Message
        lua_call(L, 1, 1);

        ...
      end;
    end;
    p := lua_getlocal(L, @ar, i);
  end;
  inc(level);
end;


Main problem: lua_getstack(L, 0, @ar) returns 0.

In 5.0 version handler works perfectly. 

Thanks for your help.
Petr Kristan

-- 
Ing. Petr Kristan
.
EPOS PRO s.r.o., Bozeny Nemcove 2625, 530 02 Pardubice
tel: +420 466335223    Czech Republic (Eastern Europe) 
fax: +420 466510709