MINOR: lua: Add a function to get a reference on a table in the stack

The hlua_checktable() function may now be used to create and return a
reference on a table in stack, given its position. This function ensures it
is really a table and throws an exception if not.

This patch is mandatory to allow the support of the filters written in lua.

(cherry picked from commit ba9e21dc68044e2ce5ffce317e8786f1079f6fee)
[cf: Required for another backport]
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
diff --git a/src/hlua.c b/src/hlua.c
index af64a02..0e606d7 100644
--- a/src/hlua.c
+++ b/src/hlua.c
@@ -363,6 +363,20 @@
 	return luaL_ref(L, LUA_REGISTRYINDEX);
 }
 
+/* Used to check an Lua table type in the stack. It creates and
+ * returns a reference of the table. This function throws an
+ * error if the rgument is not a "table".
+ */
+__LJMP unsigned int hlua_checktable(lua_State *L, int argno)
+{
+	if (!lua_istable(L, argno)) {
+		const char *msg = lua_pushfstring(L, "table expected, got %s", luaL_typename(L, argno));
+		WILL_LJMP(luaL_argerror(L, argno, msg));
+	}
+	lua_pushvalue(L, argno);
+	return luaL_ref(L, LUA_REGISTRYINDEX);
+}
+
 /* Return the string that is of the top of the stack. */
 const char *hlua_get_top_error_string(lua_State *L)
 {