4 #ifndef _SPIDERSCRIPT_H_
5 #define _SPIDERSCRIPT_H_
9 #define ERRPTR ((void*)((intptr_t)0-1))
12 * \brief Opaque script handle
14 typedef struct sSpiderScript tSpiderScript;
19 typedef struct sSpiderVariant tSpiderVariant;
20 typedef struct sSpiderFunction tSpiderFunction;
21 typedef struct sSpiderValue tSpiderValue;
22 typedef struct sSpiderObjectDef tSpiderObjectDef;
23 typedef struct sSpiderObject tSpiderObject;
27 * \brief SpiderScript Variable Datatypes
29 enum eSpiderScript_DataTypes
31 SS_DATATYPE_UNDEF, //!< Undefined
32 SS_DATATYPE_NULL, //!< NULL (Probably will never be used)
33 SS_DATATYPE_DYNAMIC, //!< Dynamically typed variable (will this be used?)
34 SS_DATATYPE_OBJECT, //!< Opaque object reference
35 SS_DATATYPE_ARRAY, //!< Array
36 SS_DATATYPE_INTEGER, //!< Integer (64-bits)
37 SS_DATATYPE_REAL, //!< Real Number (double)
38 SS_DATATYPE_STRING, //!< String
43 * \brief Variant of SpiderScript
47 const char *Name; // Just for debug
51 int NFunctions; //!< Number of functions
52 tSpiderFunction *Functions; //!< Functions
54 int NConstants; //!< Number of constants
55 tSpiderValue *Constants; //!< Number of constants
59 * \brief SpiderScript data object
63 int Type; //!< Variable type
64 int ReferenceCount; //!< Reference count
67 uint64_t Integer; //!< Integer data
68 double Real; //!< Real Number data
73 int Length; //!< Length
74 char Data[]; //!< Actual string (\a Length bytes)
77 * \brief Variable data
80 int Length; //!< Length of the array
81 tSpiderValue *Items[]; //!< Array elements (\a Length long)
84 tSpiderObject *Object;
89 * \brief Object Definition
91 * Internal representation of an arbitary object.
93 struct sSpiderObjectDef
96 * \brief Construct an instance of the object
97 * \param NArgs Number of arguments
98 * \param Args Argument count
99 * \return Pointer to an object instance (which must be fully valid)
100 * \retval NULL Invalid parameter (usually, actually just a NULL value)
101 * \retval ERRPTR Invalid parameter count
103 tSpiderObject *(*Constructor)(int NArgs, tSpiderValue *Args);
106 * \brief Clean up and destroy the object
107 * \param This Object instace
108 * \note The object pointer (\a This) should be invalidated and freed
111 void (*Destructor)(tSpiderObject *This);
113 int NAttributes; //!< Number of attributes
115 //! Attribute definitions
117 const char *Name; //!< Attribute Name
118 int bReadOnly; //!< Allow writes to the attribute?
122 int NMethods; //!< Number of methods
123 tSpiderFunction *Methods; //!< Method Definitions
127 * \brief Object Instance
131 tSpiderObjectDef *Type; //!< Object Type
132 int NReferences; //!< Number of references
133 void *OpaqueData; //!< Pointer to the end of the \a Attributes array
134 tSpiderValue *Attributes[]; //!< Attribute Array
138 * \brief Represents a function avaliable to a script
140 struct sSpiderFunction
143 * \brief Function name
147 * \brief Function handler
149 tSpiderValue *(*Handler)(tSpiderScript *Script, int nParams, tSpiderValue **Parameters);
151 * \brief Argument types
153 * Zero or -1 terminated array of \a eSpiderScript_DataTypes.
154 * If the final entry is zero, the function has a fixed number of
155 * parameters, if the final entry is -1, the function has a variable
156 * number of arguments.
158 int *ArgTypes; // Zero (or -1) terminated array of parameter types
164 * \brief Parse a file into a script
165 * \param Variant Variant structure
166 * \param Filename File to parse
167 * \return Script suitable for execution
169 extern tSpiderScript *SpiderScript_ParseFile(tSpiderVariant *Variant, const char *Filename);
171 * \brief Execute a method from a script
172 * \param Script Script to run
173 * \param Function Name of function to run ("" for the 'main')
174 * \return Return value
176 extern tSpiderValue *SpiderScript_ExecuteMethod(tSpiderScript *Script,
177 const char *Function,
178 int NArguments, tSpiderValue **Arguments
182 * \brief Free a script
184 extern void SpiderScript_Free(tSpiderScript *Script);