]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: lua: move class registration facilities
authorThierry Fournier <tfournier@arpalert.org>
Mon, 22 Feb 2016 18:52:08 +0000 (19:52 +0100)
committerWilly Tarreau <w@1wt.eu>
Wed, 30 Mar 2016 13:42:20 +0000 (15:42 +0200)
The functions
 - hlua_class_const_int()
 - hlua_class_const_str()
 - hlua_class_function()
are use for common class registration actions.

The function 'hlua_dump_object()' is generic dump name function.

These functions can be used by all the HAProxy objects, so I move
it into the safe functions file.

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

index 179d40cc3c7521188e42d47678de4b256d2fa875..560d1f4eda2c3b86dd80e16eb98c0250904e99fc 100644 (file)
@@ -1,7 +1,11 @@
 #ifndef _PROTO_HLUA_FCN_H
 #define _PROTO_HLUA_FCN_H
 
+void hlua_class_const_int(lua_State *L, const char *name, int value);
+void hlua_class_const_str(lua_State *L, const char *name, const char *value);
+void hlua_class_function(lua_State *L, const char *name, int (*function)(lua_State *L));
 void *hlua_checkudata(lua_State *L, int ud, int class_ref);
 int hlua_fcn_reg_core_fcn(lua_State *L);
+int hlua_dump_object(lua_State *L);
 
 #endif /* _PROTO_HLUA_FCN_H */
index 54fbc48474a7026998e887e44f985bac7c8e9d64..402595a06abc0200a31056bbcdb2e11f62f66a3b 100644 (file)
@@ -264,49 +264,6 @@ const char *hlua_get_top_error_string(lua_State *L)
        return lua_tostring(L, -1);
 }
 
-/* The three following functions are useful for adding entries
- * in a table. These functions takes a string and respectively an
- * integer, a string or a function and add it to the table in the
- * top of the stack.
- *
- * These functions throws an error if no more stack size is
- * available.
- */
-__LJMP static inline void hlua_class_const_int(lua_State *L, const char *name,
-                                               int value)
-{
-       if (!lua_checkstack(L, 2))
-       WILL_LJMP(luaL_error(L, "full stack"));
-       lua_pushstring(L, name);
-       lua_pushinteger(L, value);
-       lua_rawset(L, -3);
-}
-__LJMP static inline void hlua_class_const_str(lua_State *L, const char *name,
-                                        const char *value)
-{
-       if (!lua_checkstack(L, 2))
-               WILL_LJMP(luaL_error(L, "full stack"));
-       lua_pushstring(L, name);
-       lua_pushstring(L, value);
-       lua_rawset(L, -3);
-}
-__LJMP static inline void hlua_class_function(lua_State *L, const char *name,
-                                       int (*function)(lua_State *L))
-{
-       if (!lua_checkstack(L, 2))
-               WILL_LJMP(luaL_error(L, "full stack"));
-       lua_pushstring(L, name);
-       lua_pushcclosure(L, function, 0);
-       lua_rawset(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.
index 5adb128153e4ed42042f261ff470af95ca8ce68a..c649aece6eb9af668c87c327b034a7c2dbf61288 100644 (file)
 /* Contains the class reference of the concat object. */
 static int class_concat_ref;
 
+/* The three following functions are useful for adding entries
+ * in a table. These functions takes a string and respectively an
+ * integer, a string or a function and add it to the table in the
+ * top of the stack.
+ *
+ * These functions throws an error if no more stack size is
+ * available.
+ */
+void hlua_class_const_int(lua_State *L, const char *name, int value)
+{
+       if (!lua_checkstack(L, 2))
+               luaL_error(L, "full stack");
+       lua_pushstring(L, name);
+       lua_pushinteger(L, value);
+       lua_rawset(L, -3);
+}
+void hlua_class_const_str(lua_State *L, const char *name, const char *value)
+{
+       if (!lua_checkstack(L, 2))
+               luaL_error(L, "full stack");
+       lua_pushstring(L, name);
+       lua_pushstring(L, value);
+       lua_rawset(L, -3);
+}
+void hlua_class_function(lua_State *L, const char *name, int (*function)(lua_State *L))
+{
+       if (!lua_checkstack(L, 2))
+               luaL_error(L, "full stack");
+       lua_pushstring(L, name);
+       lua_pushcclosure(L, function, 0);
+       lua_rawset(L, -3);
+}
+
+/* This function returns a string containg the HAProxy object name. */
+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;
+}
+
 /* Return an object of the expected type, or throws an error. */
 void *hlua_checkudata(lua_State *L, int ud, int class_ref)
 {