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:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
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
1 2 3 4 5 6 7 8 |
print("LuaDelphi Test"); p1,p2 = HelloWorld(1,2,3) print "Results:"; print (p1); print (p2); |
38 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!
June 14, 2010
:o,
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. Скачать. […]
October 22, 2010
This is a great blog. Thanks for all your hard work and the info you give. I am hoping you post again soon.I wish u keep on.
Thank you
http://frankieespinoza.livejournal.com/878.html
January 28, 2011
Hi. I am a Pascal programmer. Been one all my life. All my code is in Pascal. Don’t know anything about C.
Now the world is turning ‘Mobile’. And I have to develop for Apple IOS and Android.
I am now trying Lua, specifically, Corona.
But I _need_ to use a lot of my Pascal code in the apps. I was hoping that with a LuaDelphi system, I could generate _pre-compiled_ modules, or whatever you want to call them, which can then be loaded into Lua and used in iPhone, iPad and Android devices.
Is there ANY way this could be done?
Thanks
January 28, 2011
Corona is very nice (I use it, too!). It is not possible to load standard lua binary compiled modules (luac) into Corona. But with the new Windows version of Corona you don’t even need a Mac. You may develop with LuaDelphi and copy&paste the Lua-source code (not the binaries) into corona editor. But this doesn’t make anything easier – you’re programming with LUA (not pascal)…
January 28, 2011
oh and btw: any extensions to the Lua language (or object interaction) you’re building with LuaDelphi aren’t available in the Corona-LuaCore-system…
April 4, 2011
hi, i’m not a great programer for delphi, but is the only language i know :p
can you send to my mail some compile code with source.
I want to know how luadelphi works and try to do something.
thank you and sorry my poor english, i’m from Argentina.
maxiducoli@gmail.com is my mail.
April 4, 2011
@maxiducoli:
Just download the ZIP, extract and load “LuaTest.dpr” in the folder “\Examples”. It’s a ready-to-compile Test project with the LUA.DLL already included in the folder.
November 9, 2011
Now I fully appreciate your work 🙂
All existing delphi-to-lua bindings is only for before-unicode delphi.
Thanx for your job!
November 9, 2011
You make take a look at Lua4Delphi, too:
http://www.simonjstuart.com/lua-projects/lua4delphi/
November 10, 2011
2 Dennis
it isnt’t ready still :(((
November 10, 2011
2 Dennis
it still not ready 🙁
December 12, 2011
It’ll be ready VERY soon 🙂
I even have experimental (will develop it further after release) Unicode support with Lua (as in, actually passing Unicode values between Lua and Delphi).
December 25, 2011
Is it possible to pass a an object from Delphi to Lua?
April 28, 2012
Hi, Dennis!
Can I use your Lua Wrapper (LuaDelphi2010-v1.3) in a commercial game project, with closed source? Do I need to buy a license for this?
And can I change a small part of your code at the same time? For compatibility with my code.
April 28, 2012
@nikolai:
do whatever you want with it – no license required (even for commercial use). It would be nice to get a short note if used in a project. thanks!
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
April 28, 2012
Thanks. It is excellent 🙂 I am notifying you if my project will be completed.
December 26, 2012
How to use “require” ?
like this :
local mongodb = require “mongodb”
March 8, 2013
Hi
Great to see lua working with delphi 😀
Any hints how to get current script line?
I tried something like that but it returns garbage:
procedure TLuaClass.printErr(s: string);
var
d:lua_Debug;
begin
lua_getstack(self.LuaInstance,1,d);
lua_getinfo(self.LuaInstance,pansichar(‘nS1′),d);
print(inttostr(d.currentline)+’: ‘+s);
end;
March 23, 2013
[…] […]
April 2, 2013
Dennis, hele me , how to read this file, i want read all table and number
MaxID = 7
Tax1 =1
Tax2 =2
Object GoldName = 1
{
Object Gold = 2
{
Object Gold = 3
{
ID = 2001
cast = 1
}
}
Object Silver = 4
{
Object Silver = 5
{
ID = 2002
broadcast = 1
}
}
Object Copper = 6
{
Object Copper = 7
{
ID = 2003
broadcast = 1
}
}
}
April 2, 2013
@lf: this does not look like an xml file
June 29, 2013
Hi, I modify a little for FPC 🙂
http://www.mediafire.com/download/67g47pexae42krq/luaFpc2010-v1.3.zip
June 30, 2013
Hello again, porting lua 5.2 🙂
http://www.mediafire.com/download/5dtxq7dgqd236y7/luaFpc2010-v1.3-lua5.2.zip
February 3, 2015
any port for 5.3?
February 3, 2015
99.8% finished 😉
February 9, 2015
Hi Dennis,
99.9% or %100 😀
February 18, 2015
About Dennis D. Spreen
Search
Recent Posts
- How to compile Lua 5.4.0 for Android as a dynamic library using Android Studio 4
- Please make inline vars usable for production – fix RSP-28892
- How to compile Lua 5.4.0 as a Mac OS X dynamic library
- How to compile Lua 5.4.0 for Linux as a shared library
- How to compile Lua 5.4.0 for Windows
- Daily Wage – a Spigot/Bukkit plugin that pays out a daily wage
- How to compile Lua 5.3.5 for Windows
- Better Collada exporter for Blender with custom properties
- MOS6502-delphi – a MOS 6502 CPU emulator for Delphi
- Pass a multidimensional array as a parameter (with a hidden caveat)
Categories
Tags
Archives
- May 2020
- March 2020
- June 2019
- March 2017
- August 2016
- July 2016
- June 2016
- January 2016
- September 2015
- February 2015
- January 2015
- October 2014
- September 2014
- August 2014
- May 2014
- March 2014
- February 2014
- November 2011
- June 2011
- February 2011
- March 2010
- September 2009
- August 2009
- July 2009
- May 2009
- March 2009
- February 2009
- January 2009
- November 2008
- October 2008
- February 2008
- June 2007
Delphi Feeds
- Select and edit directory paths in Delphi desktop applications with TTMSFNCDirectoryEdit November 20, 2024
- How To Use WebStencils To EASILY Create Modern, Professional, Superfast Websites November 19, 2024
- Creating Heatmaps in TMS FNC Maps for Delphi November 19, 2024
- Discover C++Builder 12.2 – Asia Pacific Webinar November 19, 2024
- The Horror of finding the right database! Part 2 November 18, 2024
- Using ARM runner to automatically build releases for Raspberry Pi using GitHub Actions November 16, 2024
- Signing and Validating JWTs with Private/Public Keys in Delphi with XData November 16, 2024
- QuickReport Is Back! November 15, 2024
- TMS Cryptography Pack Beta available November 14, 2024
- New Features in TMS FNC Chart: Enhanced Data Integration, Flexibility and Styling November 14, 2024
September 28, 2009