#include <nan.h>
#include <stdio.h>
using namespace v8;
#define MAX_INPUT_PER_LINE 4096
NAN_METHOD(Print)
{
  if (info.Length() == 0)
    printf("");
  else
  {
    Nan::Utf8String str(info[0]);
    printf(*str);
    if (info.Length() >= 2)
    {
      Nan::Utf8String suffix(info[1]);
      printf(*suffix);
    }
    else{
      printf("\n");
    }
  }
}
NAN_METHOD(ReadLine)
{
  char input[MAX_INPUT_PER_LINE];
  gets_s(input, MAX_INPUT_PER_LINE);
  info.GetReturnValue().Set(Nan::New(input).ToLocalChecked());
}

NAN_MODULE_INIT(Init)
{
  Isolate *isolate = Isolate::GetCurrent();
  Local<Context> context = isolate->GetCurrentContext();
  Local<Object> global = context->Global();
  Nan::Set(global, Nan::New("print").ToLocalChecked(), Nan::New<Function>(Print));
  Nan::Set(global, Nan::New("readline").ToLocalChecked(), Nan::New<Function>(ReadLine));
}

NODE_MODULE(NowCoderAddon, Init)