Writing Plugins#
+Simba scripts can be extended with plugins. +Plugins are libraries (dll/so/dylib) which can be written in virtually every low-level language.
+Note
+The cdecl calling convention is used for 32bit, otherwise the default systems calling convention is used.
++
Importing functions#
+To import functions the following methods must be exported to provide information to Simba.
+function GetFunctionInfo(Index: Integer; var Address: Pointer; var Header: PChar): Integer; cdecl;
+function GetFunctionCount: Integer; cdecl;
+
Note
+native;
to the header cause parameters and result passed in the lape wrapper format.The Lape wrapper format is:
+procedure(const Params: PParamArray; const Result: Pointer);
+
+
Importing types#
+To import types the following methods must be exported to provide information to Simba.
+function GetTypeInfo(Index: Integer; var Name: PChar; var Str: PChar): Integer; cdecl;
+function GetTypeCount: Integer; cdecl;
+
Note
+These methods are imported before GetFunctionInfo & GetFunctionCount so these types will be available when adding functions.
++
Importing code#
+Code can be imported in the script with the following methods exported.
+procedure GetCode(var Code: PChar); cdecl;
+function GetCodeLength: Integer; cdecl;
+
+
RegisterSimbaPlugin#
+A plugin can export RegisterSimbaPlugin which provides access to various Simba’s infomation & methods.
+procedure RegisterSimbaPlugin(Infomation: PSimbaInfomation; Methods: PSimbaMethods); cdecl;
+
These pointers are provided to these structures:
+TSimbaInfomation = packed record
+ SimbaVersion: Integer;
+ SimbaMajor: Integer;
+
+ FileName: PChar;
+
+ Compiler: Pointer;
+end;
+
+TSimbaMethods = packed record
+ RunOnMainThread: procedure(Method: TMainThreadMethod; Data: Pointer = nil); cdecl;
+
+ GetMem: function(Size: NativeUInt): Pointer; cdecl;
+ FreeMem: function(P: Pointer): NativeUInt; cdecl;
+ AllocMem: function(Size: NativeUInt): Pointer; cdecl;
+ ReAllocMem: function(var P: Pointer; Size: NativeUInt): Pointer; cdecl;
+ MemSize: function(P: Pointer): NativeUInt; cdecl;
+
+ RaiseException: procedure(Message: PChar); cdecl;
+
+ GetTypeInfo: function(Compiler: Pointer; Typ: PChar): Pointer; cdecl;
+ GetTypeInfoSize: function(TypeInfo: Pointer): NativeInt; cdecl;
+ GetTypeInfoFieldOffset: function(TypeInfo: Pointer; FieldName: PChar): NativeInt; cdecl;
+
+ AllocateArray: function(TypeInfo: Pointer; Len: NativeInt): Pointer; cdecl;
+ AllocateString: function(Data: PChar): Pointer; cdecl;
+ AllocateUnicodeString: function(Data: PUnicodeChar): Pointer; cdecl;
+ AllocateIntegerArray: function(Len: NativeInt): Pointer; cdecl;
+ AllocateStringArray: function(Len: NativeInt): Pointer; cdecl;
+ AllocatePointArray: function(Len: NativeInt): Pointer; cdecl;
+
+ SetArrayLength: procedure(TypeInfo: Pointer; var AVar: Pointer; NewLen: NativeInt); cdecl;
+ GetArrayLength: function(AVar: Pointer): NativeInt; cdecl;
+end;
+
See the Example C++ plugin to see how TypeInfo is used to allocate custom records & arrays.
+