]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: lua: lua integration in the build and init system.
authorThierry FOURNIER <tfournier@haproxy.com>
Fri, 23 Jan 2015 13:06:13 +0000 (14:06 +0100)
committerWilly Tarreau <w@1wt.eu>
Sat, 28 Feb 2015 22:12:33 +0000 (23:12 +0100)
This is the first step of the lua integration. We add the useful
files in the HAProxy project. These files contains the main
includes, the Makefile options and empty initialisation function.
Is is the LUA skeleton.

Makefile
include/proto/hlua.h [new file with mode: 0644]
include/types/hlua.h [new file with mode: 0644]
src/haproxy.c
src/hlua.c [new file with mode: 0644]

index 052c0821ae600fcbd2a8a7766656c9c83d77be35..a48e9b3d0f57a54ab735499abc217ac5086dab03 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -28,6 +28,7 @@
 #   USE_VSYSCALL         : enable vsyscall on Linux x86, bypassing libc
 #   USE_GETADDRINFO      : use getaddrinfo() to resolve IPv6 host names.
 #   USE_OPENSSL          : enable use of OpenSSL. Recommended, but see below.
+#   USE_LUA              : enable Lua support.
 #   USE_FUTEX            : enable use of futex on kernel 2.6. Automatic.
 #   USE_ACCEPT4          : enable use of accept4() on linux. Automatic.
 #   USE_MY_ACCEPT4       : use own implemention of accept4() if glibc < 2.10.
@@ -74,6 +75,8 @@
 #   PCRE_INC       : force the include path to libpcre ($PCREDIR/inc)
 #   SSL_LIB        : force the lib path to libssl/libcrypto
 #   SSL_INC        : force the include path to libssl/libcrypto
+#   LUA_LIB        : force the lib path to lua
+#   LUA_INC        : force the include path to lua
 #   IGNOREGIT      : ignore GIT commit versions if set.
 #   VERSION        : force haproxy version reporting.
 #   SUBVERS        : add a sub-version (eg: platform, model, ...).
@@ -557,6 +560,12 @@ endif
 endif
 endif
 
+ifneq ($(USE_LUA),)
+OPTIONS_CFLAGS  += -DUSE_LUA $(if $(LUA_INC),-I$(LUA_INC))
+OPTIONS_LDFLAGS += $(if $(LUA_LIB),-L$(LUA_LIB)) -llua -lm
+OPTIONS_OBJS    += src/hlua.o
+endif
+
 ifneq ($(USE_PCRE)$(USE_STATIC_PCRE)$(USE_PCRE_JIT),)
 # PCREDIR is used to automatically construct the PCRE_INC and PCRE_LIB paths,
 # by appending /include and /lib respectively. If your system does not use the
diff --git a/include/proto/hlua.h b/include/proto/hlua.h
new file mode 100644 (file)
index 0000000..c69210e
--- /dev/null
@@ -0,0 +1,11 @@
+#ifndef _PROTO_HLUA_H
+#define _PROTO_HLUA_H
+
+#include <lua.h>
+
+#include <types/hlua.h>
+
+/* Lua HAProxy integration functions. */
+void hlua_init();
+
+#endif /* _PROTO_HLUA_H */
diff --git a/include/types/hlua.h b/include/types/hlua.h
new file mode 100644 (file)
index 0000000..d1aa235
--- /dev/null
@@ -0,0 +1,6 @@
+#ifndef _TYPES_HLUA_H
+#define _TYPES_HLUA_H
+
+#include <lua.h>
+
+#endif /* _TYPES_HLUA_H */
index f50deff952cfdcf58e5ad30033fcb0f8fa8f8b7d..76561676c990dc2c1f647ac969d2c6c1193ad562 100644 (file)
@@ -88,6 +88,9 @@
 #include <proto/connection.h>
 #include <proto/fd.h>
 #include <proto/hdr_idx.h>
+#ifdef USE_LUA
+#include <proto/hlua.h>
+#endif
 #include <proto/listener.h>
 #include <proto/log.h>
 #include <proto/pattern.h>
@@ -558,6 +561,11 @@ void init(int argc, char **argv)
        init_pendconn();
        init_proto_http();
 
+#ifdef USE_LUA
+       /* Initialise lua. */
+       hlua_init();
+#endif
+
        global.tune.options |= GTUNE_USE_SELECT;  /* select() is always available */
 #if defined(ENABLE_POLL)
        global.tune.options |= GTUNE_USE_POLL;
diff --git a/src/hlua.c b/src/hlua.c
new file mode 100644 (file)
index 0000000..3e0b19f
--- /dev/null
@@ -0,0 +1,18 @@
+#include <lauxlib.h>
+#include <lua.h>
+#include <lualib.h>
+
+/* Lua uses longjmp to perform yield or throwing errors. This
+ * macro is used only for identifying the function that can
+ * not return because a longjmp is executed.
+ *   __LJMP marks a prototype of hlua file that can use longjmp.
+ *   WILL_LJMP() marks an lua function that will use longjmp.
+ *   MAY_LJMP() marks an lua function that may use longjmp.
+ */
+#define __LJMP
+#define WILL_LJMP(func) func
+#define MAY_LJMP(func) func
+
+void hlua_init(void)
+{
+}