Merge branch 'master' into foreign-methods
This commit is contained in:
@@ -51,6 +51,13 @@
|
||||
#define WREN_USE_LIB_IO 1
|
||||
#endif
|
||||
|
||||
// If true, loads the "Meta" class in the standard library.
|
||||
//
|
||||
// Defaults to on.
|
||||
#ifndef WREN_USE_LIB_META
|
||||
#define WREN_USE_LIB_META 1
|
||||
#endif
|
||||
|
||||
// These flags are useful for debugging and hacking on Wren itself. They are not
|
||||
// intended to be used for production code. They default to off.
|
||||
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
#include "wren_meta.h"
|
||||
|
||||
#if WREN_USE_LIB_META
|
||||
|
||||
// This string literal is generated automatically from meta.wren. Do not edit.
|
||||
static const char* libSource =
|
||||
"class Meta {}\n";
|
||||
|
||||
void metaEval(WrenVM* vm)
|
||||
{
|
||||
const char* source = wrenGetArgumentString(vm, 1);
|
||||
// TODO: Type check argument.
|
||||
wrenInterpret(vm, "Meta", source);
|
||||
}
|
||||
|
||||
void wrenLoadMetaLibrary(WrenVM* vm)
|
||||
{
|
||||
wrenInterpret(vm, "", libSource);
|
||||
wrenDefineStaticMethod(vm, "Meta", "eval(_)", metaEval);
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,14 @@
|
||||
#ifndef wren_meta_h
|
||||
#define wren_meta_h
|
||||
|
||||
#include "wren.h"
|
||||
#include "wren_common.h"
|
||||
|
||||
// This module defines the Meta class and its associated methods.
|
||||
#if WREN_USE_LIB_META
|
||||
|
||||
void wrenLoadMetaLibrary(WrenVM* vm);
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
+10
-10
@@ -14,26 +14,23 @@
|
||||
#include "wren_io.h"
|
||||
#endif
|
||||
|
||||
#if WREN_USE_LIB_META
|
||||
#include "wren_meta.h"
|
||||
#endif
|
||||
|
||||
#if WREN_DEBUG_TRACE_MEMORY || WREN_DEBUG_TRACE_GC
|
||||
#include <time.h>
|
||||
#endif
|
||||
|
||||
// The built-in reallocation function used when one is not provided by the
|
||||
// configuration.
|
||||
static void* defaultReallocate(void* memory, size_t oldSize, size_t newSize)
|
||||
{
|
||||
return realloc(memory, newSize);
|
||||
}
|
||||
|
||||
WrenVM* wrenNewVM(WrenConfiguration* configuration)
|
||||
{
|
||||
WrenReallocateFn reallocate = defaultReallocate;
|
||||
WrenReallocateFn reallocate = realloc;
|
||||
if (configuration->reallocateFn != NULL)
|
||||
{
|
||||
reallocate = configuration->reallocateFn;
|
||||
}
|
||||
|
||||
WrenVM* vm = (WrenVM*)reallocate(NULL, 0, sizeof(*vm));
|
||||
WrenVM* vm = (WrenVM*)reallocate(NULL, sizeof(*vm));
|
||||
memset(vm, 0, sizeof(WrenVM));
|
||||
|
||||
vm->reallocate = reallocate;
|
||||
@@ -80,6 +77,9 @@ WrenVM* wrenNewVM(WrenConfiguration* configuration)
|
||||
#if WREN_USE_LIB_IO
|
||||
wrenLoadIOLibrary(vm);
|
||||
#endif
|
||||
#if WREN_USE_LIB_META
|
||||
wrenLoadMetaLibrary(vm);
|
||||
#endif
|
||||
|
||||
return vm;
|
||||
}
|
||||
@@ -214,7 +214,7 @@ void* wrenReallocate(WrenVM* vm, void* memory, size_t oldSize, size_t newSize)
|
||||
if (newSize > 0 && vm->bytesAllocated > vm->nextGC) collectGarbage(vm);
|
||||
#endif
|
||||
|
||||
return vm->reallocate(memory, oldSize, newSize);
|
||||
return vm->reallocate(memory, newSize);
|
||||
}
|
||||
|
||||
// Captures the local variable [local] into an [Upvalue]. If that local is
|
||||
|
||||
Reference in New Issue
Block a user