wings 0.2.1
An embeddable header-only Python interpreter for C/C++.
wings.h
Go to the documentation of this file.
1
7#pragma once
8#include <stdint.h>
9
10#ifdef __cplusplus
11extern "C" {
12#define WG_DEFAULT_ARG(arg) = arg
13#else
14#include <stdbool.h>
15#define WG_DEFAULT_ARG(arg)
16#endif
17
18#if defined(_WIN32) && defined(_WINDLL)
19#define WG_DLL_EXPORT __declspec(dllexport)
20#else
21#define WG_DLL_EXPORT
22#endif
23
29typedef struct Wg_Context Wg_Context;
30
34typedef struct Wg_Obj Wg_Obj;
35
41typedef int64_t Wg_int;
42
48typedef uint64_t Wg_uint;
49
55typedef double Wg_float;
56
71typedef Wg_Obj* (*Wg_Function)(Wg_Context* context, Wg_Obj** argv, int argc);
72
82typedef void (*Wg_Finalizer)(void* userdata);
83
96typedef void (*Wg_PrintFunction)(const char* message, int len, void* userdata);
97
105typedef void (*Wg_ErrorCallback)(const char* message);
106
118typedef bool (*Wg_IterationCallback)(Wg_Obj* obj, void* userdata);
119
128typedef bool (*Wg_ModuleLoader)(Wg_Context* context);
129
137typedef struct Wg_Config {
190 const char* importPath;
195 const char* const* argv;
202 int argc;
204
208typedef enum Wg_UnOp {
291
295typedef enum Wg_BinOp {
441
445typedef enum Wg_Exc {
535
545WG_DLL_EXPORT
546Wg_Context* Wg_CreateContext(const Wg_Config* config WG_DEFAULT_ARG(nullptr));
547
553WG_DLL_EXPORT
555
563WG_DLL_EXPORT
565
579WG_DLL_EXPORT
580bool Wg_Execute(Wg_Context* context, const char* script, const char* prettyName WG_DEFAULT_ARG(nullptr));
581
595WG_DLL_EXPORT
596Wg_Obj* Wg_ExecuteExpression(Wg_Context* context, const char* script, const char* prettyName WG_DEFAULT_ARG(nullptr));
597
611WG_DLL_EXPORT
612Wg_Obj* Wg_Compile(Wg_Context* context, const char* script, const char* prettyName WG_DEFAULT_ARG(nullptr));
613
627WG_DLL_EXPORT
628Wg_Obj* Wg_CompileExpression(Wg_Context* context, const char* script, const char* prettyName WG_DEFAULT_ARG(nullptr));
629
637WG_DLL_EXPORT
639
648WG_DLL_EXPORT
649const char* Wg_GetErrorMessage(Wg_Context* context);
650
659WG_DLL_EXPORT
661
673WG_DLL_EXPORT
674void Wg_RaiseException(Wg_Context* context, Wg_Exc type, const char* message WG_DEFAULT_ARG(nullptr));
675
688WG_DLL_EXPORT
689void Wg_RaiseExceptionClass(Wg_Obj* klass, const char* message WG_DEFAULT_ARG(nullptr));
690
702WG_DLL_EXPORT
704
716WG_DLL_EXPORT
718
730WG_DLL_EXPORT
731void Wg_RaiseArgumentCountError(Wg_Context* context, int given, int expected);
732
744WG_DLL_EXPORT
745void Wg_RaiseArgumentTypeError(Wg_Context* context, int index, const char* expected);
746
757WG_DLL_EXPORT
758void Wg_RaiseAttributeError(const Wg_Obj* obj, const char* attribute);
759
770WG_DLL_EXPORT
771void Wg_RaiseKeyError(Wg_Context* context, Wg_Obj* key WG_DEFAULT_ARG(nullptr));
772
783WG_DLL_EXPORT
784void Wg_RaiseNameError(Wg_Context* context, const char* name);
785
791WG_DLL_EXPORT
793
801WG_DLL_EXPORT
803
814WG_DLL_EXPORT
815Wg_Obj* Wg_IsInstance(const Wg_Obj* instance, Wg_Obj*const* types, int typesLen);
816
826WG_DLL_EXPORT
827Wg_Obj* Wg_GetGlobal(Wg_Context* context, const char* name);
828
838WG_DLL_EXPORT
839void Wg_SetGlobal(Wg_Context* context, const char* name, Wg_Obj* value);
840
853WG_DLL_EXPORT
854void Wg_Print(const Wg_Context* context, const char* message, int len);
855
866WG_DLL_EXPORT
867void Wg_PrintString(const Wg_Context* context, const char* message);
868
874WG_DLL_EXPORT
876
885WG_DLL_EXPORT
886void Wg_IncRef(Wg_Obj* obj);
887
898WG_DLL_EXPORT
899void Wg_DecRef(Wg_Obj* obj);
900
907WG_DLL_EXPORT
909
919WG_DLL_EXPORT
920Wg_Obj* Wg_NewBool(Wg_Context* context, bool value WG_DEFAULT_ARG(false));
921
931WG_DLL_EXPORT
932Wg_Obj* Wg_NewInt(Wg_Context* context, Wg_int value WG_DEFAULT_ARG(0));
933
943WG_DLL_EXPORT
944Wg_Obj* Wg_NewFloat(Wg_Context* context, Wg_float value WG_DEFAULT_ARG(0));
945
955WG_DLL_EXPORT
956Wg_Obj* Wg_NewString(Wg_Context* context, const char* value WG_DEFAULT_ARG(nullptr));
957
968WG_DLL_EXPORT
969Wg_Obj* Wg_NewStringBuffer(Wg_Context* context, const char* buffer, int len);
970
982WG_DLL_EXPORT
983Wg_Obj* Wg_NewTuple(Wg_Context* context, Wg_Obj** argv, int argc);
984
996WG_DLL_EXPORT
997Wg_Obj* Wg_NewList(Wg_Context* context, Wg_Obj** argv WG_DEFAULT_ARG(nullptr), int argc WG_DEFAULT_ARG(0));
998
1014WG_DLL_EXPORT
1015Wg_Obj* Wg_NewDictionary(Wg_Context* context, Wg_Obj** keys WG_DEFAULT_ARG(nullptr), Wg_Obj** values WG_DEFAULT_ARG(nullptr), int len WG_DEFAULT_ARG(0));
1016
1028WG_DLL_EXPORT
1029Wg_Obj* Wg_NewSet(Wg_Context* context, Wg_Obj** argv WG_DEFAULT_ARG(nullptr), int argc WG_DEFAULT_ARG(0));
1030
1045WG_DLL_EXPORT
1046Wg_Obj* Wg_NewFunction(Wg_Context* context, Wg_Function fptr, void* userdata, const char* prettyName WG_DEFAULT_ARG(nullptr));
1047
1064WG_DLL_EXPORT
1065Wg_Obj* Wg_BindMethod(Wg_Obj* klass, const char* name, Wg_Function fptr, void* userdata);
1066
1086WG_DLL_EXPORT
1087Wg_Obj* Wg_NewClass(Wg_Context* context, const char* name, Wg_Obj** bases, int basesLen);
1088
1095WG_DLL_EXPORT
1096bool Wg_IsNone(const Wg_Obj* obj);
1097
1104WG_DLL_EXPORT
1105bool Wg_IsBool(const Wg_Obj* obj);
1106
1113WG_DLL_EXPORT
1114bool Wg_IsInt(const Wg_Obj* obj);
1115
1122WG_DLL_EXPORT
1123bool Wg_IsIntOrFloat(const Wg_Obj* obj);
1124
1131WG_DLL_EXPORT
1132bool Wg_IsString(const Wg_Obj* obj);
1133
1140WG_DLL_EXPORT
1141bool Wg_IsTuple(const Wg_Obj* obj);
1142
1149WG_DLL_EXPORT
1150bool Wg_IsList(const Wg_Obj* obj);
1151
1158WG_DLL_EXPORT
1159bool Wg_IsDictionary(const Wg_Obj* obj);
1160
1167WG_DLL_EXPORT
1168bool Wg_IsSet(const Wg_Obj* obj);
1169
1176WG_DLL_EXPORT
1177bool Wg_IsFunction(const Wg_Obj* obj);
1178
1185WG_DLL_EXPORT
1186bool Wg_IsClass(const Wg_Obj* obj);
1187
1194WG_DLL_EXPORT
1195bool Wg_GetBool(const Wg_Obj* obj);
1196
1203WG_DLL_EXPORT
1205
1212WG_DLL_EXPORT
1214
1226WG_DLL_EXPORT
1227const char* Wg_GetString(const Wg_Obj* obj, int* len WG_DEFAULT_ARG(nullptr));
1228
1243WG_DLL_EXPORT
1244void Wg_SetUserdata(Wg_Obj* obj, void* userdata);
1245
1256WG_DLL_EXPORT
1257bool Wg_TryGetUserdata(const Wg_Obj* obj, const char* type, void** userdata);
1258
1269WG_DLL_EXPORT
1270void Wg_RegisterFinalizer(Wg_Obj* obj, Wg_Finalizer finalizer, void* userdata WG_DEFAULT_ARG(nullptr));
1271
1281WG_DLL_EXPORT
1282bool Wg_HasAttribute(Wg_Obj* obj, const char* attribute);
1283
1298WG_DLL_EXPORT
1299Wg_Obj* Wg_GetAttribute(Wg_Obj* obj, const char* attribute);
1300
1312WG_DLL_EXPORT
1313Wg_Obj* Wg_GetAttributeNoExcept(Wg_Obj* obj, const char* attribute);
1314
1324WG_DLL_EXPORT
1325void Wg_SetAttribute(Wg_Obj* obj, const char* attribute, Wg_Obj* value);
1326
1340WG_DLL_EXPORT
1341Wg_Obj* Wg_GetAttributeFromBase(Wg_Obj* obj, const char* attribute, Wg_Obj* baseClass WG_DEFAULT_ARG(nullptr));
1342
1358WG_DLL_EXPORT
1359bool Wg_Iterate(Wg_Obj* obj, void* userdata, Wg_IterationCallback callback);
1360
1372WG_DLL_EXPORT
1373bool Wg_Unpack(Wg_Obj* obj, int count, Wg_Obj** values);
1374
1386WG_DLL_EXPORT
1388
1398WG_DLL_EXPORT
1400
1418WG_DLL_EXPORT
1419Wg_Obj* Wg_Call(Wg_Obj* callable, Wg_Obj** argv, int argc, Wg_Obj* kwargs WG_DEFAULT_ARG(nullptr));
1420
1439WG_DLL_EXPORT
1440Wg_Obj* Wg_CallMethod(Wg_Obj* obj, const char* method, Wg_Obj** argv, int argc, Wg_Obj* kwargs WG_DEFAULT_ARG(nullptr));
1441
1465WG_DLL_EXPORT
1466Wg_Obj* Wg_CallMethodFromBase(Wg_Obj* obj, const char* method, Wg_Obj** argv, int argc, Wg_Obj* kwargs WG_DEFAULT_ARG(nullptr), Wg_Obj* baseClass WG_DEFAULT_ARG(nullptr));
1467
1485WG_DLL_EXPORT
1486bool Wg_ParseKwargs(Wg_Obj* dict, const char*const* keys, int keysLen, Wg_Obj** values);
1487
1499WG_DLL_EXPORT
1501
1514WG_DLL_EXPORT
1515Wg_Obj* Wg_SetIndex(Wg_Obj* obj, Wg_Obj* index, Wg_Obj* value);
1516
1526WG_DLL_EXPORT
1528
1541WG_DLL_EXPORT
1543
1554WG_DLL_EXPORT
1555void Wg_RegisterModule(Wg_Context* context, const char* name, Wg_ModuleLoader loader);
1556
1575WG_DLL_EXPORT
1576Wg_Obj* Wg_ImportModule(Wg_Context* context, const char* module, const char* alias WG_DEFAULT_ARG(nullptr));
1577
1595WG_DLL_EXPORT
1596Wg_Obj* Wg_ImportFromModule(Wg_Context* context, const char* module, const char* name, const char* alias WG_DEFAULT_ARG(nullptr));
1597
1613WG_DLL_EXPORT
1614bool Wg_ImportAllFromModule(Wg_Context* context, const char* module);
1615
1616#undef WG_DEFAULT_ARG
1617#undef WG_DLL_EXPORT
1618
1619#ifdef __cplusplus
1620} // extern "C"
1621#endif
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.