diff options
author | Ryan Dahl <ry@tinyclouds.org> | 2018-06-13 19:38:22 +0200 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2018-06-14 14:19:17 +0200 |
commit | 4ac67cf3435b3e15f95fadc20c98e37abf706ea4 (patch) | |
tree | 651b18c568e6ca8130d3d37de60a6a44e12e855b /deno2/main.cc | |
parent | f97216609d1705a21ddbe6ca3efb04817f026fc3 (diff) |
Demo protobufs in deno2.
Adds deno_set_response() to allow stack allocated responses.
Diffstat (limited to 'deno2/main.cc')
-rw-r--r-- | deno2/main.cc | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/deno2/main.cc b/deno2/main.cc index 2c0b1b298..506469dfa 100644 --- a/deno2/main.cc +++ b/deno2/main.cc @@ -3,13 +3,33 @@ #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, NULL); + 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)); |