]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: lua: add utility function for check boolean argument
authorThierry FOURNIER / OZON.IO <thierry.fournier@ozon.io>
Thu, 24 Nov 2016 19:37:38 +0000 (20:37 +0100)
committerWilly Tarreau <w@1wt.eu>
Thu, 24 Nov 2016 20:35:10 +0000 (21:35 +0100)
Strangely, the Lua API doesn't provides a function like
luaL_checkboolean(). This little function add this one.

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

index e4ce5f0912c0be6181e214f2960ec6a3bb6b13a6..291bd428c23c6bea3445f7c7b536c6579641bb35 100644 (file)
@@ -1,6 +1,8 @@
 #ifndef _PROTO_HLUA_FCN_H
 #define _PROTO_HLUA_FCN_H
 
+int hlua_checkboolean(lua_State *L, int index);
+
 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));
index 3af4f6e20997e09075e37538adb6c199f6ece5b3..cff1e3af952dbafaa9cc6a1a2bfbd3b2b8e691b8 100644 (file)
@@ -41,6 +41,13 @@ static int class_listener_ref;
 
 static struct field stats[STATS_LEN];
 
+int hlua_checkboolean(lua_State *L, int index)
+{
+       if (!lua_isboolean(L, index))
+               luaL_argerror(L, index, "boolean expected");
+       return lua_toboolean(L, index);
+}
+
 /* This function gets a struct field and convert it in Lua
  * variable. The variable is pushed at the top of the stak.
  */