Results 1 to 6 of 6

Thread: Creating Simba plugins

  1. #1
    Join Date
    Nov 2011
    Posts
    1,532
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default Creating Simba plugins

    I came across some old threads on creating a simba plugin, and I'm interested to make one to see how it works. I found this tutorial http://villavu.com/forum/showthread.php?t=58815 . Just wondering if anyone knows if this still works nowadays.

    I think I get the idea of how to work with basic types such as integer, string, and so on. But I am not so sure how to write a plugin that takes arrays as argument and returns array (similar to the TPA functions in wizzyplugin?). Can anyone explain what I need to do to get it to work?

    Thanks in advance.
    Current activity: Recovering from vacation
    - Nulla pars vitae vacare officio potest -
    SRL membership? Can I buy that?
    Scripts - AGS - SWF - WAR - EMS - W100S-EM
    If you need scripting help, you can pm me. Remember, if you need help you have to ask for it properly though

  2. #2
    Join Date
    Oct 2009
    Location
    Stockton, CA
    Posts
    2,040
    Mentioned
    0 Post(s)
    Quoted
    1 Post(s)

    Default

    Yes, that works fine. Though those plugins will only work with the PascalScript interpreter for the time being. If you want to work with Lape plugins check out the link in my signature.

    You can take arrays as arguments and return arrays the same way you do in Simba, you just declare the types at the top of your script. You can also export your own types. If you can be a little more specific, I'd be able to help .
    Join the IRC! irc.rizon.net:6667/srl | SQLite (0.99rc3+) | SRL Doc | Simba Doc | Extra Simba Libraries (openSSL & sqlite3)
    Quote Originally Posted by #srl
    10:45 < Toter> daphil when can get sex anyday I want
    10:45 < Toter> he is always on #SRL
    "A programmer is just a tool which converts caffeine into code"

  3. #3
    Join Date
    Nov 2011
    Posts
    1,532
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by Sex View Post
    Yes, that works fine. Though those plugins will only work with the PascalScript interpreter for the time being. If you want to work with Lape plugins check out the link in my signature.

    You can take arrays as arguments and return arrays the same way you do in Simba, you just declare the types at the top of your script. You can also export your own types. If you can be a little more specific, I'd be able to help .
    Thanks for your reply. I have actually given it a try and managed to export a TIntegerArray type to simba and got it to work. But how do you export custom types other than those already used by simba? For example, how about an array [0..8] of integer? I tried declaring a type in both simba and the dll, but it won't recognize.
    Current activity: Recovering from vacation
    - Nulla pars vitae vacare officio potest -
    SRL membership? Can I buy that?
    Scripts - AGS - SWF - WAR - EMS - W100S-EM
    If you need scripting help, you can pm me. Remember, if you need help you have to ask for it properly though

  4. #4
    Join Date
    Oct 2009
    Location
    Stockton, CA
    Posts
    2,040
    Mentioned
    0 Post(s)
    Quoted
    1 Post(s)

    Default

    Quote Originally Posted by Er1k View Post
    Thanks for your reply. I have actually given it a try and managed to export a TIntegerArray type to simba and got it to work. But how do you export custom types other than those already used by simba? For example, how about an array [0..8] of integer? I tried declaring a type in both simba and the dll, but it won't recognize.
    Again, you export it the same. Instead of array of integer you put array [0..8] of integer. Doesn't that work?

    Edit: Made you an example:
    Simba Code:
    library test;

    {$mode objfpc}{$H+}

    uses
      Classes, sysutils
      { you can add units after this };

    type
       TTestIntegerArray = array [0..8] of integer;
       
    {$R *.res}

    procedure populate(var arr : TTestIntegerArray); stdcall;
    var
      i : integer;
    begin
      for i := 0 to high(arr) do
        arr[i] := random(100);
    end;

    function GetTypeCount() : Integer; stdcall; export;
    begin
      Result := 1;
    end;

    function GetTypeInfo(x: integer; var sType, sTypeDef : string): integer; stdcall;
    begin
      result := x;
      case (x) of
        0 : begin
          sType := 'TTestIntegerArray';
          sTypeDef := 'array [0..8] of integer;';
        end;
      else
        result := -1;
      end;
    end;

    function GetFunctionCount(): Integer; stdcall; export;
    begin
      Result := 1;
    end;

    function GetFunctionInfo(x: Integer; var ProcAddr: Pointer; var ProcDef: PChar): Integer; stdcall; export;
    begin
      case x of
        0:
          begin
            ProcAddr := @populate;
            StrPCopy(ProcDef, 'procedure populate(var t : TTestIntegerArray);');
          end;
      else
        x := -1;
      end;
      Result := x;
    end;

    exports GetFunctionCount, GetFunctionInfo,
            GetTypeCount, GetTypeInfo;

    begin
    end.
    Build that plugin, place it in your plugins folder, run this script in Simba:
    Simba Code:
    program test;
    {$loadlib test}

    var
      arr : TTestIntegerArray;
    begin
      writeln(length(arr)); // should be 9
      writeln(arr); // should be all zeroes
      populate(arr); // fills with random numbers
      writeln(arr); // should be now filled with random numbers
      setarraylength(arr, 8); // should fail
    end.
    Hope that works .
    Last edited by Sex; 03-29-2012 at 05:00 PM.
    Join the IRC! irc.rizon.net:6667/srl | SQLite (0.99rc3+) | SRL Doc | Simba Doc | Extra Simba Libraries (openSSL & sqlite3)
    Quote Originally Posted by #srl
    10:45 < Toter> daphil when can get sex anyday I want
    10:45 < Toter> he is always on #SRL
    "A programmer is just a tool which converts caffeine into code"

  5. #5
    Join Date
    Nov 2011
    Posts
    1,532
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Haven't run it yet, but at first glance the getTypeCount/getTypeInfo is new Didn't see it anywhere before in the tutorial. Looks nice and I'll surely give it a try when I get home.
    Current activity: Recovering from vacation
    - Nulla pars vitae vacare officio potest -
    SRL membership? Can I buy that?
    Scripts - AGS - SWF - WAR - EMS - W100S-EM
    If you need scripting help, you can pm me. Remember, if you need help you have to ask for it properly though

  6. #6
    Join Date
    Oct 2009
    Location
    Stockton, CA
    Posts
    2,040
    Mentioned
    0 Post(s)
    Quoted
    1 Post(s)

    Default

    Yeah, that's what you're looking for .
    Join the IRC! irc.rizon.net:6667/srl | SQLite (0.99rc3+) | SRL Doc | Simba Doc | Extra Simba Libraries (openSSL & sqlite3)
    Quote Originally Posted by #srl
    10:45 < Toter> daphil when can get sex anyday I want
    10:45 < Toter> he is always on #SRL
    "A programmer is just a tool which converts caffeine into code"

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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