10. Janet Callbacks

10.1. Org Parser Callback for Janet

- State "DONE" from "DONE" [2020-01-15 Wed 17:06] - State "DONE" from "WIP" [2020-01-15 Wed 15:40] Callback to be used by Janet function.

<<static_funcdefs>>=
static void parse_org(weewiki_d *w,
                      const char *str,
                      unsigned int sz);
<<functions>>=
static void parse_org(weewiki_d *w,
                      const char *str,
                      unsigned int sz)
{
    orgparse_state_flags *f;
    orgparse_state *state;
    wws_parser_d *pd;

    pd = weewiki_ud(w);
    if (pd == NULL) return;
    state = calloc(1, orgparse_state_size());
    orgparse_state_init(state, pd->op, str, sz, pd);
    f = orgparse_state_flags_get(pd->state);
    orgparse_state_flags_set(state, f);
    orgparse_state_run(state);
    free(state);
}

10.2. Print Callback for Janet

Anytime Janet calls print, this is what happens.

<<static_funcdefs>>=
static void printer(weewiki_d *w,
                    const char *str,
                    unsigned int sz);
<<functions>>=
static void printer(weewiki_d *w,
                    const char *str,
                    unsigned int sz)
{
    wws_parser_d *pd;
    pd = weewiki_ud(w);
    if (pd == NULL) return;
    wws_buffer_write(pd->buf, str, sz);
}



prev | home | next