All routines from the C API and auxiliary library mentioned in the Lua 5.1 reference manual are supported in the
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.
luaL_Reg => lua_CFunctionMost others are obvious, with P used for pointer, e.g.
luaState* => Plua_Stateor standard, e.g.
void* => Pointer int => IntegerYou can always look at the interface of
fpc-sourceon Ubuntu) to make sure.
Some names starting with
lua_L are different (probably typos):
luaL_dofile => lua_dofile luaL_dostring => lua_dostring luaL_getmetatable => lua_Lgetmetatable
uses lua, lualib, lauxlib; var L: Plua_State; result: integer; begin L := lua_open(); luaL_openlibs(L); result := lua_dostring(L, 'for k in string.gmatch("a,b,c,d,e,f,g,h","([^,]+),") do print(k) end' ); lua_close(L); end.
the Pascal source] of the unit and save it under the name
LUA_LIB_NAMEto that of your system's Lua 5.2 shared library. Some possible names are
liblua5.2.so(Debian, Ubuntu etc) and
liblua.so.5.2(Red Hat, Fedora etc).
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.
String in Free Pascal have been implemented as Unicode since December 2009. To retain Lua compatibility, the types
AnsiString are now used.
Only one unit
lua52 is needed, not three units. A minimal usage example is:
uses lua52; (* 5.2 change *) var L: Plua_State; result: integer; begin L := luaL_newstate(); (* 5.2 change *) luaL_openlibs(L); result := luaL_dostring(L, 'print (unpack,table.unpack)'); lua_close(L); end.