Lua 5.1 for Delphi 2010
This is a Lua 5.1 Wrapper for Delphi 2009 and Delphi 2010 which automatically creates OOP callback functions.
“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.”
This Lua Wrapper is based on Lua-Pascal v0.2 by Marco Antonio Abreu
- converted PChar to PAnsiChar
- converted Char to AnsiChar
- added function LuaLibLoaded: Boolean;
- added a new base class (TLua) with OOP call back functions
Download
LuaDelphi2010-v1.3
History
1.3 Improved Callback, now uses pointer instead of object index. Modified RegisterFunctions to allow methods from other class to be registered, moved object table into TLua class
1.2 Added example on how to extend lua with a delphi dll
1.1 Improved global object table, optimized delphi function calls
1.0 Initial Release
Example
TLua automatically creates OOP callback functions for Delphi <-> Lua:
uses Lua, LuaLib; type TMyLua = class(TLua) 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('Arg1', I, ': ', Lua_ToInteger(LuaState, I)); // Clear stack Lua_Pop(LuaState, Lua_GetTop(LuaState)); // Push return values Lua_PushInteger(LuaState, 101); Lua_PushInteger(LuaState, 102); Result := 2; end; var MyLua: TLua; begin MyLua := TMyLua.Create; MyLua.DoFile('Helloworld.lua'); MyLua.Free; end;
helloworld.lua
print("LuaDelphi Test"); p1,p2 = HelloWorld(1,2,3) print "Results:"; print (p1); print (p2);
12 Comments to Lua 5.1 for Delphi 2010
You might like to link to the Lua site so that people unfamiliar with Lua (as I was) can find out what it is.
September 28, 2009
Sure. Thanks for that hint!
September 28, 2009
Nothing in the download link
September 29, 2009
Fixed. Download is working now, sorry.
December 24, 2009
Tried this, good work, works nice ( had to recompile for D6 ). By the way, LUA has all of these IO,Math,OS etc.. libraries and it seems that I cannot use them in my lua scripts for this wrapper.
I have tried adding luaopen_io(LuaInstance );
under your luaopen_base(LuaInstance); line in the constructor, but to no avail.
Any ideas?
December 25, 2009
luaL_openlibs(LuaInstance);
should load all libs
February 24, 2010
I can not compile this under Linux using Free pascal in Delphi mode. First error:
> fpc -Mdelphi LuaTest.dpr
LuaLib.pas(522,1) Fatal: Syntax error, “identifier” expected but “;” found
could easily be fixed by shifting the last comma from line 518 in front of line 520.
but than I have no idea how to fix the following errors:
Compiling ../Lib/LuaLib.pas
LuaLib.pas(283,3) Warning: cdecl’ared functions have no high parameter
LuaLib.pas(394,3) Warning: cdecl’ared functions have no high parameter
LuaLib.pas(397,3) Warning: cdecl’ared functions have no high parameter
LuaLib.pas(539,27) Error: Identifier not found “GetProcAddress”
LuaLib.pas(574,28) Error: Identifier not found “LoadLibrary”
LuaLib.pas(839,17) Error: Identifier not found “FreeLibrary”
LuaLib.pas(1146) Fatal: There were 3 errors compiling module, stopping
Any help is truly appreciated
Gerhard
February 24, 2010
To answer partly my own question:
To be compatible with Delphi/Windows I have to use the unit dynlibs that offers the missing functions.
Now your test program compiles with warnings but I get an access violation:
> ./LuaTest
EAccessViolation: Access violation
Program seems not to load the shared library im line 547 of LuaLib.pas
regards
Gerhard
May 14, 2010
nice work!
I test your example on Delphi 6, and it works!
After some little changes to example program, not Lua units.
So, you may say that works not only 2009+ version.
May 14, 2010
Yaroslav, thanks for your info!
,
ya, this is exactly what i was looking for! Thanks! Works fine on Delphi 2009 (DE/US). My boss will love this too xD
August 16, 2010
[...] Другая реализация (на базе LuaPascal) DelphiLua v1.3. Скачать. [...]
Leave a comment
About
Recent Posts
- Eclipse on Mac OS X – Workspace error on NFS mounts
- Lua 5.1 for Delphi 2010
- WordPress Plugin – QR Code Tag v1.0
- Favourite Android applications
- Hint: Blank Typo3 installation screen
- How to create an ESXi v4 Whitebox ISO with Windows Tools
- Ext: tt_news – no translation for name of months
- check_apachestatus_auto.pl v1.2 released
- Ext: indexed_search – Disable indexing of meta tags
- nagios_mdaemon_check.exe v1.0 released
Search
Categories
Tags
Archives
Blogroll
Delphi Feeds
- Ingenious!
- Visual Forms 2.0.1 – Delphi XE
- BlackFish SQL Gone in Delphi XE, What About a Replacement?
- Delphi XE Released
- SamplingProfiler v1.7.5
- Castalia 2010.3
- Download links for Delphi XE, C++Builder XE, RAD Studio XE, Delphi Prism XE and RadPHP XE
- Download links for Delphi XE, C++Builder XE, RAD Studio XE, Delphi Prism XE and RadPHP XE
- tMPlayer: a Delphi Video Player
- DelphiLive 2010 blog posts….
I'm an avid programmer working on a variety of platforms in a variety of languages with a wide technical interest.

September 28, 2009