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);

Tags: Delphi ProgrammingLua

转载于:https://www.cnblogs.com/zerovirs/p/3297914.html

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值