Lua binding: New API: set_options
Signed-off-by: Jianhui Zhao <jianhuizhao329@gmail.com>main
parent
ab5eb4bdae
commit
8f8a29adc5
|
@ -30,6 +30,7 @@ print("uhttpd version:", uh.VERSION)
|
||||||
|
|
||||||
local srv = uh.new(port)
|
local srv = uh.new(port)
|
||||||
|
|
||||||
|
-- srv:set_options({docroot = "/home/zjh/www", index = "lua.html"})
|
||||||
-- srv:ssl_init("uhttpd.crt", "uhttpd.key")
|
-- srv:ssl_init("uhttpd.crt", "uhttpd.key")
|
||||||
|
|
||||||
print("Listen on:", port)
|
print("Listen on:", port)
|
||||||
|
|
|
@ -199,6 +199,26 @@ static int lua_uh_set_error404_cb(lua_State *L)
|
||||||
return 0;
|
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)
|
static int lua_uh_server_free(lua_State *L)
|
||||||
{
|
{
|
||||||
struct lua_uh_server *lsrv = lua_touserdata(L, 1);
|
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 },
|
{ "ssl_init", lua_uh_ssl_init },
|
||||||
{ "add_action", lua_uh_add_action },
|
{ "add_action", lua_uh_add_action },
|
||||||
{ "set_error404_cb", lua_uh_set_error404_cb },
|
{ "set_error404_cb", lua_uh_set_error404_cb },
|
||||||
|
{ "set_options", lua_uh_set_options },
|
||||||
{ "free", lua_uh_server_free },
|
{ "free", lua_uh_server_free },
|
||||||
{ NULL, NULL }
|
{ NULL, NULL }
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue