MINOR: lua: add class listener

This class provides the access to the listener struct, it allows
some manipulations and retrieve informations.
diff --git a/doc/lua-api/index.rst b/doc/lua-api/index.rst
index 07ade69..2bca4d0 100644
--- a/doc/lua-api/index.rst
+++ b/doc/lua-api/index.rst
@@ -597,6 +597,11 @@
   Contain an array with the attached servers. Each server entry is an object of
   type :ref:`server_class`.
 
+.. js:attribute:: Proxy.listeners
+
+  Contain an array with the attached listeners. Each listeners entry is an
+  object of type :ref:`listener_class`.
+
 .. js:function:: Proxy.pause(px)
 
   Pause the proxy. See the management socket documentation for more information.
@@ -811,6 +816,19 @@
   :param class_server sv: A :ref:`server_class` which indicates the manipulated
     server.
 
+.. _listener_class:
+
+Listener class
+==============
+
+.. js:function:: Listener.get_stats(ls)
+
+  Returns server statistics.
+
+  :param class_listener ls: A :ref:`listener_class` which indicates the
+    manipulated listener.
+  :returns: a key/value array containing stats
+
 .. _concat_class:
 
 Concat class
diff --git a/include/types/hlua.h b/include/types/hlua.h
index afe870a..43e9f1a 100644
--- a/include/types/hlua.h
+++ b/include/types/hlua.h
@@ -21,6 +21,7 @@
 #define CLASS_APPLET_HTTP  "AppletHTTP"
 #define CLASS_PROXY        "Proxy"
 #define CLASS_SERVER       "Server"
+#define CLASS_LISTENER     "Listener"
 
 struct stream;
 
diff --git a/src/hlua_fcn.c b/src/hlua_fcn.c
index 0e5a33d..2ee3393 100644
--- a/src/hlua_fcn.c
+++ b/src/hlua_fcn.c
@@ -33,6 +33,7 @@
 static int class_concat_ref;
 static int class_proxy_ref;
 static int class_server_ref;
+static int class_listener_ref;
 
 #define STATS_LEN (MAX((int)ST_F_TOTAL_FIELDS, (int)INF_TOTAL_FIELDS))
 
@@ -435,6 +436,48 @@
 	return 1;
 }
 
+int hlua_fcn_new_listener(lua_State *L, struct listener *lst)
+{
+	lua_newtable(L);
+
+	/* Pop a class sesison metatable and affect it to the userdata. */
+	lua_rawgeti(L, LUA_REGISTRYINDEX, class_listener_ref);
+	lua_setmetatable(L, -2);
+
+	lua_pushlightuserdata(L, lst);
+	lua_rawseti(L, -2, 0);
+	return 1;
+}
+
+static struct listener *hlua_check_listener(lua_State *L, int ud)
+{
+	return (struct listener *)(hlua_checkudata(L, ud, class_listener_ref));
+}
+
+int hlua_listener_get_stats(lua_State *L)
+{
+	struct listener *li;
+	int i;
+
+	li = hlua_check_listener(L, 1);
+
+	if (!li->frontend) {
+		lua_pushnil(L);
+		return 1;
+	}
+
+	stats_fill_li_stats(li->frontend, li, ST_SHLGNDS, stats, STATS_LEN);
+
+	lua_newtable(L);
+	for (i=0; i<ST_F_TOTAL_FIELDS; i++) {
+		lua_pushstring(L, stat_field_names[i]);
+		hlua_fcn_pushfield(L, &stats[i]);
+		lua_settable(L, -3);
+	}
+	return 1;
+
+}
+
 int hlua_fcn_new_server(lua_State *L, struct server *srv)
 {
 	lua_newtable(L);
@@ -713,6 +756,9 @@
 int hlua_fcn_new_proxy(lua_State *L, struct proxy *px)
 {
 	struct server *srv;
+	struct listener *lst;
+	int lid;
+	char buffer[10];
 
 	lua_newtable(L);
 
@@ -733,6 +779,23 @@
 	}
 	lua_settable(L, -3);
 
+	/* Browse and register listeners. */
+	lua_pushstring(L, "listeners");
+	lua_newtable(L);
+	lid = 1;
+	list_for_each_entry(lst, &px->conf.listeners, by_fe) {
+		if (lst->name)
+			lua_pushstring(L, lst->name);
+		else {
+			snprintf(buffer, 10, "sock-%d", lid);
+			lid++;
+			lua_pushstring(L, buffer);
+		}
+		hlua_fcn_new_listener(L, lst);
+		lua_settable(L, -3);
+	}
+	lua_settable(L, -3);
+
 	return 1;
 }
 
@@ -856,6 +919,14 @@
 	hlua_class_function(L, "concat", hlua_concat_new);
 	hlua_class_function(L, "get_info", hlua_get_info);
 
+	/* Create listener object. */
+	lua_newtable(L);
+	lua_pushstring(L, "__index");
+	lua_newtable(L);
+	hlua_class_function(L, "get_stats", hlua_listener_get_stats);
+	lua_settable(L, -3); /* -> META["__index"] = TABLE */
+	class_listener_ref = hlua_register_metatable(L, CLASS_LISTENER);
+
 	/* Create server object. */
 	lua_newtable(L);
 	lua_pushstring(L, "__index");