2018-06-10 00:32:04 +02:00
|
|
|
// Copyright 2018 Ryan Dahl <ry@tinyclouds.org>
|
|
|
|
// All rights reserved. MIT License.
|
2018-07-06 15:19:19 +08:00
|
|
|
#ifndef DENO_H_
|
|
|
|
#define DENO_H_
|
2018-06-10 14:18:15 +02:00
|
|
|
// Neither Rust nor Go support calling directly into C++ functions, therefore
|
|
|
|
// the public interface to libdeno is done in C.
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
2018-06-10 02:24:34 +02:00
|
|
|
|
2018-06-10 00:32:04 +02:00
|
|
|
// Data that gets transmitted.
|
2018-06-10 14:18:15 +02:00
|
|
|
typedef struct {
|
2018-06-11 22:19:34 +02:00
|
|
|
const char* data;
|
2018-06-10 00:32:04 +02:00
|
|
|
size_t len;
|
2018-06-10 14:18:15 +02:00
|
|
|
} deno_buf;
|
2018-06-10 03:44:56 +02:00
|
|
|
|
2018-06-10 00:32:04 +02:00
|
|
|
struct deno_s;
|
|
|
|
typedef struct deno_s Deno;
|
2018-06-10 03:44:56 +02:00
|
|
|
|
2018-07-01 18:07:12 +02:00
|
|
|
// A callback to receive a message from deno.send javascript call.
|
2018-06-11 22:19:34 +02:00
|
|
|
// buf is valid only for the lifetime of the call.
|
2018-07-01 18:07:12 +02:00
|
|
|
typedef void (*deno_recv_cb)(Deno* d, const char* channel, deno_buf buf);
|
2018-06-10 00:32:04 +02:00
|
|
|
|
2018-06-10 14:18:15 +02:00
|
|
|
void deno_init();
|
2018-06-10 14:34:59 +02:00
|
|
|
const char* deno_v8_version();
|
|
|
|
void deno_set_flags(int* argc, char** argv);
|
2018-06-10 00:32:04 +02:00
|
|
|
|
2018-07-01 18:07:12 +02:00
|
|
|
Deno* deno_new(void* data, deno_recv_cb cb);
|
2018-06-11 22:36:14 +02:00
|
|
|
void deno_delete(Deno* d);
|
2018-06-10 00:32:04 +02:00
|
|
|
|
2018-06-11 17:01:35 +02:00
|
|
|
// Returns false on error.
|
2018-06-10 00:32:04 +02:00
|
|
|
// Get error text with deno_last_exception().
|
2018-06-15 15:12:32 +02:00
|
|
|
// 0 = fail, 1 = success
|
|
|
|
int deno_execute(Deno* d, const char* js_filename, const char* js_source);
|
2018-06-10 00:32:04 +02:00
|
|
|
|
2018-07-01 18:07:12 +02:00
|
|
|
// Routes message to the javascript callback set with deno.recv(). A false
|
|
|
|
// return value indicates error. Check deno_last_exception() for exception text.
|
2018-06-15 15:12:32 +02:00
|
|
|
// 0 = fail, 1 = success
|
2018-07-01 18:07:12 +02:00
|
|
|
int deno_send(Deno* d, const char* channel, deno_buf buf);
|
2018-06-10 00:32:04 +02:00
|
|
|
|
2018-07-01 18:07:12 +02:00
|
|
|
// Call this inside a deno_recv_cb to respond synchronously to messages.
|
|
|
|
// If this is not called during the life time of a deno_recv_cb callback
|
|
|
|
// the deno.send() call in javascript will return null.
|
2018-06-13 19:38:22 +02:00
|
|
|
void deno_set_response(Deno* d, deno_buf buf);
|
|
|
|
|
2018-06-10 00:32:04 +02:00
|
|
|
const char* deno_last_exception(Deno* d);
|
|
|
|
|
|
|
|
void deno_terminate_execution(Deno* d);
|
|
|
|
|
2018-06-10 14:18:15 +02:00
|
|
|
#ifdef __cplusplus
|
|
|
|
} // extern "C"
|
|
|
|
#endif
|
2018-07-06 15:19:19 +08:00
|
|
|
#endif // DENO_H_
|