1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-01 09:24:20 -04:00
denoland-deno/deno2/include/deno.h

54 lines
1.6 KiB
C
Raw Normal View History

// Copyright 2018 Ryan Dahl <ry@tinyclouds.org>
// All rights reserved. MIT License.
2018-06-09 22:55:31 -04:00
#ifndef INCLUDE_DENO_H_
#define INCLUDE_DENO_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
// Data that gets transmitted.
2018-06-10 08:18:15 -04:00
typedef struct {
2018-06-11 16:19:34 -04:00
const char* data;
size_t len;
2018-06-10 08:18:15 -04:00
} deno_buf;
2018-06-09 21:44:56 -04:00
struct deno_s;
typedef struct deno_s Deno;
2018-06-09 21:44:56 -04:00
2018-06-11 16:19:34 -04:00
// A callback to receive a message from deno_pub javascript call.
// buf is valid only for the lifetime of the call.
typedef void (*deno_sub_cb)(Deno* d, const char* channel, deno_buf buf);
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-11 13:18:53 -04:00
Deno* deno_new(void* data, deno_sub_cb cb);
2018-06-11 16:36:14 -04:00
void deno_delete(Deno* d);
2018-06-11 11:01:35 -04:00
// Returns false on error.
// 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-11 15:57:25 -04:00
// Routes message to the javascript callback set with deno_sub(). 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
int deno_pub(Deno* d, const char* channel, deno_buf buf);
// Call this inside a deno_sub_cb to respond synchronously to messages.
// If this is not called during the life time of a deno_sub_cb callback
// the denoPub() call in javascript will return null.
void deno_set_response(Deno* d, deno_buf buf);
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-06-09 22:55:31 -04:00
#endif // INCLUDE_DENO_H_