Ben apparemment, y a pas beaucoup de monde qui aurait déjà fait ça :(
Bon voici un bout de code pour ceux que ça intéresserait (le très populaire "Hello world"). Je suis parti de ça.
unit1.pas
unit main;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, Buttons,
StdCtrls, lua, luautils, luawrapper;
type
{ TForm1 }
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
end;
var
Form1: TForm1;
implementation
{ TForm1 }
function luaHello(state: Plua_state): Integer; cdecl;
begin
showmessage('hello world');
end;
procedure TForm1.Button1Click(Sender: TObject);
var
LuaScript: TLUA;
begin
LuaScript := TLUA.Create(nil);
LuaScript.LoadFile('hello.lua');
LuaScript.RegisterLUAMethod('Hello', @luaHello);
LuaScript.Execute;
LuaScript.Free;
end;
initialization
{$I main.lrs}
end.
Un script LUA
Résultat de tout ça : lorsqu'on clique sur Button1, une fenêtre s'ouvre et affiche le message "Hello world".
Comment ça marche ? Une fois la fonction Hello (script lua) déclarée dans FPC, on l'associe à la fonction luaHello (FPC). Pour finir on lance le script LUA.