SRL Archive - OSR Help

Creating Simba plugins


Er1k

2012-03-27 09:32:24

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.

Sex

2012-03-28 20:00:15

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 :).

Er1k

2012-03-29 10:26:47

From: Sex
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.

Sex

2012-03-29 12:43:42

From: Er1k
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:

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:
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 :p.

Er1k

2012-03-29 19:54:18

Haven't run it yet, but at first glance the getTypeCount/getTypeInfo is new :D Didn't see it anywhere before in the tutorial. Looks nice and I'll surely give it a try when I get home.

Sex

2012-03-29 22:24:41

Yeah, that's what you're looking for :).