Coverage Report

Created: 2026-07-12 06:33

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/haproxy/include/haproxy/hlua.h
Line
Count
Source
1
/*
2
 * include/haproxy/hlua.h
3
 * Lua core management functions
4
 *
5
 * Copyright (C) 2015-2016 Thierry Fournier <tfournier@arpalert.org>
6
 *
7
 * This library is free software; you can redistribute it and/or
8
 * modify it under the terms of the GNU Lesser General Public
9
 * License as published by the Free Software Foundation, version 2.1
10
 * exclusively.
11
 *
12
 * This library is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15
 * Lesser General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU Lesser General Public
18
 * License along with this library; if not, write to the Free Software
19
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
20
 */
21
22
#ifndef _HAPROXY_HLUA_H
23
#define _HAPROXY_HLUA_H
24
25
#include <haproxy/hlua-t.h>
26
27
#ifdef USE_LUA
28
29
/* Lua uses longjmp to perform yield or throwing errors. This
30
 * macro is used only for identifying the function that can
31
 * not return because a longjmp is executed.
32
 *   __LJMP marks a prototype of hlua file that can use longjmp.
33
 *   WILL_LJMP() marks an lua function that will use longjmp.
34
 *   MAY_LJMP() marks an lua function that may use longjmp.
35
 */
36
#define __LJMP
37
#define WILL_LJMP(func) do { func; my_unreachable(); } while(0)
38
#define MAY_LJMP(func) func
39
40
/* The following macros are used to set flags. */
41
#define HLUA_SET_RUN(__hlua)         do {(__hlua)->flags |= HLUA_RUN;} while(0)
42
#define HLUA_CLR_RUN(__hlua)         do {(__hlua)->flags &= ~HLUA_RUN;} while(0)
43
#define HLUA_IS_RUNNING(__hlua)      ((__hlua)->flags & HLUA_RUN)
44
#define HLUA_SET_BUSY(__hlua)        do {(__hlua)->flags |= HLUA_BUSY;} while(0)
45
#define HLUA_CLR_BUSY(__hlua)        do {(__hlua)->flags &= ~HLUA_BUSY;} while(0)
46
#define HLUA_IS_BUSY(__hlua)         ((__hlua)->flags & HLUA_BUSY)
47
#define HLUA_SET_CTRLYIELD(__hlua)   do {(__hlua)->flags |= HLUA_CTRLYIELD;} while(0)
48
#define HLUA_CLR_CTRLYIELD(__hlua)   do {(__hlua)->flags &= ~HLUA_CTRLYIELD;} while(0)
49
#define HLUA_IS_CTRLYIELDING(__hlua) ((__hlua)->flags & HLUA_CTRLYIELD)
50
#define HLUA_SET_WAKERESWR(__hlua)   do {(__hlua)->flags |= HLUA_WAKERESWR;} while(0)
51
#define HLUA_CLR_WAKERESWR(__hlua)   do {(__hlua)->flags &= ~HLUA_WAKERESWR;} while(0)
52
#define HLUA_IS_WAKERESWR(__hlua)    ((__hlua)->flags & HLUA_WAKERESWR)
53
#define HLUA_SET_WAKEREQWR(__hlua)   do {(__hlua)->flags |= HLUA_WAKEREQWR;} while(0)
54
#define HLUA_CLR_WAKEREQWR(__hlua)   do {(__hlua)->flags &= ~HLUA_WAKEREQWR;} while(0)
55
#define HLUA_IS_WAKEREQWR(__hlua)    ((__hlua)->flags & HLUA_WAKEREQWR)
56
#define HLUA_CLR_NOYIELD(__hlua)     do {(__hlua)->flags &= ~HLUA_NOYIELD;} while(0)
57
#define HLUA_SET_NOYIELD(__hlua)     do {(__hlua)->flags |= HLUA_NOYIELD;} while(0)
58
#define HLUA_CANT_YIELD(__hlua)      ((__hlua)->flags & HLUA_NOYIELD)
59
60
61
#define HLUA_INIT(__hlua) do { (__hlua)->T = 0; } while(0)
62
63
/* Lua HAProxy integration functions. */
64
void hlua_yield_asap(lua_State *L);
65
void hap_register_hlua_state_init(int (*fct)(lua_State *L, char **errmsg));
66
67
/* simplified way to register a lua_State init callback from any file */
68
#define REGISTER_HLUA_STATE_INIT(fct) \
69
  INITCALL1(STG_REGISTER, hap_register_hlua_state_init, (fct))
70
const char *hlua_traceback(lua_State *L, const char* sep);
71
void hlua_ctx_destroy(struct hlua *lua);
72
void hlua_init();
73
int hlua_post_init();
74
void hlua_applet_tcp_fct(struct appctx *ctx);
75
void hlua_applet_http_fct(struct appctx *ctx);
76
int hlua_event_sub(lua_State *L, event_hdl_sub_list *sub_list);
77
struct task *hlua_process_task(struct task *task, void *context, unsigned int state);
78
const char *hlua_show_current_location(const char *pfx);
79
int hlua_ref(lua_State *L);
80
void hlua_pushref(lua_State *L, int ref);
81
void hlua_unref(lua_State *L, int ref);
82
struct hlua *hlua_gethlua(lua_State *L);
83
void hlua_yieldk(lua_State *L, int nresults, lua_KContext ctx, lua_KFunction k, int timeout, unsigned int flags);
84
int hlua_pusherror(lua_State *L, const char *fmt, ...);
85
86
__LJMP static inline void hlua_check_args(lua_State *L, int nb, char *fcn)
87
{
88
  if (lua_gettop(L) == nb)
89
    return;
90
  WILL_LJMP(luaL_error(L, "'%s' needs %d arguments", fcn, nb));
91
}
92
#define check_args hlua_check_args
93
94
#else /* USE_LUA */
95
96
/************************ For use when Lua is disabled ********************/
97
98
#define HLUA_IS_RUNNING(__hlua) 0
99
100
#define HLUA_INIT(__hlua)
101
102
/* Empty function for compilation without Lua. */
103
0
static inline void hlua_init() { }
Unexecuted instantiation: tools.c:hlua_init
Unexecuted instantiation: debug.c:hlua_init
Unexecuted instantiation: haproxy.c:hlua_init
Unexecuted instantiation: stream.c:hlua_init
104
0
static inline int hlua_post_init() { return 1; }
Unexecuted instantiation: tools.c:hlua_post_init
Unexecuted instantiation: debug.c:hlua_post_init
Unexecuted instantiation: haproxy.c:hlua_post_init
Unexecuted instantiation: stream.c:hlua_post_init
105
0
static inline void hlua_ctx_destroy(struct hlua *lua) { }
Unexecuted instantiation: tools.c:hlua_ctx_destroy
Unexecuted instantiation: debug.c:hlua_ctx_destroy
Unexecuted instantiation: haproxy.c:hlua_ctx_destroy
Unexecuted instantiation: stream.c:hlua_ctx_destroy
106
0
static inline const char *hlua_show_current_location(const char *pfx) { return NULL; }
Unexecuted instantiation: tools.c:hlua_show_current_location
Unexecuted instantiation: debug.c:hlua_show_current_location
Unexecuted instantiation: haproxy.c:hlua_show_current_location
Unexecuted instantiation: stream.c:hlua_show_current_location
107
108
#endif /* USE_LUA */
109
110
#endif /* _HAPROXY_HLUA_H */