VerySimple.Lua is a Lua 5.3 binding for Delphi XE5- XE7 which automatically creates OOP callback functions for Win32, Win64, Mac OS X, iOS and Android.
“Lua is a powerful, fast, lightweight, embeddable scripting language, it has been used in many industrial applications (e.g., Adobe’s Photoshop Lightroom), with an emphasis on embedded systems (e.g., the Ginga middleware for digital TV in Brazil) and games (e.g., World of Warcraft). Lua is currently the leading scripting language in games and it has a deserved reputation for performance. To claim to be “as fast as Lua” is an aspiration of other scripting languages.”
What’s new in v2.0?
- Lua 5.3.0 support (all header translations done from scratch)
- cross-platform – Windows 32 bit, Windows 64 bit, Mac OS X, iOS and Android
- improved autoregister function – with the help of TRtti it registers only valid methods
- simplified callback with upvalues instead of pointer list
- package support
- examples included (VCL and Firemonkey)
Example 1 – Simple usage
uses VerySimple.Lua; begin Lua := TVerySimpleLua.Create; Lua.DoFile('example1.lua'); Lua.Free; end;
Example 2 – Extend Lua with own functions
uses VerySimple.Lua, VerySimple.Lua.Lib; type TMyLua = class(TVerySimpleLua) published function HelloWorld(LuaState: TLuaState): Integer; end; function TMyLua.HelloWorld: Integer; var ArgCount: Integer; I: integer; begin writeln('Delphi: Hello World'); ArgCount := Lua_GetTop(LuaState); writeln('Arguments: ', ArgCount); for I := 1 to ArgCount do writeln('Arg', I, ': ', Lua_ToInteger(LuaState, I)); // Push return values Lua_PushInteger(LuaState, 101); Lua_PushInteger(LuaState, 102); Result := 2; end; var MyLua: TMyLua; begin MyLua := TMyLua.Create; MyLua.DoFile('helloworld.lua'); MyLua.Free; end;
helloworld.lua
print("LuaDelphi Test"); p1,p2 = HelloWorld(1,5,15) print "Results:"; print (p1); print (p2);
Output:
LuaDelphi Test Delphi: Hello World Arguments: 3 Arg1: 1 Arg2: 5 Arg3: 15 Results: 101 102
Dynamic library vs. static library
VerySimple.Lua uses the lua dynamic library if compiled for Windows, Mac OS X or Android and uses the static library if compiled for iOS (all libraries included).
Unit tests
<excuse type=”lame”>This binding is based on my now 6 year old Lua 5.1 delphi binding, and I didn’t had time for writing (updated) unit tests</excuse>.
Automatic get/setters for properties, etc.
As the name implies: it is just a very simple Lua <-> delphi binding. Feel free to add those functions by yourself.