[Free Pascal] is a well-supported Pascal compiler available on many platforms.

All routines from the C API and auxiliary library mentioned in the Lua 5.1 reference manual are supported in the lua, lualib or lauxlib libraries of Free Pascal 2.4. For Lua 5.2, see the section below. There is no documentation, but you can use the Lua manual since the call sequences are basically identical, with only a few exceptions.

In order to split strings over multiple lines in Free Pascal, create multiple string constants that are concatenated via the '+' operator. Alternatively, you can store your Lua code in files, or put it all on one line.

Type names

luaL_Reg => lua_CFunction

Most others are obvious, with P used for pointer, e.g.

luaState* => Plua_State

or standard, e.g.

void* => Pointer
int => Integer

You can always look at the interface of lauxlib.pas etc
(package fpc-source on Ubuntu) to make sure.

This update conforming to Lua 5.2 was made by Egor Skriptunoff. Some further improvements, including Delphi compatibility, were added by Vladimir Klimov. See the comments at the start of lua52.pas for full details. The version here was uploaded on 1 May 2013. A more recent version (1 March 2014) with mainly cosmetic changes is available but attempts to upload it have so far failed.

Note that PChar and String in Free Pascal have been implemented as Unicode since December 2009. To retain Lua compatibility, the types PAnsiChar and AnsiString are now used.

Only one unit lua52 is needed, not three units. A minimal usage example is: