Kaynağa Gözat

Add Lua function to list all options

bel2125 8 yıl önce
ebeveyn
işleme
096b5472a0
2 değiştirilmiş dosya ile 23 ekleme ve 0 silme
  1. 19 0
      src/mod_lua.inl
  2. 4 0
      test/page2.lua

+ 19 - 0
src/mod_lua.inl

@@ -1157,6 +1157,25 @@ lsp_get_option(lua_State *L)
 	lua_gettable(L, LUA_REGISTRYINDEX);
 	ctx = (struct mg_context *)lua_touserdata(L, -1);
 
+	if (num_args == 0) {
+		const struct mg_option *opts = mg_get_valid_options();
+
+		if (!opts) {
+			return 0;
+		}
+
+		lua_newtable(L);
+		while (opts->name) {
+			data = mg_get_option(ctx, opts->name);
+			if (data) {
+				reg_string(L, opts->name, data);
+			}
+			opts++;
+		}
+
+		return 1;
+	}
+
 	if (num_args == 1) {
 		type1 = lua_type(L, 1);
 		if (type1 == LUA_TSTRING) {

+ 4 - 0
test/page2.lua

@@ -57,6 +57,10 @@ recurse(_G[libname])
 -- Print connect function
 print_if_available(connect, "connect function")
 
+-- Get all server options
+mg.write("<li>server options</li>\n")
+recurse(mg.get_option())
+
 mg.write("</ul></p>\n");
 mg.write("<p> Today is " .. os.date("%A") .. "</p>\n");