Simplify how built-in foreign methods and classes are wired up.

This commit is contained in:
Bob Nystrom
2015-09-21 07:58:39 -07:00
parent 8ef4ea6186
commit f6083b1756
9 changed files with 129 additions and 83 deletions
+1 -12
View File
@@ -3,7 +3,6 @@
#include "uv.h"
#include "io.h"
#include "scheduler.h"
#include "vm.h"
#include "wren.h"
@@ -28,7 +27,7 @@ static void sizeCallback(uv_fs_t* request)
schedulerResumeDouble(fiber, size);
}
static void startSize(WrenVM* vm)
void fileStartSize(WrenVM* vm)
{
const char* path = wrenGetArgumentString(vm, 1);
WrenValue* fiber = wrenGetArgumentValue(vm, 2);
@@ -39,13 +38,3 @@ static void startSize(WrenVM* vm)
uv_fs_stat(getLoop(), request, path, sizeCallback);
}
WrenForeignMethodFn ioBindForeign(
WrenVM* vm, const char* className, bool isStatic, const char* signature)
{
if (strcmp(className, "File") != 0) return NULL;
if (isStatic && strcmp(signature, "startSize_(_,_)") == 0) return startSize;
return NULL;
}
-9
View File
@@ -1,9 +0,0 @@
#ifndef io_h
#define io_h
#include "wren.h"
WrenForeignMethodFn ioBindForeign(
WrenVM* vm, const char* className, bool isStatic, const char* signature);
#endif
+1 -11
View File
@@ -13,22 +13,12 @@
static WrenValue* resume;
static WrenValue* resumeWithArg;
static void captureMethods(WrenVM* vm)
void schedulerCaptureMethods(WrenVM* vm)
{
resume = wrenGetMethod(vm, "scheduler", "Scheduler", "resume_(_)");
resumeWithArg = wrenGetMethod(vm, "scheduler", "Scheduler", "resume_(_,_)");
}
WrenForeignMethodFn schedulerBindForeign(
WrenVM* vm, const char* className, bool isStatic, const char* signature)
{
if (strcmp(className, "Scheduler") != 0) return NULL;
if (isStatic && strcmp(signature, "captureMethods_()") == 0) return captureMethods;
return NULL;
}
void schedulerResume(WrenValue* fiber)
{
wrenCall(getVM(), resume, NULL, "v", fiber);
-3
View File
@@ -3,9 +3,6 @@
#include "wren.h"
WrenForeignMethodFn schedulerBindForeign(
WrenVM* vm, const char* className, bool isStatic, const char* signature);
void schedulerResume(WrenValue* fiber);
void schedulerResumeDouble(WrenValue* fiber, double value);
void schedulerResumeString(WrenValue* fiber, const char* text);
+1 -12
View File
@@ -4,7 +4,6 @@
#include "uv.h"
#include "scheduler.h"
#include "timer.h"
#include "vm.h"
#include "wren.h"
@@ -26,7 +25,7 @@ static void timerCallback(uv_timer_t* handle)
schedulerResume(fiber);
}
static void startTimer(WrenVM* vm)
void timerStartTimer(WrenVM* vm)
{
int milliseconds = (int)wrenGetArgumentDouble(vm, 1);
WrenValue* fiber = wrenGetArgumentValue(vm, 2);
@@ -38,13 +37,3 @@ static void startTimer(WrenVM* vm)
uv_timer_init(getLoop(), handle);
uv_timer_start(handle, timerCallback, milliseconds, 0);
}
WrenForeignMethodFn timerBindForeign(
WrenVM* vm, const char* className, bool isStatic, const char* signature)
{
if (strcmp(className, "Timer") != 0) return NULL;
if (isStatic && strcmp(signature, "startTimer_(_,_)") == 0) return startTimer;
return NULL;
}
-9
View File
@@ -1,9 +0,0 @@
#ifndef timer_h
#define timer_h
#include "wren.h"
WrenForeignMethodFn timerBindForeign(
WrenVM* vm, const char* className, bool isStatic, const char* signature);
#endif