Results 1 to 8 of 8

Thread: c(++) to delphi?

  1. #1

    c(++) to delphi?

    I encountered the following c syntax how do i convert it to delphi?

    Code:
    static const struct lual_reg arraylib [] = {
    {"new", newarray},
    {"set", setarray},
    {"get", getarray},
    {"size", getsize],
    {NULL,NULL}
    };
    This structure has to be passed to a c function in a dll. I am out of ideas...
    http://3das.noeska.com - create adventure games without programming

  2. #2

    c(++) to delphi?

    It would be helpful if you posted the structure definition too...
    [size=10px][ Join us in #pgd on irc.freenode.net ] [ Sign the Petition for a Software Patent Free Europe ][/size]

  3. #3

    c(++) to delphi?

    here is the lua_reg structure as it appears in lua.pas:
    Code:
    type
      luaL_reg = record
        name: PChar;
        func: lua_CFunction;
      end;
      PluaL_reg = ^luaL_reg;
    
    var
      luaL_openlib: procedure(L: Plua_State; const lr: PluaL_reg; nup: Integer); cdecl;
    and this as in lauxlib.h:
    Code:
    typedef struct luaL_reg {
      const char *name;
      lua_CFunction func;
    } luaL_reg;
    
    
    LUALIB_API void luaL_openlib (lua_State *L, const char *libname,
                                   const luaL_reg *l, int nup);
    I hope this helps explaining the problem....

    Also:
    Code:
    typedef struct lua_State lua_State;
    
    typedef int (*lua_CFunction) (lua_State *L);
    is in delphi:
    Code:
    type
      Plua_State = Pointer;
    
      lua_CFunction = function(L: Plua_State): Integer; cdecl;
    This last thing is known to work ok.
    http://3das.noeska.com - create adventure games without programming

  4. #4

    c(++) to delphi?

    This should do it.

    Code:
    implementation
    
    const
      arraylib = array [0..4] of lual_reg =
      (
        (name: 'new'; func: newarray),
        (name: 'set'; func: setarray),
        (name: 'get'; func: getarray),
        (name: 'size'; func: getsize),
        (name: nil; func: nil)
      );
    
    begin
      // Note that PAS declaration is missing the libname parameter
      luaL_openlib(@luaState, 'libname', @arraylib[0], High(arraylib));
    end;

  5. #5

    c(++) to delphi?

    A bit off topic, but where did you find the delphi headers? I've search for it but haven't found any.
    Signature:
    <br />This is a block of text that can be added to posts you make. There is a 255 character limit

  6. #6

    c(++) to delphi?

    ultra look here: http://assoc.wanadoo.fr/thallium-software/thlua.en.html

    sly your solution does not seem to work. It looks ok though...
    http://3das.noeska.com - create adventure games without programming

  7. #7

    c(++) to delphi?

    Thanks for the tip. I'm sorry I can't seem to find a solution to your problem.
    Signature:
    <br />This is a block of text that can be added to posts you make. There is a 255 character limit

  8. #8

    c(++) to delphi?

    It turned out the procedure definition for luaL_openlib in the lua.pas file was wrong. I uploaded the final working example here: http://www.noeska.com/dlua/downloads.aspx

    Are there more people here interested in lua? As it seems that the thlua is not maintained anymore. Meaning the lua.pas is not up to date anymore.
    http://3das.noeska.com - create adventure games without programming

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •