-
Notifications
You must be signed in to change notification settings - Fork 5
/
cmark.i
40 lines (33 loc) · 829 Bytes
/
cmark.i
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
%module cmark
%{
#include "cmark.h"
%}
// Renames:
// CMARK_NODE_PARAGRAPH -> NODE_PARAGRAPH
// cmark_parse_document -> parse_document
%rename("%(regex:/^(cmark|CMARK)_(.*)/\\2/)s") "";
%include "cmark.h"
%{
extern void push_cmark_node(lua_State *L, cmark_node *node)
{
SWIG_NewPointerObj(L,node,SWIGTYPE_p_cmark_node,0);
}
%}
%luacode {
function cmark.parse_string(s, opts)
return cmark.parse_document(s, string.len(s), opts)
end
function cmark.walk(node)
local iter = cmark.iter_new(node)
return function()
while true do
local et = cmark.iter_next(iter)
if et == cmark.EVENT_DONE then break end
local cur = cmark.iter_get_node(iter)
return cur, (et == cmark.EVENT_ENTER), cmark.node_get_type(cur)
end
cmark.iter_free(iter)
return nil
end
end
}