1
0
mirror of https://github.com/moparisthebest/Simba synced 2024-11-11 11:55:02 -05:00
Simba/Projects/MMLLib/libmml.lpr

189 lines
3.4 KiB
ObjectPascal
Raw Normal View History

library libmml;
{$mode objfpc}{$H+}
uses
2010-03-26 10:20:50 -04:00
cmem,Classes,interfaces,graphics,client,sysutils,MufasaTypes,dtmutil;
{$R *.res}
2010-03-26 07:22:08 -04:00
type
PTPoint = ^TPoint;
2010-03-26 10:20:50 -04:00
PPDTM = ^PDTM;
2010-03-26 07:22:08 -04:00
2010-03-30 18:24:16 -04:00
Const
RESULT_OK = 0;
RESULT_ERROR = 1;
var
C: TClient;
2010-03-30 18:24:16 -04:00
gr: Pointer;
last_error: PChar;
function init: integer; cdecl;
begin
2010-03-30 18:24:16 -04:00
C:=TClient.Create('');
result:=0;
end;
2010-03-30 18:24:16 -04:00
function test: pchar; cdecl;
begin
2010-03-30 18:24:16 -04:00
result := PChar('hello world');
raise exception.Create('wat');
end;
2010-03-30 18:24:16 -04:00
{ Mouse }
function getmousepos(var t: tpoint): integer; cdecl;
begin
2010-03-30 18:24:16 -04:00
try
C.IOManager.GetMousePos(t.x,t.y);
result := RESULT_OK;
except on e : Exception do
begin
result := RESULT_ERROR;
last_error := PChar(e.Message);
end;
end;
end;
2010-03-30 18:24:16 -04:00
{function ConvIntClickType(Int : Integer) : TClickType;inline;
begin;
case int of
ps_mouse_right : result := mouse_Right;
ps_mouse_left : result := mouse_left;
ps_mouse_middle: result := mouse_middle;
else
raise exception.CreateFMT('Unknown Clicktype (%d) passed.',[int]);
end;
end; }
2010-03-27 07:44:19 -04:00
function returnpoints: PTPoint; cdecl;
2010-03-26 07:22:08 -04:00
begin
result := AllocMem(sizeof(TPoint) * 2);
result[0].x := 5;
result[0].y := 10;
result[1].x := 20;
result[1].y := 30;
end;
2010-03-27 07:44:19 -04:00
function printpoints(b: PTPoint; len: integer): boolean; cdecl;
2010-03-26 07:22:08 -04:00
var i:integer;
begin
for i := 0 to len - 1 do
writeln('X, Y: (' + inttostr(b[i].x) + ', ' + inttostr(b[i].y) + ')');
end;
2010-03-27 07:44:19 -04:00
procedure hoi(var i: integer); cdecl;
2010-03-26 07:22:08 -04:00
begin
i := i + 1;
end;
2010-03-27 07:44:19 -04:00
function givedtm:PPDTM; cdecl;
2010-03-26 10:20:50 -04:00
var
dtm: PPDTM;
begin
2010-03-30 18:24:16 -04:00
writeln('Size: ' + inttostr(sizeof(pdtm)));
writeln('Size: ' + inttostr(sizeof(ptruint)));
2010-03-26 10:20:50 -04:00
dtm := AllocMem(sizeof(pdtm));
initdtm(dtm^,2);
result:=dtm;
dtm^.n := PChar('wat');
end;
2010-03-30 18:24:16 -04:00
function givedtm2:PDTM; cdecl;
var
dtm: pdtm;
begin
initdtm(dtm,2);
result:=dtm;
//result.n := PChar('wat');
//writeln('woohoo');
end;
function returnarray: tpointarray; cdecl;
var
i:integer;
begin
setlength(result,5);
for i := 0 to high(result) do
result[i] := Point(i * 50, i + 50);
writeln('res: ' + IntToStr(PtrUInt(result)));
gr := @result[0];
end;
procedure printarray2(var arr: TPointArray); cdecl;
var i:integer;
begin
for i := 0 to high(arr) do
writeln(inttostr(arr[i].x) + ',' + inttostr(arr[i].y));
setlength(arr,0);
writeln('GR: ' + inttostr(tpoint(tpointarray(gr)[0]).y));
end;
procedure printarray(arr: PTPoint); cdecl;
var
i:integer;
arr2: TPointArray;
begin
writeln('arr: ' + IntToStr(PtrUInt(@arr[0])));
setlength(arr2,0);
arr2 := @arr[0];
writeln('arr2: ' + IntToStr(PtrUInt(@arr2[0])));
{ for i := 0 to 4 do
writeln(inttostr(arr[i].x) + ',' + inttostr(arr[i].y));
writeln(length(arr2));
for i := 0 to high(arr2) do
writeln(inttostr(arr2[i].x) + ',' + inttostr(arr2[i].y)); }
printarray2(arr2);
writeln(inttostr(length(arr2)));
writeln(inttostr(arr[0].x) + ',' + inttostr(arr[0].y));
end;
procedure fpc_freemem_(p:pointer); cdecl;
begin
writeln('free: ' + inttostr(qword(p)));
freemem(pointer(ptruint(p)));
end;
function fpc_allocmem_(size: ptruint): pointer; cdecl;
begin
result:=AllocMem(size);
writeln('alloc: ' + inttostr(qword(result)));
end;
function fpc_reallocmem_(size: ptruint; ptr: pointer): pointer;
begin
result:=ReAllocMem(ptr, size);
end;
exports
test,
init,
2010-03-26 07:22:08 -04:00
getmousepos,
returnpoints,
printpoints,
2010-03-26 10:20:50 -04:00
hoi,
2010-03-30 18:24:16 -04:00
givedtm,
givedtm2,
returnarray,
printarray,
fpc_freemem_,
fpc_allocmem_,
fpc_reallocmem_;
begin
end.