Go to file
Mark van Renswoude 745c8b5a35 Added Get/Set/AddRequirePath methods 2017-06-04 11:16:55 +02:00
UnitTests Fixed string conversion warning in lua_where 2017-05-31 22:00:26 +02:00
.gitignore Added exception handling for registered functions 2017-05-28 16:34:51 +02:00
Lua.API.pas Fixed issue with lua_debug struct size causing corruption 2017-05-31 22:29:36 +02:00
Lua.pas Added Get/Set/AddRequirePath methods 2017-06-04 11:16:55 +02:00
README.md 64-bits compatibility 2016-02-07 18:06:05 +01:00

README.md

DelphiLua

definitely not the most creative project name

This project consists of two parts: a straight-up conversion of the LuaBinaries 5.2 C headers to Delphi, and the TLua class to make integrating Lua with Delphi projects easier.

A note on compatibility

It's been tested and developed on Delphi XE2 32-bits and 64-bits. Minimum version for the wrapper is probably 2010, due to anonymous functions and TRttiContext being used.

Getting started

Download lua-5.2.4_Win32_bin.zip or lua-5.2.4_Win64_bin.zip from LuaBinaries and extract lua52.dll.

If you're just interested in the API, the Lua manual is the best place to start.

For the wrapper, take a look at the unit tests in TestWrapper.pas. Be sure to copy Lua52.dll into the output path if you're gonna run the unit tests or your own project.

A very, very simple example

Load a script from a string, passing two variables A and B and having the script sum them up into variable C.

var
  lua: TLua;
  returnValue: Integer;

begin
  lua := TLua.Create;
  try
    lua.SetGlobalVariable('A', 5);
    lua.SetGlobalVariable('B', 10);

    lua.LoadFromString('C = A + B');

    returnValue := lua.GetGlobalVariable('C').AsInteger;
  finally
    FreeAndNil(lua);
  end;
end;

...of course, you can do much more exciting things like calling Delphi functions from Lua or vice versa. Check out the Call and RegisterFunction(s) methods. Have fun!