X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;ds=sidebyside;f=Usermode%2Finclude%2Fspiderscript.h;h=e6fdaab2101f1726e4044dd8cda52cfedb35afd0;hb=5e007006d5b007c29268e4c949a8c9d472233257;hp=409cf493ce617af95f0558c5e1fde27b69443776;hpb=3887bf8941fe33071d061961f213a7da360af02a;p=tpg%2Facess2.git diff --git a/Usermode/include/spiderscript.h b/Usermode/include/spiderscript.h index 409cf493..e6fdaab2 100644 --- a/Usermode/include/spiderscript.h +++ b/Usermode/include/spiderscript.h @@ -14,6 +14,7 @@ typedef struct sSpiderScript tSpiderScript; typedef struct sSpiderVariant tSpiderVariant; +typedef struct sSpiderNamespace tSpiderNamespace; typedef struct sSpiderFunction tSpiderFunction; typedef struct sSpiderValue tSpiderValue; typedef struct sSpiderObjectDef tSpiderObjectDef; @@ -26,18 +27,63 @@ typedef struct sSpiderObject tSpiderObject; */ enum eSpiderScript_DataTypes { - SS_DATATYPE_UNDEF, //!< Undefined - SS_DATATYPE_NULL, //!< NULL (Probably will never be used) - SS_DATATYPE_DYNAMIC, //!< Dynamically typed variable (will this be used?) - SS_DATATYPE_OPAQUE, //!< Opaque data type - SS_DATATYPE_OBJECT, //!< Object reference - SS_DATATYPE_ARRAY, //!< Array - SS_DATATYPE_INTEGER, //!< Integer (64-bits) + /** + * \brief Undefined data + * \note Default type of an undefined dynamic variable + */ + SS_DATATYPE_UNDEF, + /** + * \brief Dynamically typed variable + * \note Used to dentote a non-fixed type for function parameters + */ + SS_DATATYPE_DYNAMIC, + /** + * \brief Opaque Data Pointer + * + * Opaque data types are used for resource handles or for system buffers. + */ + SS_DATATYPE_OPAQUE, + /** + * \brief Object reference + * + * A reference to a SpiderScript class instance. Can be accessed + * using the -> operator. + */ + SS_DATATYPE_OBJECT, + /** + * \brief Array data type + */ + SS_DATATYPE_ARRAY, + /** + * \brief Integer datatype + * + * 64-bit integer + */ + SS_DATATYPE_INTEGER, SS_DATATYPE_REAL, //!< Real Number (double) SS_DATATYPE_STRING, //!< String NUM_SS_DATATYPES }; +/** + * \brief Namespace definition + */ +struct sSpiderNamespace +{ + tSpiderNamespace *Next; + + tSpiderNamespace *FirstChild; + + tSpiderFunction *Functions; + + tSpiderObjectDef *Classes; + + int NConstants; //!< Number of constants + tSpiderValue *Constants; //!< Number of constants + + const char Name[]; +}; + /** * \brief Variant of SpiderScript */ @@ -45,12 +91,15 @@ struct sSpiderVariant { const char *Name; // Just for debug - int bDyamicTyped; //!< Use static typing + int bDyamicTyped; //!< Use dynamic typing + int bImplicitCasts; //!< Allow implicit casts (casts to lefthand side) tSpiderFunction *Functions; //!< Functions (Linked List) int NConstants; //!< Number of constants tSpiderValue *Constants; //!< Number of constants + + tSpiderNamespace RootNamespace; }; /** @@ -84,7 +133,6 @@ struct sSpiderValue */ struct { void *Data; //!< Data (can be anywhere) - int Size; //!< Data size (zero means full opaque) void (*Destroy)(void *Data); //!< Called on GC } Opaque; @@ -108,16 +156,16 @@ struct sSpiderObjectDef /** * \brief Object type name */ - const char* const Name; + const char * const Name; /** * \brief Construct an instance of the object * \param NArgs Number of arguments - * \param Args Argument count + * \param Args Argument array * \return Pointer to an object instance (which must be fully valid) * \retval NULL Invalid parameter (usually, actually just a NULL value) * \retval ERRPTR Invalid parameter count */ - tSpiderObject *(*Constructor)(int NArgs, tSpiderValue *Args); + tSpiderObject *(*Constructor)(int NArgs, tSpiderValue **Args); /** * \brief Clean up and destroy the object @@ -127,17 +175,15 @@ struct sSpiderObjectDef */ void (*Destructor)(tSpiderObject *This); + tSpiderFunction *Methods; //!< Method Definitions (linked list) + int NAttributes; //!< Number of attributes //! Attribute definitions struct { const char *Name; //!< Attribute Name int bReadOnly; //!< Allow writes to the attribute? - } *AttributeDefs; - - - int NMethods; //!< Number of methods - tSpiderFunction *Methods; //!< Method Definitions + } AttributeDefs[]; }; /** @@ -146,7 +192,7 @@ struct sSpiderObjectDef struct sSpiderObject { tSpiderObjectDef *Type; //!< Object Type - int NReferences; //!< Number of references + int ReferenceCount; //!< Number of references void *OpaqueData; //!< Pointer to the end of the \a Attributes array tSpiderValue *Attributes[]; //!< Attribute Array }; @@ -190,13 +236,13 @@ struct sSpiderFunction */ extern tSpiderScript *SpiderScript_ParseFile(tSpiderVariant *Variant, const char *Filename); /** - * \brief Execute a method from a script + * \brief Execute a function from a script * \param Script Script to run * \param Function Name of function to run ("" for the 'main') * \return Return value */ -extern tSpiderValue *SpiderScript_ExecuteMethod(tSpiderScript *Script, - const char *Function, +extern tSpiderValue *SpiderScript_ExecuteFunction(tSpiderScript *Script, + tSpiderNamespace *Namespace, const char *Function, int NArguments, tSpiderValue **Arguments ); @@ -206,6 +252,8 @@ extern tSpiderValue *SpiderScript_ExecuteMethod(tSpiderScript *Script, */ extern void SpiderScript_Free(tSpiderScript *Script); +extern tSpiderObject *SpiderScript_AllocateObject(tSpiderObjectDef *Class, int ExtraBytes); + /** * \name tSpiderValue Manipulation functions * \{ @@ -215,6 +263,7 @@ extern tSpiderValue *SpiderScript_CreateReal(double Value); extern tSpiderValue *SpiderScript_CreateString(int Length, const char *Data); extern tSpiderValue *SpiderScript_CastValueTo(int Type, tSpiderValue *Source); extern int SpiderScript_IsValueTrue(tSpiderValue *Value); +extern void SpiderScript_FreeValue(tSpiderValue *Value); extern char *SpiderScript_DumpValue(tSpiderValue *Value); /** * \}