]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: lua: post initialization
authorThierry Fournier <tfournier@arpalert.org>
Fri, 19 Feb 2016 19:53:30 +0000 (20:53 +0100)
committerWilly Tarreau <w@1wt.eu>
Wed, 30 Mar 2016 13:44:58 +0000 (15:44 +0200)
This patch adds a Lua post initialisation wrapper. It already exists for
pure Lua function, now it executes also C. It is useful for doing things
when the configuration is ready to use. For example we can can browse and
register all the proxies.

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

index 9c5d9081b7871ca1d73a9d4771e4e8385a01f4fb..e4ce5f0912c0be6181e214f2960ec6a3bb6b13a6 100644 (file)
@@ -6,6 +6,7 @@ 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_register_metatable(struct lua_State *L, char *name);
+int hlua_fcn_post_init(lua_State *L);
 int hlua_fcn_reg_core_fcn(lua_State *L);
 int hlua_dump_object(lua_State *L);
 
index 89b3a795fb296f548f3f90abc291dc8cde4871e2..0f491255baf84135bfbb77fca58e71b1b7bb2886 100644 (file)
@@ -6444,6 +6444,18 @@ int hlua_post_init()
        enum hlua_exec ret;
        const char *error;
 
+       /* Call post initialisation function in safe environement. */
+       if (!SET_SAFE_LJMP(gL.T)) {
+               if (lua_type(gL.T, -1) == LUA_TSTRING)
+                       error = lua_tostring(gL.T, -1);
+               else
+                       error = "critical error";
+               fprintf(stderr, "Lua post-init: %s.\n", error);
+               exit(1);
+       }
+       hlua_fcn_post_init(gL.T);
+       RESET_SAFE_LJMP(gL.T);
+
        list_for_each_entry(init, &hlua_init_functions, l) {
                lua_rawgeti(gL.T, LUA_REGISTRYINDEX, init->function_ref);
                ret = hlua_ctx_resume(&gL, 0);
index 1dcd650f2a660cfdfe981ac918c1514e90ea4e7c..215058a879d74625664e48a05c37702f009cdcb2 100644 (file)
@@ -313,6 +313,11 @@ static int hlua_concat_init(lua_State *L)
        return 1;
 }
 
+int hlua_fcn_post_init(lua_State *L)
+{
+       return 1;
+}
+
 int hlua_fcn_reg_core_fcn(lua_State *L)
 {
        if (!hlua_concat_init(L))