Move clock into IO.
This commit is contained in:
@@ -2,7 +2,6 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "wren_core.h"
|
||||
#include "wren_value.h"
|
||||
@@ -731,12 +730,6 @@ DEF_NATIVE(string_subscript)
|
||||
RETURN_VAL(value);
|
||||
}
|
||||
|
||||
DEF_NATIVE(os_clock)
|
||||
{
|
||||
double time = (double)clock() / CLOCKS_PER_SEC;
|
||||
RETURN_NUM(time);
|
||||
}
|
||||
|
||||
static ObjClass* defineSingleClass(WrenVM* vm, const char* name)
|
||||
{
|
||||
size_t length = strlen(name);
|
||||
@@ -899,9 +892,6 @@ void wrenInitializeCore(WrenVM* vm)
|
||||
NATIVE(vm->stringClass, "!= ", string_bangeq);
|
||||
NATIVE(vm->stringClass, "[ ]", string_subscript);
|
||||
|
||||
ObjClass* osClass = defineClass(vm, "OS");
|
||||
NATIVE(osClass->metaclass, "clock", os_clock);
|
||||
|
||||
wrenInterpret(vm, "Wren core library", libSource);
|
||||
|
||||
vm->listClass = AS_CLASS(findGlobal(vm, "List"));
|
||||
|
||||
+9
-2
@@ -1,4 +1,5 @@
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "wren_io.h"
|
||||
|
||||
@@ -17,15 +18,21 @@ static const char* libSource =
|
||||
" }\n"
|
||||
"}\n";
|
||||
|
||||
static void writeString(WrenVM* vm)
|
||||
static void ioWriteString(WrenVM* vm)
|
||||
{
|
||||
const char* s = wrenGetArgumentString(vm, 1);
|
||||
// TODO: Check for null.
|
||||
printf("%s", s);
|
||||
}
|
||||
|
||||
static void ioClock(WrenVM* vm)
|
||||
{
|
||||
wrenReturnDouble(vm, (double)clock() / CLOCKS_PER_SEC);
|
||||
}
|
||||
|
||||
void wrenLoadIOLibrary(WrenVM* vm)
|
||||
{
|
||||
wrenInterpret(vm, "Wren IO library", libSource);
|
||||
wrenDefineStaticMethod(vm, "IO", "writeString_", 1, writeString);
|
||||
wrenDefineStaticMethod(vm, "IO", "writeString_", 1, ioWriteString);
|
||||
wrenDefineStaticMethod(vm, "IO", "clock", 0, ioClock);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user