12#define WG_DEFAULT_ARG(arg) = arg
15#define WG_DEFAULT_ARG(arg)
18#if defined(_WIN32) && defined(_WINDLL)
19#define WG_DLL_EXPORT __declspec(dllexport)
1616#undef WG_DEFAULT_ARG
The configuration used to initialise an interpreter.
Definition: wings.h:137
int maxRecursion
The maximum recursion depth allowed before a RecursionError will be raised.
Definition: wings.h:161
void * printUserdata
The userdata passed to the print callback.
Definition: wings.h:183
float gcRunFactor
The 'aggressiveness' of the garbage collector. Higher means less aggressive.
Definition: wings.h:170
int maxAlloc
The maximum number of objects allowed to be allocated at a time before a MemoryError will be raised.
Definition: wings.h:155
const char *const * argv
The commandline arguments passed to the interpreter. If argc is 0, then this can be NULL.
Definition: wings.h:195
int argc
The length of the argv array. If argc is 0, then a length 1 array with an empty string is implied.
Definition: wings.h:202
Wg_PrintFunction print
The callback to be invoked when print is called in the interpreter. If this is NULL,...
Definition: wings.h:179
const char * importPath
The path to search in when importing file modules. The terminating directory separator is optional.
Definition: wings.h:190
bool enableOSAccess
Enables the os module and the global 'open' function.
Definition: wings.h:148
Wg_Obj * Wg_SetIndex(Wg_Obj *obj, Wg_Obj *index, Wg_Obj *value)
Set an index of an object.
void Wg_RaiseArgumentTypeError(Wg_Context *context, int index, const char *expected)
Raise a TypeError with a formatted message.
void Wg_SetGlobal(Wg_Context *context, const char *name, Wg_Obj *value)
Set a global variable in the current module namespace.
void Wg_RegisterFinalizer(Wg_Obj *obj, Wg_Finalizer finalizer, void *userdata)
Register a finalizer to run when an object is garbage collected.
Wg_Obj * Wg_CallMethod(Wg_Obj *obj, const char *method, Wg_Obj **argv, int argc, Wg_Obj *kwargs)
Call a method on a object.
bool Wg_Unpack(Wg_Obj *obj, int count, Wg_Obj **values)
Helper function to unpack an iterable object into an array of objects.
void(* Wg_PrintFunction)(const char *message, int len, void *userdata)
The signature of the print function used by the interpreter for printing.
Definition: wings.h:96
bool Wg_IsFunction(const Wg_Obj *obj)
Check if an object is a function.
bool Wg_IsClass(const Wg_Obj *obj)
Check if an object is a class.
bool Wg_IsBool(const Wg_Obj *obj)
Check if an object is a boolean.
bool Wg_IsNone(const Wg_Obj *obj)
Check if an object is None.
Wg_Obj * Wg_BindMethod(Wg_Obj *klass, const char *name, Wg_Function fptr, void *userdata)
Instantiate a function object and bind it to a class.
Wg_Obj * Wg_NewBool(Wg_Context *context, bool value)
Instantiate a boolean object.
bool Wg_IsList(const Wg_Obj *obj)
Check if an object is a list.
void Wg_SetUserdata(Wg_Obj *obj, void *userdata)
Set the userdata for an object.
void Wg_RaiseArgumentCountError(Wg_Context *context, int given, int expected)
Raise a TypeError with a formatted message.
struct Wg_Context Wg_Context
An opaque type representing the state of an interpreter.
Definition: wings.h:29
Wg_Obj * Wg_IsInstance(const Wg_Obj *instance, Wg_Obj *const *types, int typesLen)
Check if an object's class derives from any of the specified classes.
void * Wg_GetFunctionUserdata(Wg_Context *context)
Get the userdata associated with the current function.
void Wg_DestroyContext(Wg_Context *context)
Free a context created with Wg_CreateContext().
bool Wg_Iterate(Wg_Obj *obj, void *userdata, Wg_IterationCallback callback)
Iterate over an iterable object.
void Wg_RaiseExceptionClass(Wg_Obj *klass, const char *message)
Create and raise an exception using a class object.
void Wg_DecRef(Wg_Obj *obj)
Decrement the reference count of an object. A positive reference count prevents the object from being...
Wg_Obj * Wg_NewFunction(Wg_Context *context, Wg_Function fptr, void *userdata, const char *prettyName)
Instantiate a function object.
Wg_float Wg_GetFloat(const Wg_Obj *obj)
Get the float value from an integer or float object.
bool Wg_ParseKwargs(Wg_Obj *dict, const char *const *keys, int keysLen, Wg_Obj **values)
Get the values from a kwargs parameter.
Wg_Exc
The type exception to be raised by Wg_RaiseException.
Definition: wings.h:445
@ WG_EXC_KEYERROR
KeyError.
Definition: wings.h:493
@ WG_EXC_EXCEPTION
Exception.
Definition: wings.h:457
@ WG_EXC_ISADIRECTORYERROR
IsADirectoryError.
Definition: wings.h:509
@ WG_EXC_INDEXERROR
IndexError.
Definition: wings.h:489
@ WG_EXC_SYSTEMEXIT
SystemExit.
Definition: wings.h:453
@ WG_EXC_ATTRIBUTEERROR
AttributeError.
Definition: wings.h:477
@ WG_EXC_STOPITERATION
StopIteration.
Definition: wings.h:461
@ WG_EXC_OVERFLOWERROR
OverflowError.
Definition: wings.h:469
@ WG_EXC_RUNTIMEERROR
RuntimeError.
Definition: wings.h:513
@ WG_EXC_IMPORTERROR
ImportError.
Definition: wings.h:481
@ WG_EXC_RECURSIONERROR
RecursionError.
Definition: wings.h:521
@ WG_EXC_SYNTAXERROR
SyntaxError.
Definition: wings.h:525
@ WG_EXC_NOTIMPLEMENTEDERROR
NotImplementedError.
Definition: wings.h:517
@ WG_EXC_NAMEERROR
NameError.
Definition: wings.h:501
@ WG_EXC_LOOKUPERROR
LookupError.
Definition: wings.h:485
@ WG_EXC_BASEEXCEPTION
BaseException.
Definition: wings.h:449
@ WG_EXC_ARITHMETICERROR
ArithmeticError.
Definition: wings.h:465
@ WG_EXC_ZERODIVISIONERROR
ZeroDivisionError.
Definition: wings.h:473
@ WG_EXC_OSERROR
OSError.
Definition: wings.h:505
@ WG_EXC_MEMORYERROR
MemoryError.
Definition: wings.h:497
@ WG_EXC_TYPEERROR
TypeError.
Definition: wings.h:529
@ WG_EXC_VALUEERROR
ValueError.
Definition: wings.h:533
Wg_Obj * Wg_BinaryOp(Wg_BinOp op, Wg_Obj *lhs, Wg_Obj *rhs)
Perform a binary operation.
bool Wg_GetBool(const Wg_Obj *obj)
Get the value from a boolean object.
Wg_Obj * Wg_NewSet(Wg_Context *context, Wg_Obj **argv, int argc)
Instantiate a set object.
bool Wg_HasAttribute(Wg_Obj *obj, const char *attribute)
Check if an object has an attribute.
bool Wg_ImportAllFromModule(Wg_Context *context, const char *module)
Import all names from a module.
Wg_Obj * Wg_GetAttributeNoExcept(Wg_Obj *obj, const char *attribute)
Get an attribute of an object. Unlike, Wg_GetAttribute(), this function does not raise exceptions.
void Wg_SetAttribute(Wg_Obj *obj, const char *attribute, Wg_Obj *value)
Set an attribute of an object.
Wg_Obj * Wg_GetAttribute(Wg_Obj *obj, const char *attribute)
Get an attribute of an object. If the attribute does not exist, an AttributeError is raised....
void Wg_RaiseNameError(Wg_Context *context, const char *name)
Raise a NameError with a formatted message.
Wg_Obj * Wg_NewString(Wg_Context *context, const char *value)
Instantiate a string object.
bool Wg_IsInt(const Wg_Obj *obj)
Check if an object is an integer.
bool Wg_IsSet(const Wg_Obj *obj)
Check if an object is a set.
bool Wg_Execute(Wg_Context *context, const char *script, const char *prettyName)
Execute a script.
Wg_Obj * Wg_NewTuple(Wg_Context *context, Wg_Obj **argv, int argc)
Instantiate a tuple object.
bool Wg_IsIntOrFloat(const Wg_Obj *obj)
Check if an object is a float.
Wg_Obj * Wg_NewFloat(Wg_Context *context, Wg_float value)
Instantiate a float object.
Wg_Obj * Wg_GetAttributeFromBase(Wg_Obj *obj, const char *attribute, Wg_Obj *baseClass)
Get an attribute of an object, skipping attributes that belong to the most derived layer.
uint64_t Wg_uint
The unsigned version of Wg_int.
Definition: wings.h:48
const char * Wg_GetErrorMessage(Wg_Context *context)
Get the current exception message.
void Wg_RaiseException(Wg_Context *context, Wg_Exc type, const char *message)
Create and raise an exception.
bool(* Wg_ModuleLoader)(Wg_Context *context)
The signature of a module loader.
Definition: wings.h:128
Wg_Obj * Wg_NewDictionary(Wg_Context *context, Wg_Obj **keys, Wg_Obj **values, int len)
Instantiate a dictionary object.
bool Wg_IsTuple(const Wg_Obj *obj)
Check if an object is a tuple.
bool Wg_IsString(const Wg_Obj *obj)
Check if an object is a string.
void Wg_DefaultConfig(Wg_Config *config)
Get the default configuration.
Wg_Obj * Wg_Compile(Wg_Context *context, const char *script, const char *prettyName)
Compile a script into a function object.
void(* Wg_ErrorCallback)(const char *message)
The signature of the fatal error callback.
Definition: wings.h:105
Wg_Obj * Wg_GetKwargs(Wg_Context *context)
Get the keyword arguments dictionary passed to the current function.
Wg_UnOp
The unary operation to be used Wg_UnaryOp.
Definition: wings.h:208
@ WG_UOP_NOT
The logical not operator.
Definition: wings.h:233
@ WG_UOP_INT
The integer conversion operator.
Definition: wings.h:261
@ WG_UOP_FLOAT
The float operator operator.
Definition: wings.h:268
@ WG_UOP_POS
The identity operator.
Definition: wings.h:214
@ WG_UOP_BITNOT
The bitwise complement operator.
Definition: wings.h:226
@ WG_UOP_STR
The string conversion operator.
Definition: wings.h:275
@ WG_UOP_LEN
The length operator.
Definition: wings.h:247
@ WG_UOP_REPR
The string representation operator.
Definition: wings.h:282
@ WG_UOP_INDEX
The index conversion operator.
Definition: wings.h:289
@ WG_UOP_HASH
The hash operator.
Definition: wings.h:240
@ WG_UOP_BOOL
The bool conversion operator.
Definition: wings.h:254
@ WG_UOP_NEG
The unary minus operator.
Definition: wings.h:220
Wg_Obj * Wg_ImportModule(Wg_Context *context, const char *module, const char *alias)
Import a module.
void Wg_RaiseExceptionObject(Wg_Obj *obj)
Raise an existing exception object.
void Wg_RaiseKeyError(Wg_Context *context, Wg_Obj *key)
Raise a KeyError with a formatted message.
bool(* Wg_IterationCallback)(Wg_Obj *obj, void *userdata)
The signature of an iteration callback used by Wg_Iterate().
Definition: wings.h:118
Wg_Obj * Wg_ImportFromModule(Wg_Context *context, const char *module, const char *name, const char *alias)
Import a specific name from a module.
Wg_Obj * Wg_CallMethodFromBase(Wg_Obj *obj, const char *method, Wg_Obj **argv, int argc, Wg_Obj *kwargs, Wg_Obj *baseClass)
Call a method on a object, skipping methods which belong to the most derived layer.
void Wg_ClearException(Wg_Context *context)
Clear the current exception.
Wg_BinOp
The binary operation to be used by Wg_BinaryOp.
Definition: wings.h:295
@ WG_BOP_SHL
The bit left shift operator.
Definition: wings.h:377
@ WG_BOP_DIV
The division operator.
Definition: wings.h:319
@ WG_BOP_NOTIN
The not in operator.
Definition: wings.h:397
@ WG_BOP_IN
The in operator.
Definition: wings.h:390
@ WG_BOP_LE
The less than or equals operator.
Definition: wings.h:425
@ WG_BOP_GT
The greater than operator.
Definition: wings.h:432
@ WG_BOP_POW
The power operator.
Definition: wings.h:337
@ WG_BOP_BITXOR
The xor operator.
Definition: wings.h:355
@ WG_BOP_FLOORDIV
The floor division operator.
Definition: wings.h:325
@ WG_BOP_NE
The not equals operator.
Definition: wings.h:411
@ WG_BOP_LT
The less than operator.
Definition: wings.h:418
@ WG_BOP_MOD
The modulo operator.
Definition: wings.h:331
@ WG_BOP_OR
The logical or operator.
Definition: wings.h:371
@ WG_BOP_SUB
The subtraction operator.
Definition: wings.h:307
@ WG_BOP_MUL
The multiplication operator.
Definition: wings.h:313
@ WG_BOP_BITAND
The bitwise and operator.
Definition: wings.h:343
@ WG_BOP_BITOR
The bitwise or operator.
Definition: wings.h:349
@ WG_BOP_GE
The greater than or equals operator.
Definition: wings.h:439
@ WG_BOP_AND
The logical and operator.
Definition: wings.h:363
@ WG_BOP_ADD
The addition operator.
Definition: wings.h:301
@ WG_BOP_EQ
The equals operator.
Definition: wings.h:404
@ WG_BOP_SHR
The bit right shift operator.
Definition: wings.h:383
Wg_Obj * Wg_NewClass(Wg_Context *context, const char *name, Wg_Obj **bases, int basesLen)
Instantiate a class object.
Wg_Context * Wg_CreateContext(const Wg_Config *config)
Create an instance of an interpreter.
const char * Wg_GetString(const Wg_Obj *obj, int *len)
Get the value from a string object.
Wg_Obj * Wg_NewInt(Wg_Context *context, Wg_int value)
Instantiate an integer object.
Wg_Context * Wg_GetContextFromObject(Wg_Obj *obj)
Get the context associated with an object.
double Wg_float
The underlying data type of a float object.
Definition: wings.h:55
struct Wg_Obj Wg_Obj
An opaque type representing an object in the interpreter.
Definition: wings.h:34
bool Wg_IsDictionary(const Wg_Obj *obj)
Check if an object is a dictionary.
Wg_Obj * Wg_ExecuteExpression(Wg_Context *context, const char *script, const char *prettyName)
Execute a script containing an expression.
Wg_Obj * Wg_Call(Wg_Obj *callable, Wg_Obj **argv, int argc, Wg_Obj *kwargs)
Call a callable object.
void(* Wg_Finalizer)(void *userdata)
The signature of an object finalizer.
Definition: wings.h:82
Wg_Obj * Wg_CompileExpression(Wg_Context *context, const char *script, const char *prettyName)
Compile an expression into a function object.
void Wg_PrintString(const Wg_Context *context, const char *message)
Print a string message.
void Wg_RegisterModule(Wg_Context *context, const char *name, Wg_ModuleLoader loader)
Register a callback to be called when a module with the given name is imported. In the callback,...
void Wg_RaiseAttributeError(const Wg_Obj *obj, const char *attribute)
Raise a AttributeError with a formatted message.
Wg_Obj * Wg_NewList(Wg_Context *context, Wg_Obj **argv, int argc)
Instantiate a list object.
Wg_Obj * Wg_GetIndex(Wg_Obj *obj, Wg_Obj *index)
Index an object.
Wg_Obj * Wg_None(Wg_Context *context)
Get the None singleton value.
Wg_Obj * Wg_GetGlobal(Wg_Context *context, const char *name)
Get a global variable in the current module namespace.
void Wg_Print(const Wg_Context *context, const char *message, int len)
Print a message.
Wg_Obj * Wg_UnaryOp(Wg_UnOp op, Wg_Obj *arg)
Perform a unary operation.
Wg_Obj * Wg_GetException(Wg_Context *context)
Get the current exception object.
void Wg_IncRef(Wg_Obj *obj)
Increment the reference count of an object. A positive reference count prevents the object from being...
Wg_Obj * Wg_NewStringBuffer(Wg_Context *context, const char *buffer, int len)
Instantiate a string object from a buffer.
void Wg_SetErrorCallback(Wg_ErrorCallback callback)
Set a callback for programmer errors.
void Wg_CollectGarbage(Wg_Context *context)
Force run the garbage collector and free all unreachable objects.
void Wg_ReraiseExceptionObject(Wg_Obj *obj)
Raise an existing exception object without affecting the stack trace.
Wg_int Wg_GetInt(const Wg_Obj *obj)
Get the value from an integer object.
Wg_Obj *(* Wg_Function)(Wg_Context *context, Wg_Obj **argv, int argc)
The signature of a native function registered into the interpreter as a function object.
Definition: wings.h:71
int64_t Wg_int
The underlying data type of an integer object.
Definition: wings.h:41
bool Wg_TryGetUserdata(const Wg_Obj *obj, const char *type, void **userdata)
Get the userdata from an object if it is of the expected type.