Lua binding: New API: set_options

Signed-off-by: Jianhui Zhao <jianhuizhao329@gmail.com>
main
Jianhui Zhao 2018-07-19 21:27:51 +08:00
parent ab5eb4bdae
commit 8f8a29adc5
2 changed files with 22 additions and 0 deletions

View File

@ -30,6 +30,7 @@ print("uhttpd version:", uh.VERSION)
local srv = uh.new(port)
-- srv:set_options({docroot = "/home/zjh/www", index = "lua.html"})
-- srv:ssl_init("uhttpd.crt", "uhttpd.key")
print("Listen on:", port)

View File

@ -199,6 +199,26 @@ static int lua_uh_set_error404_cb(lua_State *L)
return 0;
}
static int lua_uh_set_options(lua_State *L)
{
struct lua_uh_server *lsrv = lua_touserdata(L, 1);
struct uh_server *srv = &lsrv->srv;
luaL_checktype(L, 2, LUA_TTABLE);
lua_getfield(L, 2, "docroot");
if (lua_tostring(L, -1))
srv->set_docroot(srv, lua_tostring(L, -1));
lua_pop(L, 1);
lua_getfield(L, 2, "index");
if (lua_tostring(L, -1))
srv->set_index_file(srv, lua_tostring(L, -1));
lua_pop(L, 1);
return 0;
}
static int lua_uh_server_free(lua_State *L)
{
struct lua_uh_server *lsrv = lua_touserdata(L, 1);
@ -212,6 +232,7 @@ static const luaL_Reg server_mt[] = {
{ "ssl_init", lua_uh_ssl_init },
{ "add_action", lua_uh_add_action },
{ "set_error404_cb", lua_uh_set_error404_cb },
{ "set_options", lua_uh_set_options },
{ "free", lua_uh_server_free },
{ NULL, NULL }
};