diff --git a/README.md b/README.md index 2fc0a3f..ac6d0bc 100644 --- a/README.md +++ b/README.md @@ -58,7 +58,7 @@ table: ``` -markdown.compile(markdown_text,flag,flag,flag) +markdown.compile(markdown_text,flags) ``` @@ -103,7 +103,7 @@ Example: ``` -markdown.compile(markdown_text,"extrafootnote","toc","notables") +markdown.compile(markdown_text,{"extrafootnote","toc","notables"}) ``` diff --git a/discount3.c b/discount3.c index fd88a40..930f068 100644 --- a/discount3.c +++ b/discount3.c @@ -61,17 +61,25 @@ static int compile(lua_State *L) { MMIOT *doc; mkd_flag_t *flags = mkd_flags(); char *body = NULL, *toc = NULL, *css = NULL; - int body_size, toc_size, css_size, i, argc; + int body_size, toc_size, css_size; size_t input_size; const char *input = luaL_checklstring(L, 1, &input_size); luaL_argcheck(L, input_size < INT_MAX, 1, "string too long"); - - for (i = 2, argc = lua_gettop(L); i <= argc; i++) { - mkd_set_flag_num(flags, option_codes[luaL_checkoption(L, i, NULL, options)]); + + if (lua_gettop(L) >= 2) { + luaL_argcheck(L, lua_istable(L, 2), 2, "second argument must be a table"); + lua_pushvalue(L, 2); + lua_pushnil(L); + while (lua_next(L, -2) != 0) { + mkd_set_flag_num(flags, option_codes[luaL_checkoption(L, -1, NULL, options)]); + lua_pop(L, 1); + } + lua_pop(L, 1); } doc = mkd_string(input, (int) input_size, flags); + if (unlikely(doc == NULL)) { lua_pushnil(L); lua_pushstring(L, "mkd_string() returned NULL"); diff --git a/discount3.o b/discount3.o index 3c26f7f..9417704 100644 Binary files a/discount3.o and b/discount3.o differ diff --git a/discount3.so b/discount3.so index bae3ef8..fab6042 100755 Binary files a/discount3.so and b/discount3.so differ diff --git a/test.lua b/test.lua index b0636ad..a14b358 100644 --- a/test.lua +++ b/test.lua @@ -25,13 +25,13 @@ do end do - local doc = assert(compile("", "toc")) + local doc = assert(compile("", {"toc"})) assert(doc.body == "") assert(not doc.index) end do - local doc = assert(compile("# Heading", "toc")) + local doc = assert(compile("# Heading", {"toc"})) assert(doc.body) assert(doc.index) print(doc.index)