Networking.
This commit is contained in:
+37
-1
@@ -4,6 +4,7 @@
|
||||
#include "modules.h"
|
||||
|
||||
#include "io.wren.inc"
|
||||
#include "net.wren.inc"
|
||||
#include "os.wren.inc"
|
||||
#include "repl.wren.inc"
|
||||
#include "scheduler.wren.inc"
|
||||
@@ -51,8 +52,22 @@ extern void stdinIsTerminal(WrenVM* vm);
|
||||
extern void stdinReadStart(WrenVM* vm);
|
||||
extern void stdinReadStop(WrenVM* vm);
|
||||
extern void stdoutFlush(WrenVM* vm);
|
||||
extern void stderrWrite(WrenVM* vm);
|
||||
extern void schedulerCaptureMethods(WrenVM* vm);
|
||||
extern void timerStartTimer(WrenVM* vm);
|
||||
extern void socketAllocate(WrenVM* vm);
|
||||
extern void socketFinalize(void* data);
|
||||
extern void socketConnect(WrenVM* vm);
|
||||
extern void socketWrite(WrenVM* vm);
|
||||
extern void socketRead(WrenVM* vm);
|
||||
extern void socketClose(WrenVM* vm);
|
||||
extern void netCaptureClass(WrenVM* vm);
|
||||
extern void netShutdown();
|
||||
extern void serverAllocate(WrenVM* vm);
|
||||
extern void serverFinalize(void* data);
|
||||
extern void serverBind(WrenVM* vm);
|
||||
extern void serverAccept(WrenVM* vm);
|
||||
extern void serverClose(WrenVM* vm);
|
||||
|
||||
// The maximum number of foreign methods a single class defines. Ideally, we
|
||||
// would use variable-length arrays for each class in the table below, but
|
||||
@@ -69,7 +84,7 @@ extern void timerStartTimer(WrenVM* vm);
|
||||
// If you add a new class to the largest module below, make sure to bump this.
|
||||
// Note that it also includes an extra slot for the sentinel value indicating
|
||||
// the end of the list.
|
||||
#define MAX_CLASSES_PER_MODULE 6
|
||||
#define MAX_CLASSES_PER_MODULE 8
|
||||
|
||||
// Describes one foreign method in a class.
|
||||
typedef struct
|
||||
@@ -167,6 +182,27 @@ static ModuleRegistry modules[] =
|
||||
CLASS(Stdout)
|
||||
STATIC_METHOD("flush()", stdoutFlush)
|
||||
END_CLASS
|
||||
CLASS(Stderr)
|
||||
STATIC_METHOD("write(_)", stderrWrite)
|
||||
END_CLASS
|
||||
END_MODULE
|
||||
MODULE(net)
|
||||
CLASS(Socket)
|
||||
ALLOCATE(socketAllocate)
|
||||
FINALIZE(socketFinalize)
|
||||
STATIC_METHOD("captureClass_()", netCaptureClass)
|
||||
METHOD("connect_(_,_,_)", socketConnect)
|
||||
METHOD("write_(_,_)", socketWrite)
|
||||
METHOD("read_(_)", socketRead)
|
||||
METHOD("close_()", socketClose)
|
||||
END_CLASS
|
||||
CLASS(Server)
|
||||
ALLOCATE(serverAllocate)
|
||||
FINALIZE(serverFinalize)
|
||||
METHOD("bind_(_,_)", serverBind)
|
||||
METHOD("accept_(_)", serverAccept)
|
||||
METHOD("close_()", serverClose)
|
||||
END_CLASS
|
||||
END_MODULE
|
||||
MODULE(os)
|
||||
CLASS(Platform)
|
||||
|
||||
@@ -286,9 +286,14 @@ static void initVM()
|
||||
uv_loop_init(loop);
|
||||
}
|
||||
|
||||
extern void ioShutdown();
|
||||
extern void netShutdown();
|
||||
extern void schedulerShutdown();
|
||||
|
||||
static void freeVM()
|
||||
{
|
||||
ioShutdown();
|
||||
netShutdown();
|
||||
schedulerShutdown();
|
||||
|
||||
uv_loop_close(loop);
|
||||
|
||||
Reference in New Issue
Block a user