Free Lua Scripting Interpreter Library For Delphi XE7 Firemonkey On Android And IOS

來源:互聯網
上載者:User

標籤:

http://www.fmxexpress.com/free-lua-scripting-interpreter-library-for-delphi-xe7-firemonkey-on-android-and-ios/

http://blog.spreendigital.de/tag/delphi/

http://blog.spreendigital.de/2015/02/18/verysimple-lua-2-0-a-cross-platform-lua-5-3-0-wrapper-for-delphi-xe5-xe7/

 

Dynamic library vs. static library VerySimple.Lua uses the lua dynamic library if compiled for Windows, Mac OS X or Android and uses the static library if compiled for iOS (all libraries included).

Unit tests < excuse type=”lame”>This binding is based on my now 6 year old Lua 5.1 delphi binding, and I didn’t had time for writing (updated) unit tests</excuse>.

Automatic get/setters for properties, etc. As the name implies: it is just a very simple Lua <-> delphi binding. Feel free to add those functions by yourself.

Tags: binding, Delphi Programming, Lua

Developer Dennis D. Spreen has released an upgraded wrapper component for Lua 5.3 that allows you to run Lua scripts in Delphi XE7 Firemonkey. The wrapper which is called VerySimple.Lua uses the Lua static and dynamic libraries to enable the component on Android, IOS, Windows, and OSX. Between this component and paxCompiler you can now interpret Lua, Object Pascal, Basic, and Javascript on all four Firemonkey platforms at runtime. Blizzard uses Lua as the scripting language in World of Warcraft as one example of where people use Lua. There is some sample code for using the wrapper on the blog post itself. There is also more sample code for using VerySimple.Lua and interpreting Lua scripts in both FMX and VCL on Google Code and in the download. This Lua scripting interpreter component should also work with Appmethod. It is free and full source code is available. A dynamic library is used on Android, OSX, and Windows. A static library is used on IOS. I looked through the code and here is a snippet for how it loads the dynamic Lua library:

{$IFNDEF STATICLIBRARY}

// check if Library exists if not FileExists(LoadPath) then raise ELuaLibraryNotFound.Create(‘Lua library “‘ + QuotedStr(LoadPath) + ‘” not found’);

// try to load the library LibraryHandle := LoadLibrary(PChar(LoadPath)); if LibraryHandle = 0 then raise ELuaLibraryLoadError.Create(‘Failed to load Lua library “‘ + QuotedStr(LoadPath) + ‘”‘ {$IF defined(POSIX)} + (String(dlerror)){$ENDIF});

lua_newstate := GetAddress(‘lua_newstate’); lua_close := GetAddress(‘lua_close’);

 

http://blog.spreendigital.de/2015/02/18/verysimple-lua-2-0-a-cross-platform-lua-5-3-0-wrapper-for-delphi-xe5-xe7/

 

VerySimple.Lua is a Lua 5.3 binding for Delphi XE5- XE7 which automatically creates OOP callback functions for Win32, Win64, Mac OS X, iOS and Android. “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.”

Download current version at Google Code

What’s new in v2.0?

 

  • Lua 5.3.0 support (all header translations done from scratch)
  • cross-platform – Windows 32 bit, Windows 64 bit, Mac OS X, iOS and Android
  • improved autoregister function – with the help of TRtti it registers only valid methods
  • simplified callback with upvalues instead of pointer list
  • package support
  • examples included (VCL and Firemonkey)

Example 1 – Simple usage

 
12345678910  uses  VerySimple.Lua; begin  Lua := TVerySimpleLua.Create;  Lua.DoFile(‘example1.lua‘);  Lua.Free;end; 

Example 2 – Extend Lua with own functions

 
12345678910111213141516171819202122232425262728293031323334353637  uses  VerySimple.Lua, VerySimple.Lua.Lib; type  TMyLua = class(TVerySimpleLua)  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(‘Arg‘, I, ‘: ‘, Lua_ToInteger(LuaState, I));   // Push return values  Lua_PushInteger(LuaState, 101);  Lua_PushInteger(LuaState, 102);  Result := 2;end; var  MyLua: TMyLua; begin  MyLua := TMyLua.Create;  MyLua.DoFile(‘helloworld.lua‘);  MyLua.Free;end; 

helloworld.lua

 
1234567  print("LuaDelphi Test");p1,p2 = HelloWorld(1,5,15)print "Results:";print (p1);print (p2); 

Output:

 
1234567891011  LuaDelphi TestDelphi: Hello WorldArguments: 3Arg1: 1Arg2: 5Arg3: 15Results:101102 

 

Free Lua Scripting Interpreter Library For Delphi XE7 Firemonkey On Android And IOS

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.