]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: lua: identify userdata objects
authorThierry FOURNIER <tfournier@arpalert.org>
Fri, 18 Sep 2015 05:35:06 +0000 (07:35 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 25 Sep 2015 21:40:20 +0000 (23:40 +0200)
This patch adds lua primitives for identifying lua class
associated with userdata.

src/hlua.c

index 966ed5adb6980ae2489977bab1d81f29f824ee7f..7e75a31c6497bada6bb862b5395e436dea49f949 100644 (file)
@@ -254,6 +254,13 @@ __LJMP static inline void hlua_class_function(lua_State *L, const char *name,
        lua_settable(L, -3);
 }
 
+__LJMP static int hlua_dump_object(struct lua_State *L)
+{
+       const char *name = (const char *)lua_tostring(L, lua_upvalueindex(1));
+       lua_pushfstring(L, "HAProxy class %s", name);
+       return 1;
+}
+
 /* This function check the number of arguments available in the
  * stack. If the number of arguments available is not the same
  * then <nb> an error is throwed.
@@ -4917,6 +4924,12 @@ void hlua_init(void)
        /* Create and fill the metatable. */
        lua_newtable(gL.T);
 
+       /* Create the __tostring identifier */
+       lua_pushstring(gL.T, "__tostring");
+       lua_pushstring(gL.T, CLASS_MAP);
+       lua_pushcclosure(gL.T, hlua_dump_object, 1);
+       lua_rawset(gL.T, -3);
+
        /* Create and fille the __index entry. */
        lua_pushstring(gL.T, "__index");
        lua_newtable(gL.T);
@@ -4948,6 +4961,12 @@ void hlua_init(void)
        /* Create and fill the metatable. */
        lua_newtable(gL.T);
 
+       /* Create the __tostring identifier */
+       lua_pushstring(gL.T, "__tostring");
+       lua_pushstring(gL.T, CLASS_CHANNEL);
+       lua_pushcclosure(gL.T, hlua_dump_object, 1);
+       lua_rawset(gL.T, -3);
+
        /* Create and fille the __index entry. */
        lua_pushstring(gL.T, "__index");
        lua_newtable(gL.T);
@@ -4979,6 +4998,12 @@ void hlua_init(void)
        /* Create and fill the metatable. */
        lua_newtable(gL.T);
 
+       /* Create the __tostring identifier */
+       lua_pushstring(gL.T, "__tostring");
+       lua_pushstring(gL.T, CLASS_FETCHES);
+       lua_pushcclosure(gL.T, hlua_dump_object, 1);
+       lua_rawset(gL.T, -3);
+
        /* Create and fille the __index entry. */
        lua_pushstring(gL.T, "__index");
        lua_newtable(gL.T);
@@ -5029,6 +5054,12 @@ void hlua_init(void)
        /* Create and fill the metatable. */
        lua_newtable(gL.T);
 
+       /* Create the __tostring identifier */
+       lua_pushstring(gL.T, "__tostring");
+       lua_pushstring(gL.T, CLASS_CONVERTERS);
+       lua_pushcclosure(gL.T, hlua_dump_object, 1);
+       lua_rawset(gL.T, -3);
+
        /* Create and fill the __index entry. */
        lua_pushstring(gL.T, "__index");
        lua_newtable(gL.T);
@@ -5076,6 +5107,12 @@ void hlua_init(void)
        /* Create and fill the metatable. */
        lua_newtable(gL.T);
 
+       /* Create the __tostring identifier */
+       lua_pushstring(gL.T, "__tostring");
+       lua_pushstring(gL.T, CLASS_HTTP);
+       lua_pushcclosure(gL.T, hlua_dump_object, 1);
+       lua_rawset(gL.T, -3);
+
        /* Create and fille the __index entry. */
        lua_pushstring(gL.T, "__index");
        lua_newtable(gL.T);
@@ -5116,6 +5153,12 @@ void hlua_init(void)
        /* Create and fill the metatable. */
        lua_newtable(gL.T);
 
+       /* Create the __tostring identifier */
+       lua_pushstring(gL.T, "__tostring");
+       lua_pushstring(gL.T, CLASS_TXN);
+       lua_pushcclosure(gL.T, hlua_dump_object, 1);
+       lua_rawset(gL.T, -3);
+
        /* Create and fille the __index entry. */
        lua_pushstring(gL.T, "__index");
        lua_newtable(gL.T);
@@ -5152,6 +5195,12 @@ void hlua_init(void)
        /* Create and fill the metatable. */
        lua_newtable(gL.T);
 
+       /* Create the __tostring identifier */
+       lua_pushstring(gL.T, "__tostring");
+       lua_pushstring(gL.T, CLASS_SOCKET);
+       lua_pushcclosure(gL.T, hlua_dump_object, 1);
+       lua_rawset(gL.T, -3);
+
        /* Create and fille the __index entry. */
        lua_pushstring(gL.T, "__index");
        lua_newtable(gL.T);