Made by InnerFuse.
TCs2PascalScript = Object/Class
Public properties:
Variables : PVariableManager
read Use to add variables.
Procedures : PProcedureManager
read Use to add external function/procedures.
OnUses : TOnUses Read/Write
Triggered when an Uses Clause is occrd.
ErrorCode : TCs2Error
Read Used to read the error occured.
ErrorPos : LongInt Read Used to read
the error position.
Constructor Create (Id : Pointer);
Create an instance of the script engine, ID is passed to all
events.
Procedure SetText (p : Pchar);
Assign a text to the script engine. Afterwards you should
checkerrorcode.
Procedure RunScript;
Execute the script code , first assign some script with SetText.
Function RunScriptProc (Const Name
: String;Parameters : PVariableManager): PCajVariant;
Run an function inside the script.
Destructor Destroy;
Destroy the scriptengine.
PVariableManager
Type
PVariableManager = Pointer;
Variable manager is used for storing an array of variables. You
can use these functions for accessing it:
Function VM_Create (InheritFrom : PVariableManager) :
PVariableManager;
Create an instance of PVariableManager
Procedure VM_Destroy (p : PVariableManager);
Destroy an instance of PVariableManager
Function VM_Add ( P : PVariableManager; D : PCajVariant;Const Name : String)
: PCajVariant;
Add a PCajVariant to it.
Procedure VM_Delete (p : PVariableManager; Idx : LongInt);
Delete a PCajVariant from it. Also destroy all the Variants.
Function VM_Get (p : PVariableManager; Idx : LongInt) : PCajVariant;
Return a PCajVariant from the variable list.
Procedure VM_SetName (p : PVariableManager; Idx : LongInt;
S: String);
Set the name of an item.
Function VM_Count (p : PVariableManager) : LongInt;
Return the number of variant.
Function VM_Find (p : PVariableManager; Const Name
:String) : LongInt;
Find a variant.
Procedure VM_Clear (p : PVariableManager);
Remove all items from the list.
PProcedureManager
Type PProcedureManager = Pointer.
Procedure manager is used for adding external procedures to the
script.
Function PM_Create : PProcedureManager;
Create an instance of PProcedureManager.
Procedure PM_Destroy (p : PProcedureManager);
Destroy an instance of PProcedureManager.
Procedure PM_Clear (p : PProcedureManager);
Remove all items.
Procedure PM_Add (p : PProcedureManager; Const Spec : String;Addr
: Pointer);
Spec should be the procedure header in this format:
ReturnType+' '+ProcedureName+' '+Parameter1Name+'
'+Parameter1Type+' '+Parameter2Name....
The types are number (see PCajVariant0.
When there is an ! before the parameter name, it is an Var
variant.This can be changed.
Addr should point to an TRegisteredProc.
Procedure PM_Delete (p : PProcedureManager; I : LongInt);
Delete procedure number I.
Function PM_Find (p : PProcedureManager; Const Name : String):
Integer;
Search for procedure.
Function PM_Get (p : PProcedureManager; i : LongInt) :
Pointer;
Return the address of the procedure.
Function PM_GetSpec (p : PProcedureManager; i : LongInt) :
String;
Return the procedure definition of I.
Type TCs2Error = Word;
TCs2Error is used for error handling.
Eror codes:
ENoError - No error has occured
ECanNotReadProperty - Can not read property, not used yet
ECanNotWriteProperty - Can not write property, not used
yet
EUnknownIdentifier - The identifier is unknown
EIdentifierExpected - An identifier is expected
ESemicolonExpected - A semicolon is required
EBeginExpected - Begin is expected
EDuplicateIdentifier - Duplicate identifier
EUnexpectedEndOfFile - Unexpected end of file is occured
EColonExpected - An colon is expected
ESyntaxError - There was an error in the syntax
EStringError - A string error, usually, a string that has
notended before the enter.
EErrorInStatement - Error in the statement
EAssignmentExpected - Assignment is expected
ETypeMismatch - Type is not the same.
EErrorInExpression - Error in the expresssion.
ERoundOpenExpected - A round open is expected
ERoundCloseExpected - A round close is expected
EVariableExpected - A variable is expected
ECommaExpected - A comma is expected
EThenExpected - Then is expected
EPeriodExpected - A period is expected
EParameterError - Parameter error, occurs when calling
RunScriptProc.The ErrorPos gives the parameter number.
EToExpected - To expected
EDoExpected - Do expected
ERangeError - out of range
EOfExpected - Of expected
EndExpxcted - End expected
TOnUses =Function (
Id
: Pointer;
Sender
: PCs2PascalScript;
Name
: String
)
: TCs2Error;
This function is triggered when script is loaded (the name is
:systemand when someone add uses XXX;
Id The id passed to the TCs2PascalScript.Create.
Can be used when using more scripts at once.
Sender The TCs2PascalScript.
Name The name of the uses.
This function should return ENoError.
TRegisteredProc = Function
(
ID
: Pointer;
Const
ProcName : String;
Params
: VariableManager;
res
: PCajVariant
)
: TCS2Error;
This function is triggered when some external function is
called.
Id The id passed to the TCs2PascalScript.Create.
Can be used when using more scripts at once.
ProcName The name of the uses.
Params an array of parameters, use VM_Get to
receive.
Res when your function returns something, put
it in here.
This function should return ENoError.
TCajVariant
CajVariant is used for storing variables.
Type
PCajVariant = ^TCajVariant;
TCajVariant = Packed Record
VType
: Word;
Flags
: Byte; {Readonly(Const) = 1}
Case
Word of
CSV_UByte
: (CV_UByte : Byte);
CSV_SByte
: (CV_SByte : ShortInt);
CSV_Char
: (CV_Char : Char);
CSV_UInt16
: (CV_UInt16 : Word);
CSV_SInt16
: (CV_SInt16 : {$IFDEF DELPHI}SmallInt{$ELSE}
Integer{$ENDIF} );
CSV_UInt32
: (CV_UInt32 : {$IFDEF DELPHI} Cardinal{$ELSE}LongInt{$ENDIF}
);
CSV_SInt32
: (CV_SInt32 : LongInt);
CSV_String
: (CV_Str : String);
CSV_Real
: (CV_Real : Real);
CSV_Single
: (CV_Single : Single);
CSV_Double
: (CV_Double : Double);
CSV_Extended
: (CV_Extended : Extended);
CSV_Comp
: (CV_Comp : Comp);
CSV_Bool
: (CV_Bool : Boolean);
CSV_Var
: (cv_Var : Pointer);
End;
Variable type (TCajVariant.VType):
CSV_None | 0 | No result, used with procedures |
CSV_UByte | 1 | CajScript/Pascal/Delphi: Byte |
CSV_SByte | 2 | CajScript/Pascal/Delphi: ShortInt |
CSV_UInt16 | 3 | CajScript: SmallInt Pascal: Integer Delphi: SmallInt |
CSV_SInt16 | 4 | CajScript/Pascal/Delphi: Word |
CSV_UInt32 | 5 | CajScript/Delphi: Integer/Longint Pascal: Longint |
CSV_SInt32 | 6 | CajScript/Delphi: Cardinal Pascal:Longint |
CSV_Char | 7 | Cajscript/Pascal/Delphi: Char |
CSV_String | 8 | CajScript/Pascal/Delphi: String |
CSV_Real | 9 | CajScript/Pascal/Delphi: Real |
CSV_Single: | 10 | CajScript/Pascal/Delphi: Single |
CSV_Double | 11 | CajScript/Pascal/Delphi: Double |
CSV_Extended | 12 | CajScript/Pascal/Delphi: Extended |
CSV_Comp | 13 | CajScript/Pascal/Delphi: Comp |
CSV_Bool | 14 | CajScript/Pascal/Delphi: Boolean |
CSV_Var | 15 | Variable, CV_Var points to an other TCajVariant. Use GetVarLink to resolve links. |