Richard
01-18-2012, 02:40 AM
I'm about to begin developing a plugin for this new idea I'd had, but I've never previously developed a plugin before, so I thought I'd have a go at using one of my more basic functions in there. The point is very simple, it's returning nothing when it should return something.
Here is the code I'm using in the plugin:
library project1;
{$mode objfpc}{$H+}
uses
Classes, sysutils, mufasatypes
{ you can add units after this };
function IntArrayTo2D(intarray: TIntegerArray; dimlength: Integer) : T2DIntegerArray; register;
var
i: Integer;
begin
if (Length(intarray) mod dimlength) <> 0 then
exit;
SetLength(Result, Length(intarray) div dimlength);
for i := 0 to High(Result) do
SetLength(Result[i], dimlength);
for i := 0 to High(intarray) do
Result[i div dimlength][i mod dimlength] := intarray[i];
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 := @IntArrayTo2D;
StrPCopy(ProcDef, 'function IntArrayTo2D(intarray: TIntegerArray; dimlength: Integer) : T2DIntegerArray;');
end;
else
x := -1;
end;
Result := x;
end;
exports GetFunctionCount;
exports GetFunctionInfo;
begin
end.
And using IntArrayTo2D there does NOT work. However, if I then use the same code, but simply have it as a script in Simba, it works perfectly:
program SimbaPluginTest;
//{$LoadLib project1}
function IntArrayTo2D(intarray: TIntegerArray; dimlength: Integer) : T2DIntegerArray;
var
i: Integer;
begin
if (Length(intarray) mod dimlength) <> 0 then
exit;
SetLength(Result, Length(intarray) div dimlength);
for i := 0 to High(Result) do
SetLength(Result[i], dimlength);
for i := 0 to High(intarray) do
Result[i div dimlength][i mod dimlength] := intarray[i];
end;
begin
writeln(IntArrayTo2D([5,2,7,1],2));
end.
Plugin output is: "[]"
Script output is "[[5, 2], [7, 1]]"
Really have no idea where I'm going wrong.
Here is the code I'm using in the plugin:
library project1;
{$mode objfpc}{$H+}
uses
Classes, sysutils, mufasatypes
{ you can add units after this };
function IntArrayTo2D(intarray: TIntegerArray; dimlength: Integer) : T2DIntegerArray; register;
var
i: Integer;
begin
if (Length(intarray) mod dimlength) <> 0 then
exit;
SetLength(Result, Length(intarray) div dimlength);
for i := 0 to High(Result) do
SetLength(Result[i], dimlength);
for i := 0 to High(intarray) do
Result[i div dimlength][i mod dimlength] := intarray[i];
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 := @IntArrayTo2D;
StrPCopy(ProcDef, 'function IntArrayTo2D(intarray: TIntegerArray; dimlength: Integer) : T2DIntegerArray;');
end;
else
x := -1;
end;
Result := x;
end;
exports GetFunctionCount;
exports GetFunctionInfo;
begin
end.
And using IntArrayTo2D there does NOT work. However, if I then use the same code, but simply have it as a script in Simba, it works perfectly:
program SimbaPluginTest;
//{$LoadLib project1}
function IntArrayTo2D(intarray: TIntegerArray; dimlength: Integer) : T2DIntegerArray;
var
i: Integer;
begin
if (Length(intarray) mod dimlength) <> 0 then
exit;
SetLength(Result, Length(intarray) div dimlength);
for i := 0 to High(Result) do
SetLength(Result[i], dimlength);
for i := 0 to High(intarray) do
Result[i div dimlength][i mod dimlength] := intarray[i];
end;
begin
writeln(IntArrayTo2D([5,2,7,1],2));
end.
Plugin output is: "[]"
Script output is "[[5, 2], [7, 1]]"
Really have no idea where I'm going wrong.