Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update function signatures #21

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions Wren++.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ inline const char* errorTypeToString(WrenErrorType type)
}
}

char* loadModuleFnWrapper(WrenVM* vm, const char* mod) { return wrenpp::VM::loadModuleFn(mod); }
WrenLoadModuleResult loadModuleFnWrapper(WrenVM* vm, const char* mod)
{
return WrenLoadModuleResult{wrenpp::VM::loadModuleFn(mod), nullptr, nullptr};
}

void writeFnWrapper(WrenVM* vm, const char* text) { wrenpp::VM::writeFn(text); }

Expand All @@ -63,7 +66,12 @@ void errorFnWrapper(WrenVM*, WrenErrorType type, const char* module, int line, c
wrenpp::VM::errorFn(type, module, line, message);
}

void* reallocateFnWrapper(void* memory, std::size_t newSize)
void reportClassFnWrapper(WrenVM*, ClassInfo* classInfo)
{
wrenpp::VM::reportClassFn(classInfo);
}

void* reallocateFnWrapper(void* memory, std::size_t newSize, void*)
{
return wrenpp::VM::reallocateFn(memory, newSize);
}
Expand Down Expand Up @@ -220,6 +228,8 @@ ErrorFn VM::errorFn =

ReallocateFn VM::reallocateFn = std::realloc;

ReportClassFn VM::reportClassFn = [](ClassInfo*) -> void {};

std::size_t VM::initialHeapSize = 0xA00000u;

std::size_t VM::minHeapSize = 0x100000u;
Expand All @@ -241,6 +251,7 @@ VM::VM() : vm_{nullptr}
configuration.bindForeignClassFn = foreignClassProvider;
configuration.writeFn = writeFnWrapper;
configuration.errorFn = errorFnWrapper;
configuration.reportClassFn = reportClassFnWrapper;
configuration.userData = new BoundState();

vm_ = wrenNewVM(&configuration);
Expand Down
4 changes: 3 additions & 1 deletion Wren++.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define WRENPP_H_INCLUDED

extern "C" {
#include "wren.h"
#include <wren.h>
}
#include <string>
#include <functional> // for std::hash
Expand All @@ -23,6 +23,7 @@ using LoadModuleFn = std::function<char*(const char*)>;
using WriteFn = std::function<void(const char*)>;
using ReallocateFn = std::function<void*(void*, std::size_t)>;
using ErrorFn = std::function<void(WrenErrorType, const char*, int, const char*)>;
using ReportClassFn = std::function<void(ClassInfo*)>;

namespace detail
{
Expand Down Expand Up @@ -859,6 +860,7 @@ class VM
static WriteFn writeFn;
static ReallocateFn reallocateFn;
static ErrorFn errorFn;
static ReportClassFn reportClassFn;
static std::size_t initialHeapSize;
static std::size_t minHeapSize;
static int heapGrowthPercent;
Expand Down