]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: lua: move common function
authorThierry Fournier <tfournier@arpalert.org>
Wed, 27 Jan 2016 08:55:30 +0000 (09:55 +0100)
committerWilly Tarreau <w@1wt.eu>
Fri, 12 Feb 2016 10:08:53 +0000 (11:08 +0100)
This patch moves the function hlua_checkudata which check that
an object contains the expected class_reference as metatable.
This function is commonly used by all the lua functions.
The function hlua_metatype is also moved.

include/proto/hlua_fcn.h
src/hlua.c
src/hlua_fcn.c

index 37d07ffa0535d0fe7bedc2ac49e8e0646f8e8c2a..179d40cc3c7521188e42d47678de4b256d2fa875 100644 (file)
@@ -1,6 +1,7 @@
 #ifndef _PROTO_HLUA_FCN_H
 #define _PROTO_HLUA_FCN_H
 
+void *hlua_checkudata(lua_State *L, int ud, int class_ref);
 int hlua_fcn_reg_core_fcn(lua_State *L);
 
 #endif /* _PROTO_HLUA_FCN_H */
index b4b8980e55c9554f4f551d7ce3463097c7c06c6b..11117205d86591216c11c2d1765351dbb52b3078 100644 (file)
@@ -306,47 +306,6 @@ __LJMP static inline void check_args(lua_State *L, int nb, char *fcn)
        WILL_LJMP(luaL_error(L, "'%s' needs %d arguments", fcn, nb));
 }
 
-/* Return true if the data in stack[<ud>] is an object of
- * type <class_ref>.
- */
-static int hlua_metaistype(lua_State *L, int ud, int class_ref)
-{
-       if (!lua_getmetatable(L, ud))
-               return 0;
-
-       lua_rawgeti(L, LUA_REGISTRYINDEX, class_ref);
-       if (!lua_rawequal(L, -1, -2)) {
-               lua_pop(L, 2);
-               return 0;
-       }
-
-       lua_pop(L, 2);
-       return 1;
-}
-
-/* Return an object of the expected type, or throws an error. */
-__LJMP static void *hlua_checkudata(lua_State *L, int ud, int class_ref)
-{
-       void *p;
-
-       /* Check if the stack entry is an array. */
-       if (!lua_istable(L, ud))
-               WILL_LJMP(luaL_argerror(L, ud, NULL));
-       /* Check if the metadata have the expected type. */
-       if (!hlua_metaistype(L, ud, class_ref))
-               WILL_LJMP(luaL_argerror(L, ud, NULL));
-       /* Push on the stack at the entry [0] of the table. */
-       lua_rawgeti(L, ud, 0);
-       /* Check if this entry is userdata. */
-       p = lua_touserdata(L, -1);
-       if (!p)
-               WILL_LJMP(luaL_argerror(L, ud, NULL));
-       /* Remove the entry returned by lua_rawgeti(). */
-       lua_pop(L, 1);
-       /* Return the associated struct. */
-       return p;
-}
-
 /* This fucntion push an error string prefixed by the file name
  * and the line number where the error is encountered.
  */
index a35ccfafe06e443ede5880db0e957e96fcb46f7b..7950038cef04192ee2ad11ed00a5af0988fb4310 100644 (file)
@@ -9,6 +9,47 @@
 
 #include <common/time.h>
 
+/* Return true if the data in stack[<ud>] is an object of
+ * type <class_ref>.
+ */
+static int hlua_metaistype(lua_State *L, int ud, int class_ref)
+{
+       if (!lua_getmetatable(L, ud))
+               return 0;
+
+       lua_rawgeti(L, LUA_REGISTRYINDEX, class_ref);
+       if (!lua_rawequal(L, -1, -2)) {
+               lua_pop(L, 2);
+               return 0;
+       }
+
+       lua_pop(L, 2);
+       return 1;
+}
+
+/* Return an object of the expected type, or throws an error. */
+void *hlua_checkudata(lua_State *L, int ud, int class_ref)
+{
+       void *p;
+
+       /* Check if the stack entry is an array. */
+       if (!lua_istable(L, ud))
+               WILL_LJMP(luaL_argerror(L, ud, NULL));
+       /* Check if the metadata have the expected type. */
+       if (!hlua_metaistype(L, ud, class_ref))
+               WILL_LJMP(luaL_argerror(L, ud, NULL));
+       /* Push on the stack at the entry [0] of the table. */
+       lua_rawgeti(L, ud, 0);
+       /* Check if this entry is userdata. */
+       p = lua_touserdata(L, -1);
+       if (!p)
+               WILL_LJMP(luaL_argerror(L, ud, NULL));
+       /* Remove the entry returned by lua_rawgeti(). */
+       lua_pop(L, 1);
+       /* Return the associated struct. */
+       return p;
+}
+
 /* This function return the current date at epoch format in milliseconds. */
 int hlua_now(lua_State *L)
 {