2018-07-23 14:46:30 -04:00
|
|
|
// Copyright 2018 the Deno authors. All rights reserved. MIT license.
|
2018-07-06 03:19:19 -04:00
|
|
|
#ifndef DENO_H_
|
|
|
|
#define DENO_H_
|
2018-07-06 15:00:45 -04:00
|
|
|
#include <stddef.h>
|
2018-07-08 21:35:34 -04:00
|
|
|
#include <stdint.h>
|
2018-06-10 08:18:15 -04: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-09 20:24:34 -04:00
|
|
|
|
2018-06-09 18:32:04 -04:00
|
|
|
// Data that gets transmitted.
|
2018-06-10 08:18:15 -04:00
|
|
|
typedef struct {
|
2018-07-08 21:35:34 -04:00
|
|
|
uint8_t* alloc_ptr; // Start of memory allocation (returned from `malloc()`).
|
|
|
|
size_t alloc_len; // Length of the memory allocation.
|
|
|
|
uint8_t* data_ptr; // Start of logical contents (within the allocation).
|
|
|
|
size_t data_len; // Length of logical contents.
|
2018-06-10 08:18:15 -04:00
|
|
|
} deno_buf;
|
2018-06-09 21:44:56 -04:00
|
|
|
|
2018-06-09 18:32:04 -04:00
|
|
|
struct deno_s;
|
|
|
|
typedef struct deno_s Deno;
|
2018-06-09 21:44:56 -04:00
|
|
|
|
2018-07-01 12:07:12 -04:00
|
|
|
// A callback to receive a message from deno.send javascript call.
|
2018-06-11 16:19:34 -04:00
|
|
|
// buf is valid only for the lifetime of the call.
|
2018-07-06 16:26:34 -04:00
|
|
|
typedef void (*deno_recv_cb)(Deno* d, deno_buf buf);
|
2018-06-09 18:32:04 -04:00
|
|
|
|
2018-06-10 08:18:15 -04:00
|
|
|
void deno_init();
|
2018-06-10 08:34:59 -04:00
|
|
|
const char* deno_v8_version();
|
|
|
|
void deno_set_flags(int* argc, char** argv);
|
2018-06-09 18:32:04 -04:00
|
|
|
|
2018-07-01 12:07:12 -04:00
|
|
|
Deno* deno_new(void* data, deno_recv_cb cb);
|
2018-06-11 16:36:14 -04:00
|
|
|
void deno_delete(Deno* d);
|
2018-06-09 18:32:04 -04:00
|
|
|
|
2018-07-26 17:47:42 -04:00
|
|
|
// Returns the void* data provided in deno_new.
|
|
|
|
void* deno_get_data(Deno*);
|
|
|
|
|
2018-06-11 11:01:35 -04:00
|
|
|
// Returns false on error.
|
2018-06-09 18:32:04 -04:00
|
|
|
// Get error text with deno_last_exception().
|
2018-06-15 09:12:32 -04:00
|
|
|
// 0 = fail, 1 = success
|
|
|
|
int deno_execute(Deno* d, const char* js_filename, const char* js_source);
|
2018-06-09 18:32:04 -04:00
|
|
|
|
2018-07-01 12:07:12 -04: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 09:12:32 -04:00
|
|
|
// 0 = fail, 1 = success
|
2018-07-08 21:35:34 -04:00
|
|
|
// After calling deno_send(), the caller no longer owns `buf` and must not use
|
|
|
|
// it; deno_send() is responsible for releasing it's memory.
|
|
|
|
// TODO(piscisaureus) In C++ and/or Rust, use a smart pointer or similar to
|
|
|
|
// enforce this rule.
|
2018-07-06 16:26:34 -04:00
|
|
|
int deno_send(Deno* d, deno_buf buf);
|
2018-06-09 18:32:04 -04:00
|
|
|
|
2018-07-01 12:07:12 -04: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-07-08 21:35:34 -04:00
|
|
|
// After calling deno_set_response(), the caller no longer owns `buf` and must
|
|
|
|
// not access it; deno_set_response() is responsible for releasing it's memory.
|
2018-06-13 13:38:22 -04:00
|
|
|
void deno_set_response(Deno* d, deno_buf buf);
|
|
|
|
|
2018-06-09 18:32:04 -04:00
|
|
|
const char* deno_last_exception(Deno* d);
|
|
|
|
|
|
|
|
void deno_terminate_execution(Deno* d);
|
|
|
|
|
2018-06-10 08:18:15 -04:00
|
|
|
#ifdef __cplusplus
|
|
|
|
} // extern "C"
|
|
|
|
#endif
|
2018-07-06 03:19:19 -04:00
|
|
|
#endif // DENO_H_
|