Skip to content

Commit

Permalink
Add new console bindings source
Browse files Browse the repository at this point in the history
  • Loading branch information
avaer committed May 23, 2019
1 parent a9440ac commit d917e51
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
22 changes: 22 additions & 0 deletions deps/exokit-bindings/console/include/console.h
@@ -0,0 +1,22 @@
#ifndef _CONSOLE_H_
#define _CONSOLE_H_

#include <stdio.h>

#include <v8.h>
#include <node.h>
#include <nan.h>

#include <defines.h>

using namespace v8;
using namespace node;

namespace console {

NAN_METHOD(Log);
Local<Object> Initialize(Isolate *isolate);

};

#endif
24 changes: 24 additions & 0 deletions deps/exokit-bindings/console/src/console.cc
@@ -0,0 +1,24 @@
#include <console.h>

namespace console {

NAN_METHOD(Log) {
Local<Uint8Array> array = Local<Uint8Array>::Cast(info[0]);
char *data = (char *)array->Buffer()->GetContents().Data() + array->ByteOffset();
size_t length = array->ByteLength();
fwrite(data, length, 1, stdout);
}

Local<Object> Initialize(Isolate *isolate) {
Nan::EscapableHandleScope scope;

Local<Object> result = Nan::New<Object>();

Local<FunctionTemplate> logFnTemplate = Nan::New<FunctionTemplate>(Log);
Local<Function> logFn = Nan::GetFunction(logFnTemplate).ToLocalChecked();
result->Set(JS_STR("Log"), logFn);

return scope.Escape(result);
}

};

0 comments on commit d917e51

Please sign in to comment.