-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathiNode.cpp
46 lines (37 loc) · 919 Bytes
/
iNode.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <node.h>
#include <v8.h>
#include <iostream>
#include <string>
#include "toyasm.h"
using v8::Local;
using v8::Value;
using v8::FunctionCallbackInfo;
using v8::Isolate;
using v8::HandleScope;
using v8::Handle;
using v8::Object;
char* get(Local<Value> value, char* fallback = "")
{
if(value->IsString()) {
v8::String::Utf8Value str(value);
return *str;
}
return fallback;
}
void Create(const FunctionCallbackInfo<Value>& args) {
Isolate* isolate = Isolate::GetCurrent();
HandleScope scope(isolate);
if (args.Length() < 1) {
isolate->ThrowException(v8::Exception::TypeError(
v8::String::NewFromUtf8(isolate, "Wrong number of arguments")));
return;
}
char* val = get(args[0]);
Toyasm toasm;
toasm.create(val, false);
args.GetReturnValue().Set(1);
}
void Init(Handle<Object> exports) {
NODE_SET_METHOD(exports, "create", Create);
}
NODE_MODULE(toyasm, Init)