Skip to content

Commit

Permalink
Merge pull request #178 from domeengine/finalWrenAPI
Browse files Browse the repository at this point in the history
Final Wren API methods
  • Loading branch information
avivbeeri authored Feb 27, 2021
2 parents 637ed88 + 7a210d3 commit 86d2cd7
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
10 changes: 9 additions & 1 deletion docs/plugins/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -261,25 +261,33 @@ This is a list of provided methods:
double getSlotDouble(WrenVM* vm, int slot);
const char* getSlotString(WrenVM* vm, int slot);
const char* getSlotBytes(WrenVM* vm, int slot, int* length);
void abortFiber(WrenVM* vm, int slot);

WrenType getSlotType(WrenVM* vm, int slot);

void setSlotNewList(WrenVM* vm, int slot);
int getListCount(WrenVM* vm, int slot);
void getListElement(WrenVM* vm, int listSlot, int index, int elementSlot);
void setListElement(WrenVM* vm, int listSlot, int index, int elementSlot);
void insertInList(WrenVM* vm, int listSlot, int index, int elementSlot);

void setSlotNewMap(WrenVM* vm, int slot);
int getMapCount(WrenVM* vm, int slot);
bool getMapContainsKey(WrenVM* vm, int mapSlot, int keySlot);
void getMapValue(WrenVM* vm, int mapSlot, int keySlot, int valueSlot);
void setMapValue(WrenVM* vm, int mapSlot, int keySlot, int valueSlot);
void removeMapValue(WrenVM* vm, int mapSlot, int keySlot, int removedValueSlot);


WrenInterpretResult interpret(WrenVM* vm, const char* module, const char* source);
WrenInterpretResult call(WrenVM* vm, WrenHandle* method);

bool hasModule(WrenVM* vm, const char* module);
bool hasVariable(WrenVM* vm, const char* module, const char* name);
void getVariable(WrenVM* vm, const char* module, const char* name, int slot);
WrenHandle* getSlotHandle(WrenVM* vm, int slot);
void setSlotHandle(WrenVM* vm, int slot, WrenHandle* handle);
void releaseHandle(WrenVM* vm, WrenHandle* handle);
void abortFiber(WrenVM* vm, int slot);
```
### Module Embedding
Expand Down
17 changes: 15 additions & 2 deletions include/dome.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ typedef struct WrenHandle WrenHandle;
typedef void (*WrenForeignMethodFn)(WrenVM* vm);
typedef void (*WrenFinalizerFn)(void* data);

typedef enum
{
typedef enum {
WREN_TYPE_BOOL,
WREN_TYPE_NUM,
WREN_TYPE_FOREIGN,
Expand All @@ -76,6 +75,14 @@ typedef enum
// The object is of a type that isn't accessible by the C API.
WREN_TYPE_UNKNOWN
} WrenType;

typedef enum
{
WREN_RESULT_SUCCESS,
WREN_RESULT_COMPILE_ERROR,
WREN_RESULT_RUNTIME_ERROR
} WrenInterpretResult;

#endif

typedef DOME_Result (*DOME_Plugin_Hook) (DOME_Context context);
Expand Down Expand Up @@ -133,6 +140,12 @@ typedef struct {
WrenHandle* (*getSlotHandle)(WrenVM* vm, int slot);
void (*setSlotHandle)(WrenVM* vm, int slot, WrenHandle* handle);
void (*releaseHandle)(WrenVM* vm, WrenHandle* handle);

bool (*hasVariable)(WrenVM* vm, const char* module, const char* name);
bool (*hasModule)(WrenVM* vm, const char* module);

WrenInterpretResult (*call)(WrenVM* vm, WrenHandle* method);
WrenInterpretResult (*interpret)(WrenVM* vm, const char* module, const char* source);
} WREN_API_v0;

typedef struct {
Expand Down
7 changes: 6 additions & 1 deletion src/plugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,12 @@ WREN_API_v0 wren_v0 = {
.getVariable = wrenGetVariable,
.getSlotHandle = wrenGetSlotHandle,
.setSlotHandle = wrenSetSlotHandle,
.releaseHandle = wrenReleaseHandle
.releaseHandle = wrenReleaseHandle,

.hasVariable = wrenHasVariable,
.hasModule = wrenHasModule,
.call = wrenCall,
.interpret = wrenInterpret,
};

DOME_API_v0 dome_v0 = {
Expand Down

0 comments on commit 86d2cd7

Please sign in to comment.