GithubHelp home page GithubHelp logo

verysimplelua's Introduction

==============================================
VerySimple.Lua - Lua 5.3.0 for Delphi XE5-10.1
==============================================
(c) 2009-2016 Dennis D. Spreen
http://blog.spreendigital.de/2015/02/18/verysimple-lua-2-0-a-cross-platform-lua-5-3-0-wrapper-for-delphi-xe5-xe7/

History
2.1     DS      Added [hidden] attribute
                Added OnError property
                Fixed MULTIRET lua call
		Fixed function luaL_testudata
2.0.3   DS      Fix XE5 - Added Pointer cast for RegisterFunc
2.0.2   DS      Fix: added missing lua_isinteger function
2.0.1   DS      Fix: fixed Register function 
                Added Example 6 - Call a Lua function
2.0     DS      Updated Lua Lib to 5.3.0
                Rewrite of Delphi register functions
                Removed Class only functions
                Removed a lot of convenience overloaded functions
                Support for mobile compiler
1.4     DS      Rewrite of Lua function calls, they use now published static
                methods, no need for a Callbacklist required anymore
                Added Package functions
                Added Class registering functions
1.3     DS      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	DS	Added example on how to extend lua with a delphi dll
1.1     DS      Improved global object table, this optimizes the delphi
                function calls
1.0     DS      Initial Release


This is a Lua Wrapper for Delphi XE5-D10.1 which 
automatically creates OOP callback functions for Delphi <-> Lua:


uses
  VerySimple.Lua, VerySimple.Lua.Lib;

type
  TMyLua = class(TVerySimpleLua)
  published
    function HelloWorld(LuaState: TLuaState): Integer;
  end;

function TMyLua.HelloWorld(LuaState: TLuaState): Integer;
var
  ArgCount: Integer;
  I: integer;
begin
  ArgCount := Lua_GetTop(LuaState);

  writeln('Delphi: Hello World');
  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: TVerySimpleLua;

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


**************************************************************************
Copyright 2016  Dennis D. Spreen (http://blog.spreendigital.de/)

VerySimple.Lua is distributed under the terms of the Mozilla Public License, 
v. 2.0. If a copy of the MPL was not distributed with your software, 
You can obtain one at http://mozilla.org/MPL/2.0/.

**************************************************************************

verysimplelua's People

Contributors

dennis1000 avatar zaher avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

verysimplelua's Issues

Version for Delphi XE2

Hello,
thanks for your very nice units.
I adapted them to work with Delphi XE2. The only modifications required are:

  1. substitute $ENDIF with $IFEND in the conditional compilation beginning with $IF defined(...)

  2. insert this conditional block in VerySimple.Lua.Lib in Interface types part:
    // Compile for Delphi <= XE2
    {$IF CompilerVersion<=23}
    MarshaledAString = PAnsiChar;
    PMarshaledAString = ^PAnsiChar;
    TMarshString = record
    s: string;
    function ToPointer(): PAnsiChar;
    end;
    TMarshaller = record
    s: string;
    function AsAnsi(s: string): TMarshString;
    end;
    {$ifend}

  3. insert this conditional block in VerySimple.Lua.Lib under Implementation part:
    // Compile for Delphi <= XE2
    {$IF CompilerVersion<=23}
    function TMarshString.ToPointer(): PAnsiChar;
    begin
    Result:=PAnsiChar(AnsiString(s));
    end;
    function TMarshaller.AsAnsi(s: string): TMarshString;
    var
    ms: TMarshString;
    begin
    ms.s:= s;
    Result:= ms;
    end;
    {$ifend}

Of course it emulates types MarshaledAString and TMarshaller that are present only in newer versions of Delphi.
Regards

Giandomenico De Sanctis


Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

Example request (call a Lua function from a Delphi program)

Hello! It isn't an issue, but rather a request for a code example.

I would like to call a Lua function from my Delphi program, and get the result, 
as you can see in the attached example. What would my code look like, if I 
would use VerySimple.Lua?

Best regards.

Roland Chastain

Original issue reported on code.google.com by [email protected] on 21 Feb 2015 at 6:12

Attachments:

how to Register a variable

lua code
test = TTest.new();
test.dosomething();
print(test.somevalue);

--- Want to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/41737864-how-to-register-a-variable?utm_campaign=plugin&utm_content=tracker%2F13496533&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F13496533&utm_medium=issues&utm_source=github).

Exapmles 3 and 4 (FMX) does not work

  1. Lua.LibraryPath is invalid
  2. After fixing #1 nothing is printed in Memo. print function is not called at all.
--- Want to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/40647567-exapmles-3-and-4-fmx-does-not-work?utm_campaign=plugin&utm_content=tracker%2F13496533&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F13496533&utm_medium=issues&utm_source=github).

Wrong function declaration: lua_testudata

The function reads as such:

procedure luaL_testudata(L: lua_State; ud: Integer; const tname: MarshaledAString);

However the lua 5.3 documentation declares it with a return type of void *. I suggest this change:

function luaL_testudata(L: lua_State; ud: Integer; const tname: MarshaledAString): Integer;

Thanks for your great work in translating the C headers, it helped me tremendously.

how return a object

lua code
test = TTest.new();
test.dosomething();

how code the TTest in delphi?

delphi code

function TTest.new(L:lua_State):Integer;
var
obj:TTest;
begin
obj:=TTest.Create;
lua_pushobject(L,obj);
return 1;
end;

--- Want to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/41360840-how-return-a-object?utm_campaign=plugin&utm_content=tracker%2F13496533&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F13496533&utm_medium=issues&utm_source=github).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.