Memory macros
Macros listed below allow to allocate managed memory from C++ application side. This
is the same what new operator does in SC scripts (though on the host side it is only
allowed to use default constructors).
-
SC_UPCAST_PTR(BASE_TYPE, DERIVED_TYPE, NS) - Safely casts managed pointer (BASE_TYPE) to derived type (DERIVED_TYPE), NS - namespace used to seach types
-
SC_ALLOC(PTR_TYPE, ELEM_NUM, NS) - Allocates ELEM_NUM array of type PTR_TYPE, NS - namespace used to seach types
-
SC_ALLOC_DERIVED(PTR_TYPE, ALLOC_TYPE, ELEM_NUM, NS) - Allocates ELEM_NUM array of class ALLOC_TYPE that is derived from PTR_TYPE, NS - namespace used to seach types
Example
TSCPtr<TSCPtr<Soldier> > s1 = SC_ALLOC(TSCPtr<Soldier>, 4, NULL); //array of 4 Soldier managed pointers
TSCPtr<Soldier> s2 = SC_ALLOC(Soldier, 1, NULL); //one Soldier object
TSCPtr<Soldier> s3 = SC_ALLOC_DERIVED(Soldier, Marine, 1, NULL); //derived Marine class
Namespace
Used to define data in namespaces.
-
SC_BASE_CLASS(NS, CL) - register a base class CL in namespace NS
-
SC_DERIVED_CLASS(NS, CL, BASE) - register a derived class CL in namespace NS, BASE base class
-
SC_BASE_ABSTRACT_CLASS(NS, CL) - register a base abstract class CL in namespace NS
-
SC_DERIVED_ABSTRACT_CLASS(NS, CL, BASE) - register a derived abstract class CL in namespace NS, BASE base class
-
SC_SIMPLE_TYPE(NS, TYPE) - registers a simple type in namespace NS
-
SC_NAMESPACE(NS, NAME) - registers a namespace in namespace NS
-
SC_FUNC_PTR_TYPE(NS, RET, PROC, ARGS) - registers a function pointer type in namespace NS, RET - returs statement, PROC - name, ARGS- arguments (all are a function declaration split to 3 parts)
-
SC_VARIABLE(NS, TYPE, VAR) - registers a variable VAR of TYPE type
-
SC_FUNCTION(NS, RET, PROC, ARGS) - registers a stdcall function, RET - return statement, PROC - name, ARGS - arguments, all connected create the declaration of the function
Example
typedef void (SCSTDCALL* TFuncVoidInt)(Int x);
...
ISCType *tTFuncVoidInt = SC_FUNC_PTR_TYPE(ns, void, TFuncVoidInt, (Int x));
if(!tTFuncVoidInt)
return 0;
...
Int *extIntPtr = NULL;
ISCSymbol *vExtIntPtr = SC_VARIABLE(ns, Int*, extIntPtr);
Class
Used to define data in classes.
-
SC_ATTRIBUTE(SCPARTYPE, CLASS, TYPE, VAR) - Registers an attribute, SCPARTYPE class (ISCType) returned by SC_*_CLASS macros, CLASS c++ class, TYPE - type of the variable, VAR variable
-
SC_STATIC_ATTRIBUTE(SCPARTYPE, CLASS, TYPE, VAR) - Registers an static attribute , SCPARTYPE class (ISCType) returned by SC_*_CLASS macros, CLASS c++ class, TYPE - type of the variable, VAR variable
-
SC_METHOD(SCPARTYPE, CLASS, RET, PROC, ARGS) - Registers a method, SCPARTYPE class (ISCType) returned by SC_*_CLASS macros, CLASS c++ class, RET, PROC, ARGS - return value ,name, and function aguments split to 3 parts
-
SC_STATIC_METHOD(SCPARTYPE, CLASS, RET, PROC, ARGS) - Registers a static method, SCPARTYPE class (ISCType) returned by SC_*_CLASS macros, CLASS c++ class, RET, PROC, ARGS - return value ,name, and function aguments split to 3 parts
-
SC_CONSTRUCTOR(SCPARTYPE, CLASS, PROC, ARGS) - Registers a constructor with argumets, SCPARTYPE class (ISCType) returned by SC_*_CLASS macros, CLASS c++ class, PROC, ARGS - name, and function aguments split to 2 parts
-
SC_CONSTRUCTOR_BODY(TYPE, OBJECT, ARGS) - Put into initalization function that is registered with SC_CONSTRUCTOR, TYPE - C++ class, OBJECT - object reference, ARGS - arguments , only names (like call)
Example
//That is a parametrized constructor and
//such a form should always be used.
Soldier& SCSTDCALL InitSoldier(Soldier &s, Int h)
{
SC_CONSTRUCTOR_BODY(Soldier, s, (h));
}
...
ISCType *tSoldier = SC_BASE_CLASS(ns, Soldier);
if(!SC_ATTRIBUTE(tSoldier, Soldier, Int, health) ||
!SC_ATTRIBUTE(tSoldier, Soldier, TSCPtr<Soldier>, leader) ||
!SC_CONSTRUCTOR(tSoldier, Soldier, InitSoldier, (Soldier *s, Int h)) ||
!SC_METHOD(tSoldier, Soldier, void, Hit, (Int damage)) ||
!SC_METHOD(tSoldier, Soldier, void, Show, () const) )
return -1;
...
Getting data from scripts
Allow to obtain some data from scripts.
-
SC_GET_FUNC_PTR(SCRIPT, DEST_FUNC_TYPEDEF, NAME) - returns an SC function pointer to the function defined in the script, SCRIPT - the script to search, DEST_FUNC_TYPEDEF - typedef of function pointer, NAME - name of the function
Example. It is assumed that TestFuncDoubleConstVec3Ref function exists in vmScript.
typedef Double (SCSTDCALL *TFuncDoubleConstVec3Ref)(const Vec3& a);
...
TSCFuncPtr<TFuncDoubleConstVec3Ref> fptr1;
fptr1 = SC_GET_FUNC_PTR(vmScript,TFuncDoubleConstVec3Ref, "TestFuncDoubleConstVec3Ref");
...
Script user variables
Allow to register some variable directly in the main block of the script, passed
while script creation.
-
SC_USER_VAR_INFO(TYPE, VAR) - creates an information structure about the variable, TYPE - C++ type of the variable, VAR - variable
-
SC_USER_VAR_INFO_N(TYPE, VAR, NAME) - creates an information structure about the variable, TYPE - C++ type of the variable, VAR - variable, NAME - name of the variable visible in the script
-
SC_USER_VAR_INFO_PTR_N(TYPE, VAR, NAME) - creates an information structure about the variable ,the variable is given as a pointer, TYPE - C++ type of the variable, VAR - variable, NAME - name of the variable visible in the script
Example
Int userIntVar = 1;
Character selfChar;
ISCUserVarInfo userVarInfo[] = {
SC_USER_VAR_INFO(Int, userIntVar),
SC_USER_VAR_INFO_PTR_N(Character, &selfChar, "self")
};
Special function
Allow to register special functions for types. Note that for classes assignment of non constant object is defined.
If special function already exists ,error is reported and NULL returned.
-
SC_ADD(SCTYPE, CPPTYPE, A, B) - addition , SCTYPE - registered SC type, CPPTYPE - c++ type, A left argument, B right argument
-
SC_SUB(SCTYPE, CPPTYPE, A, B) - subtraction , SCTYPE - registered SC type, CPPTYPE - c++ type, A left argument, B right argument
-
SC_MUL(SCTYPE, CPPTYPE, A, B) - multiplication , SCTYPE - registered SC type, CPPTYPE - c++ type, A left argument, B right argument
-
SC_DIV(SCTYPE, CPPTYPE, A, B) - division , SCTYPE - registered SC type, CPPTYPE - c++ type, A left argument, B right argument
-
SC_MOD(SCTYPE, CPPTYPE, A, B) - modulo , SCTYPE - registered SC type, CPPTYPE - c++ type, A left argument, B right argument
-
SC_MINUS(SCTYPE, CPPTYPE, A, B) - neegative number, SCTYPE - registered SC type, CPPTYPE - c++ type, A argument
-
SC_BIT_AND(SCTYPE, CPPTYPE, A, B) - bitwise and , SCTYPE - registered SC type, CPPTYPE - c++ type, A left argument, B right argument
-
SC_BIT_OR(SCTYPE, CPPTYPE, A, B) - bitwise or , SCTYPE - registered SC type, CPPTYPE - c++ type, A left argument, B right argument
-
SC_BIT_XOR(SCTYPE, CPPTYPE, A, B) - bitwise xor , SCTYPE - registered SC type, CPPTYPE - c++ type, A left argument, B right argument
-
SC_BIT_NEG(SCTYPE, CPPTYPE, A, B) - bitwise negation , SCTYPE - registered SC type, CPPTYPE - c++ type, A left argument, B right argument
-
SC_LSHIFT(SCTYPE, CPPTYPE, A, B) - bitwise left shift , SCTYPE - registered SC type, CPPTYPE - c++ type, A argument
-
SC_RSHIFT(SCTYPE, CPPTYPE, A, B) - bitwise right shift , SCTYPE - registered SC type, CPPTYPE - c++ type, A left argument, B right argument
-
SC_LOG_AND(SCTYPE, CPPTYPE, A, B) - logical and , SCTYPE - registered SC type, CPPTYPE - c++ type, A left argument, B right argument
-
SC_LOG_OR(SCTYPE, CPPTYPE, A, B) - logical or , SCTYPE - registered SC type, CPPTYPE - c++ type, A left argument, B right argument
-
SC_LOG_NOT(SCTYPE, CPPTYPE, A) - logical not , SCTYPE - registered SC type, CPPTYPE - c++ type, A argument
-
SC_INC_PREF(SCTYPE, CPPTYPE) - prefix increment , SCTYPE - registered SC type, CPPTYPE - c++ type
-
SC_DEC_PREF(SCTYPE, CPPTYPE) - prefix decrement , SCTYPE - registered SC type, CPPTYPE - c++ type
-
SC_INC_POST(SCTYPE, CPPTYPE) - postfix increment , SCTYPE - registered SC type, CPPTYPE - c++ type
-
SC_DEC_POST(SCTYPE, CPPTYPE) - postfix decrement , SCTYPE - registered SC type, CPPTYPE - c++ type
-
SC_ASSIGN(SCTYPE, CPPCLASS, A) - assignment , SCTYPE - registered SC type, CPPTYPE - c++ type, A argument
-
SC_CMP(SCTYPE, CPPCLASS, A) - comparison function, the type must thave defined ==,!=,<,>,<=,>=, SCTYPE - registered SC type, CPPTYPE - c++ type, A argument
-
SC_CONV(SCTYPE, CPPCLASS, A) - cast function, SCTYPE - registered SC type, CPPCLASS - c++ class, A the type that cast to
Example.
ISCType *tVec3 = SC_BASE_CLASS(ns, Vec3);
if(!SC_ADD(tVec3, Vec3, const Vec3, const Vec3) ||
!SC_SUB(tVec3, Vec3, const Vec3, const Vec3) ||
!SC_MUL(tVec3, Vec3, const Vec3, const Vec3) ||
!SC_DIV(tVec3, Vec3, const Vec3, const Vec3))
return -1;