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;
16 typedef struct sSpiderVariant tSpiderVariant;
17 typedef struct sSpiderFunction tSpiderFunction;
18 typedef struct sSpiderValue tSpiderValue;
19 typedef struct sSpiderObjectDef tSpiderObjectDef;
20 typedef struct sSpiderObject tSpiderObject;
24 * \brief SpiderScript Variable Datatypes
25 * \todo Expand the descriptions
27 enum eSpiderScript_DataTypes
29 SS_DATATYPE_UNDEF, //!< Undefined
30 SS_DATATYPE_NULL, //!< NULL (Probably will never be used)
31 SS_DATATYPE_DYNAMIC, //!< Dynamically typed variable (will this be used?)
32 SS_DATATYPE_OPAQUE, //!< Opaque data type
33 SS_DATATYPE_OBJECT, //!< Object reference
34 SS_DATATYPE_ARRAY, //!< Array
35 SS_DATATYPE_INTEGER, //!< Integer (64-bits)
36 SS_DATATYPE_REAL, //!< Real Number (double)
37 SS_DATATYPE_STRING, //!< String
42 * \brief Variant of SpiderScript
46 const char *Name; // Just for debug
48 int bDyamicTyped; //!< Use static typing
50 tSpiderFunction *Functions; //!< Functions (Linked List)
52 int NConstants; //!< Number of constants
53 tSpiderValue *Constants; //!< Number of constants
57 * \brief SpiderScript data object
61 enum eSpiderScript_DataTypes Type; //!< Variable type
62 int ReferenceCount; //!< Reference count
65 uint64_t Integer; //!< Integer data
66 double Real; //!< Real Number data
71 int Length; //!< Length
72 char Data[]; //!< Actual string (\a Length bytes)
75 * \brief Variable data
78 int Length; //!< Length of the array
79 tSpiderValue *Items[]; //!< Array elements (\a Length long)
86 void *Data; //!< Data (can be anywhere)
87 void (*Destroy)(void *Data); //!< Called on GC
91 * \brief Object Instance
93 tSpiderObject *Object;
98 * \brief Object Definition
100 * Internal representation of an arbitary object.
102 struct sSpiderObjectDef
106 struct sSpiderObjectDef *Next; //!< Internal linked list
108 * \brief Object type name
110 const char* const Name;
112 * \brief Construct an instance of the object
113 * \param NArgs Number of arguments
114 * \param Args Argument count
115 * \return Pointer to an object instance (which must be fully valid)
116 * \retval NULL Invalid parameter (usually, actually just a NULL value)
117 * \retval ERRPTR Invalid parameter count
119 tSpiderObject *(*Constructor)(int NArgs, tSpiderValue *Args);
122 * \brief Clean up and destroy the object
123 * \param This Object instace
124 * \note The object pointer (\a This) should be invalidated and freed
127 void (*Destructor)(tSpiderObject *This);
129 int NAttributes; //!< Number of attributes
131 //! Attribute definitions
133 const char *Name; //!< Attribute Name
134 int bReadOnly; //!< Allow writes to the attribute?
138 int NMethods; //!< Number of methods
139 tSpiderFunction *Methods; //!< Method Definitions
143 * \brief Object Instance
147 tSpiderObjectDef *Type; //!< Object Type
148 int NReferences; //!< Number of references
149 void *OpaqueData; //!< Pointer to the end of the \a Attributes array
150 tSpiderValue *Attributes[]; //!< Attribute Array
154 * \brief Represents a function avaliable to a script
156 struct sSpiderFunction
159 * \brief Next function in list
161 struct sSpiderFunction *Next;
164 * \brief Function name
168 * \brief Function handler
170 tSpiderValue *(*Handler)(tSpiderScript *Script, int nParams, tSpiderValue **Parameters);
172 * \brief Argument types
174 * Zero or -1 terminated array of \a eSpiderScript_DataTypes.
175 * If the final entry is zero, the function has a fixed number of
176 * parameters, if the final entry is -1, the function has a variable
177 * number of arguments.
179 int ArgTypes[]; // Zero (or -1) terminated array of parameter types
185 * \brief Parse a file into a script
186 * \param Variant Variant structure
187 * \param Filename File to parse
188 * \return Script suitable for execution
190 extern tSpiderScript *SpiderScript_ParseFile(tSpiderVariant *Variant, const char *Filename);
192 * \brief Execute a method from a script
193 * \param Script Script to run
194 * \param Function Name of function to run ("" for the 'main')
195 * \return Return value
197 extern tSpiderValue *SpiderScript_ExecuteMethod(tSpiderScript *Script,
198 const char *Function,
199 int NArguments, tSpiderValue **Arguments
203 * \brief Free a script
204 * \param Script Script structure to free
206 extern void SpiderScript_Free(tSpiderScript *Script);
209 * \name tSpiderValue Manipulation functions
212 extern tSpiderValue *SpiderScript_CreateInteger(uint64_t Value);
213 extern tSpiderValue *SpiderScript_CreateReal(double Value);
214 extern tSpiderValue *SpiderScript_CreateString(int Length, const char *Data);
215 extern tSpiderValue *SpiderScript_CastValueTo(int Type, tSpiderValue *Source);
216 extern int SpiderScript_IsValueTrue(tSpiderValue *Value);
217 extern char *SpiderScript_DumpValue(tSpiderValue *Value);