size: 1 KiB

1#ifndef DJOT_H
2#define DJOT_H
3#include <stdio.h>
4#include <string.h>
5#include <stdbool.h>
6#include <lua.h>
7
8/* Open a Lua virtual machine and load the djot code.
9 * This should only be done once, before all use of djot functions.
10 * The state can be closed with djot_close. */
11lua_State *djot_open();
12
13/* Close the Lua virtual machine opened by djot_open, freeing its
14 * memory. */
15void djot_close(lua_State *L);
16
17/* Report the error on the top of the Lua stack. This should
18 * be run immediately if a function that is supposed to return
19 * a pointer returns NULL. */
20void djot_report_error(lua_State *L);
21
22/* Return string version of error on top of Lua stack.
23* This should be run immediately if a function that is supposed to return
24* a pointer returns NULL. */
25const char *djot_get_error(lua_State *L);
26
27/* Parse input (optionally including source positions) and add
28 * a global 'doc' with the parsed AST. The
29 * subordinate functions djot_render_html, djot_render_ast,
30 * djot_render_matches, djot_apply_filter can then be used to manipulate
31 * or render the content. Returns 1 on success, 0 on error. */
32int djot_parse(lua_State *L, char *input, bool sourcepos);
33
34/* Render the document in the global 'doc' as HTML, returning a string,
35 * or NULL on error. */
36char *djot_render_html(lua_State *L);
37
38/* Render the AST of the document in the global 'doc' as JSON.
39 * NULL is returned on error. */
40char *djot_render_ast_json(lua_State *L);
41
42/* Render the AST of the document in the global 'doc' as JSON.
43 * NULL is returned on error. */
44char *djot_render_ast_pretty(lua_State *L);
45
46/* Tokenize input and render the matches.
47 * If 'as_json' is true, use JSON, otherwise, produce a compact
48 * human-readable tree. NULL is returned on error. */
49char *djot_parse_and_render_events(lua_State *L, char *input);
50
51/* Load a filter from a string and apply it to the AST in global 'doc'.
52 * Return 1 on success, 0 on error. */
53int djot_apply_filter(lua_State *L, char *filter);
54
55#endif