-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhio.cpp
33 lines (25 loc) · 781 Bytes
/
hio.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
#include "hio.h"
#include "mainwindow.h"
using namespace v8;
QString rt(const char * s);
extern v8::Persistent<v8::Context> context;
v8::Handle<v8::Value>v8_js_print(const Arguments &args)
{
QString result = "";
for (int i = 0; i < args.Length(); ++i){
String::Utf8Value ascii(args[i]);
result += rt(*ascii);
}
QByteArray ba;
QTextCodec *codec = QTextCodec::codecForName("UTF-8");
ba = codec->fromUnicode(result);
fprintf(stderr,"%s",ba.data());fflush(stderr);
return Boolean::New(true);
}
io::io()
{
Handle<Object> global = context->Global();
Local<Object> ob = Object::New();
ob->Set(v8::String::NewSymbol("log"),v8::FunctionTemplate::New(v8_js_print)->GetFunction());
global->Set(String::New("io"), ob);
}