summaryrefslogtreecommitdiff
path: root/deno2/main.cc
blob: 506469dfa13087eccc0c4985e7b0554b9eef5685 (plain)
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
// Copyright 2018 Ryan Dahl <ry@tinyclouds.org>
// All rights reserved. MIT License.
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string>

#include "./msg.pb.h"
#include "include/deno.h"

void MessagesFromJS(Deno* d, const char* channel, deno_buf buf) {
  printf("MessagesFromJS %s\n", channel);

  char cwdbuf[1024];
  std::string cwd(getcwd(cwdbuf, sizeof(cwdbuf)));

  deno::Msg response;
  response.set_command(deno::Msg_Command_START);
  response.set_start_cwd(cwd);

  std::string output;
  assert(response.SerializeToString(&output) == true);

  auto bufout = deno_buf{output.c_str(), output.length()};
  deno_set_response(d, bufout);
}

int main(int argc, char** argv) {
  deno_init();

  Deno* d = deno_new(NULL, MessagesFromJS);
  bool r = deno_execute(d, "deno_main.js", "denoMain();");
  if (!r) {
    printf("Error! %s\n", deno_last_exception(d));
    exit(1);
  }
  deno_delete(d);
}