Melang

Logo

A script language of time-sharing scheduling coroutine in single thread

View the Project on GitHub Water-Melon/Melang

Pipe

The pipe provides a way for the C level to communicate with the script level.

Functions

In C
int mln_lang_ctx_pipe_send(mln_lang_ctx_t *ctx, char *fmt, ...);

This function will send a data set given by ... to a specified script task by ctx.

fmt is used for the interpretation of variable parameters, fmt supports three characters:

Return value:

int mln_trace_recv_handler_set(mln_lang_ctx_pipe_recv_cb_t recv_handler);

typedef int (*mln_lang_ctx_pipe_recv_cb_t)(mln_lang_ctx_t *, mln_lang_val_t *);

This function is used to receive data from the script level in C code.

The parameters of recv_handler:

Return value:

In Melang

Pipe(op);

This function is used to subscribe, unsubscribe and receive data from C layer.

op has three values:

Return value:

Example

In C

mln_lang_ctx_pipe_send(ctx, "ir", 1, 3.14);

In Melang

sys = Import('sys');
Pipe('subscribe');
sys.print(Pipe('recv'));
Pipe('unsubscribe');

The output is:

[[1, 3.14], ]