test: add test for creating a VM with null config and fix wrenNewVM to handle NULL config
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
#include "get_variable.h"
|
||||
#include "foreign_class.h"
|
||||
#include "lists.h"
|
||||
#include "new_vm.h"
|
||||
#include "slots.h"
|
||||
#include "value.h"
|
||||
|
||||
@@ -44,6 +45,9 @@ static WrenForeignMethodFn bindForeignMethod(
|
||||
method = listsBindMethod(fullName);
|
||||
if (method != NULL) return method;
|
||||
|
||||
method = newVMBindMethod(fullName);
|
||||
if (method != NULL) return method;
|
||||
|
||||
method = slotsBindMethod(fullName);
|
||||
if (method != NULL) return method;
|
||||
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
#include <string.h>
|
||||
|
||||
#include "new_vm.h"
|
||||
|
||||
static void nullConfig(WrenVM* vm)
|
||||
{
|
||||
WrenVM* otherVM = wrenNewVM(NULL);
|
||||
|
||||
// We should be able to execute code.
|
||||
WrenInterpretResult result = wrenInterpret(otherVM, "1 + 2");
|
||||
wrenSetSlotBool(vm, 0, result == WREN_RESULT_SUCCESS);
|
||||
|
||||
wrenFreeVM(otherVM);
|
||||
}
|
||||
|
||||
WrenForeignMethodFn newVMBindMethod(const char* signature)
|
||||
{
|
||||
if (strcmp(signature, "static VM.nullConfig()") == 0) return nullConfig;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
#include "wren.h"
|
||||
|
||||
WrenForeignMethodFn newVMBindMethod(const char* signature);
|
||||
@@ -0,0 +1,6 @@
|
||||
class VM {
|
||||
foreign static nullConfig()
|
||||
}
|
||||
// TODO: Other configuration settings.
|
||||
|
||||
System.print(VM.nullConfig()) // expect: true
|
||||
Reference in New Issue
Block a user