PDA

View Full Version : Problems importing the LUA dll into a Lazarus Application



jdarling
27-02-2006, 04:42 PM
I've spent quite a bit of time trying to get LUA to work in Lazarus, all to no avail. I started with a working Delphi version and when it wouldn't run (lots of AV's don't ask me to list) once compiled in Lazarus I started modifying it to fit the standard FPC stuff (I think).

If any of the Lazarus gurus could take a look I'd love to know what you think or what I'm doing wrong. You can download the entire thing (project files for Delphi and Lazarus as well as the library) from http://www.eonclash.com/Lazarus/LUA.zip.

jdarling
27-02-2006, 04:46 PM
BTW: My problem (witch I forgot to mention) all lies in the calling of the imported methods. For example when I call:


lua_register(L, 'print', @lua_print);

it actually does the following:


procedure lua_register(L: Plua_State; const n: PChar; f: lua_CFunction);
begin
lua_pushstring(L, n);
lua_pushcfunction(L, f);
lua_settable(L, LUA_GLOBALSINDEX);
end;

Witch fails on the lua_pushstring method. This leads me to believe that one of two things is happening;
1) CDecl isn't working as I thought it would in FPC
2) Even though I have what appears to be a valid method address, it isn't.

Legolas
27-02-2006, 06:48 PM
Uhm... I don't know if is the case, but you can try to look at this thread (http://www.lazarus.freepascal.org/index.php?name=PNphpBB2&file=viewtopic&t=1148&highlight=getprocaddress) on Lazarus forum.

jdarling
27-02-2006, 07:33 PM
Unfortunately I've already typed all of the get methods and they appear to be receiving the method pointer properly. Things like LUA_Open and LUA_Close work just fine. Its some of the other routines that have problems. If I static link the DLL then I don't have any problems with anything (at least what I've been playing with). This may be one of those cases were I simply have to static link :(

Almindor
04-03-2006, 09:46 PM
Hi, I've had a short look at your files (especialy lua.pas).

1. Don't use libC in unix, use baseunix and unix units instead.
2. Don't use {$IFDEF LINUX} but {$IFDEF UNIX} or {$IFNDEF MSWINDOWS} otherwise BSD and other unices won't work

I haven't been able to get it to compile on my FreeBSD yet due to afforementioned problems but I'll try tomorrow and see what I can see :)

I'll keep you posted.

Almindor
04-03-2006, 10:25 PM
Ok I've managed to hack the lua.pas into compilable state.
you can get the "FPC ready" version here: http://members.chello.sk/ales/lua.pas

It does exactly the same exception on the same method as for you in windows however. This is too much to be coincidental so there's a bug somewhere. Might be something in lua.pas which I don't have a clue about.

Ales