Hi all

Currently I am trying to make work attached code under Win64.
It uses LuaJIT 2 as drop-in replacement to Lua.

The code works fine under Linux32, Linux64, Win32, but not under Win64.
Under Win64 it crashes with unhandled exception like following:

An unhandled exception occurred at $0000000077D67D9D:
EControlC: Control-C hit
  $0000000077D67D9D

The same dll works fine under gcc/msvc complied project (luajit.exe interpreter 
which comes in box).

The idea of the attached code is following:
- try to calculate _invalid_ Lua code
- return Lua error (not exception).

The problem seems to have something to do with exception handling under Win64 
as LuaJIT 2 using native exceptions in its dll.
But it does not mean that C exceptions should be catched by FPC.  I understand 
that's not possible.
lua_pcall should handle those internally (like under Linux64).

It looks like some issue in FPC prevents LuaJIT catch its own exception under 
Win64.

P.S. Tested under FPC svn rev. 23910
P.P.S. You can use 
https://github.com/malkia/ufo/blob/master/bin/Windows/x64/luajit.dll LuaJIT 
build under Win64. Just rename it to lua5.1.dll to comply with lua.pas.

-- 
Regards,
Denis Golovan
program project1;

{$mode objfpc}{$H+}
{$apptype console}

uses
  {$IFDEF UNIX}{$IFDEF UseCThreads}
  cthreads,
  {$ENDIF}{$ENDIF}
  {$IFDEF WINDOWS}
  Windows,
  {$ENDIF}
  sysutils,
  Classes
  { you can add units after this },
  
  lua,
  lauxlib
  ;

var L : Plua_State;
  LibName, script, r:string;
  errCode:Integer;
begin
  L := lua_open;
  LibName:='main';

  Script:='do return 1 + nil end';
  luaL_loadbuffer(L, PChar(Script), Length(Script), PChar(LibName));

  errCode:=lua_pcall(L, 0, LUA_MULTRET, 0); // << crashes here under Win64
  r := string(lua_tostring(l, -1));
  WriteLn(r);

  lua_close(l);
end.

_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply via email to