PDA

View Full Version : JetLua - Delphi Lua SDK



drezgames
11-08-2020, 06:14 AM
1557

Download
https://github.com/tinyBigGAMES/JetLua

Overview
JetLua is a Lua (https://www.lua.org/) SDK for Delphi to allow easy integration for Lua scripting inside your Delphi application.

Features


Support for Delphi (https://www.embarcadero.com/products/delphi) 10.4 Sydney
Only two minimal interfaces to access feature set (IJetLua & IJetLuaContext)
You can auto register class/object JetLua routines
If you have created an AutoSetup class function, it's automatically called during registration where you can do global setup operations
You can declare tables in "table.table.table" format
You can declare global/table variables and access them
You can check the exists of global/table variables and routines
You can call global/table functions with a variable number of parameters
You can pull and push data from and to the Lua stack via the IJetLuaContext interface
You can load source code from a file, string and buffer
You can import Lua modules
Source is JIT (https://en.wikipedia.org/wiki/Just-in-time_compilation) compiled using moonjit (https://github.com/moonjit/moonjit)
You can compile Lua sources (including imported modules) and bind to an EXE for stand-alone distribution
You can add version information, an icon, enable runtime-themes and high DPI aware support to EXEs


You can find more information, updates, availability on our website (https://tinybiggames.com/projects/project/4-jetlua/).

1558

JernejL
11-08-2020, 07:43 AM
This looks intruiging and impressively simple.

Is any freepascal & crossplatform support planned?

drezgames
11-08-2020, 04:44 PM
This looks intruiging and impressively simple.

Is any freepascal & crossplatform support planned?

Hi, thanks. Happy that you can see where I'm going with it. My goal was to reduce the complexly down to a fast, fun and easy way to access Lua from pascal.

Yes, I've made substantial investments this year getting setup for cross-platform development. Mostly desktop Windows, Linux and macOS.
1559

If I can continue getting feedback I should be able to get it ported to and working on other platforms. At this time, initial development is being done on Windows. I've not yet test freepascal, but in theory the current version should be able to work assuming the last versions of freepascal can support the TJetLuaValue structure with operator overloading. Passing TClass and TObject to those auto register function most likely will not work. There is already one routine that can manually register a global routines, which should work. I can add another one to manually register table routines. I will look more into this and see what I can come up with. Testing and feedback would be invaluable for me if your up for it.

drezgames
12-08-2020, 02:41 AM
@JernejL:

Good news, I got the interface routines down to the now probably the minimum that I can:


{ IJetLuaContext }
IJetLuaContext = interface
['{6AEC306C-45BC-4C65-A0E1-044739DED1EB}']


function PushCount: Integer;
procedure ClearStack;
procedure PopStack(aCount: Integer);
function GetStackType(aIndex: Integer): TLuaType;


function GetValue(aType: TJetLuaValueType; aIndex: Integer): TJetLuaValue;
procedure PushValue(aValue: TJetLuaValue);


procedure SetTableFieldValue(aName: PChar; aValue: TJetLuaValue; aIndex: Integer);
function GetTableFieldValue(aName: PChar; aType: TJetLuaValueType; aIndex: Integer): TJetLuaValue;
end;


{ TLuaFunction }
TJetLuaFunction = procedure(aLua: IJetLuaContext) of object;


{ IJetLua }
IJetLua = interface
['{671FAB20-00F2-4C81-96A6-6F675A37D00B}']


procedure Reset;


procedure LoadFile(aFilename: PChar; aAutoRun: Boolean = True);
procedure LoadString(aData: PChar; aAutoRun: Boolean = True);
procedure LoadBuffer(aData: Pointer; aSize: NativeUInt; aAutoRun: Boolean = True);


procedure Run;


function RoutineExist(aName: PChar): Boolean;
function Call(aName: PChar; const aParams: array of TJetLuaValue): TJetLuaValue;


function VariableExist(aName: PChar): Boolean;


procedure SetVariable(aName: PChar; aValue: TJetLuaValue);
function GetVariable(aName: PChar; aType: TJetLuaValueType): TJetLuaValue;


procedure RegisterRoutine(aName: PChar; aRoutine: TJetLuaFunction);


procedure RegisterRoutines(aClass: TClass); overload;
procedure RegisterRoutines(aObject: TObject); overload;
procedure RegisterRoutines(aTables: PChar; aClass: TClass; aTableName: PChar=nil); overload;
procedure RegisterRoutines(aTables: PChar; aObject: TObject; aTableName: PChar=nil); overload;


procedure AddVerInfo(aValue: Boolean);
procedure SetNoConsole(aValue: Boolean);
procedure SetVerInfo(aCompanyName: PChar; aFileVersion: PChar;
aFileDescription: PChar; aInternalName: PChar; aLegalCopyright: PChar;
aLegalTrademarks: PChar; aOriginalFilename: PChar; aProductName: PChar;
aProductVersion: PChar; aComments: PChar);
procedure SetExeFilename(aFilename: PChar);
procedure SetIconFilename(aFilename: PChar);
procedure EnableRuntimeThemes(aValue: Boolean);
procedure EnableHighDPIAware(aValue: Boolean);


procedure Compile(aSourceFilename: PChar; aPayloadFilename: PChar);


function HasPayload: Boolean;
procedure RunPayload;
end;




Bad news:
I did some initial tests and in it's present form, it will not work with freepascal, sigh. It's currently taking advantage of a lot of Delphi'ish features. Hopefully at some point I can get it working with freepascal.

drezgames
15-08-2020, 02:08 AM
clicky, https://github.com/tinyBigGAMES/JetLua

drezgames
16-08-2020, 02:02 PM
@JernejL

I added this new routine that allows Lua function registration in freepascal:


procedure IJetLua.RegisterRoutine(aName: PChar; aData: Pointer; aCode: Pointer);

So far so good. I will have to do more testing. The IJetLua.RegisterRoutines methods (the ones that take TClass and TObject params) take advantage of Delphi's extended RTTI to scan and find the JetLua function signatures for auto registration. With the added routine above, it now should be possible to implement auto registration in freepascal. Scan for the routines and call the above routine to register them. Does freepascal have extended RTTI like Delphi?

JernejL
24-08-2020, 11:38 AM
I know it has some RTTI, but i rarely dealt with that, it's question more suitable for lazarus forums.