blob: a4d14442bdec63340002cdb8949491ef198d390c [file] [log] [blame]
Thierry FOURNIER6f1fd482015-01-23 14:06:13 +01001#ifndef _TYPES_HLUA_H
2#define _TYPES_HLUA_H
3
4#include <lua.h>
5
Thierry FOURNIER2ba18a22015-01-23 14:07:08 +01006#define CLASS_CORE "Core"
Thierry FOURNIER65f34c62015-02-16 20:11:43 +01007#define CLASS_TXN "TXN"
8
9struct session;
Thierry FOURNIER2ba18a22015-01-23 14:07:08 +010010
Thierry FOURNIER380d0932015-01-23 14:27:52 +010011enum hlua_state {
12 HLUA_STOP = 0,
13 HLUA_RUN,
14};
15
16enum hlua_exec {
17 HLUA_E_OK = 0,
18 HLUA_E_AGAIN, /* LUA yield, must resume the stack execution later, when
19 the associatedtask is waked. */
20 HLUA_E_ERRMSG, /* LUA stack execution failed with a string error message
21 in the top of stack. */
22 HLUA_E_ERR, /* LUA stack execution failed without error message. */
23};
24
25struct hlua {
26 lua_State *T; /* The LUA stack. */
27 int Tref; /* The reference of the stack in coroutine case.
28 -1 for the main lua stack. */
29 int Mref; /* The reference of the memory context in coroutine case.
30 -1 if the memory context is not used. */
31 int nargs; /* The number of arguments in the stack at the start of execution. */
32 enum hlua_state state; /* The current execution state. */
33 struct task *task; /* The task associated with the lua stack execution.
34 We must wake this task to continue the task execution */
Thierry FOURNIER9ff7e6e2015-01-23 11:08:20 +010035 struct list com; /* The list head of the signals attached to this task. */
Thierry FOURNIER380d0932015-01-23 14:27:52 +010036 struct ebpt_node node;
37};
38
Thierry FOURNIER9ff7e6e2015-01-23 11:08:20 +010039struct hlua_com {
40 struct list purge_me; /* Part of the list of signals to be purged in the
41 case of the LUA execution stack crash. */
42 struct list wake_me; /* Part of list of signals to be targeted if an
43 event occurs. */
44 struct task *task; /* The task to be wake if an event occurs. */
45};
46
Thierry FOURNIERa4a0f3d2015-01-23 12:08:30 +010047/* This is a part of the list containing references to functions
48 * called at the initialisation time.
49 */
50struct hlua_init_function {
51 struct list l;
52 int function_ref;
53};
54
Thierry FOURNIERfa0e5dd2015-02-16 20:19:18 +010055/* This struct contains the lua data used to bind
56 * Lua function on HAProxy hook like sample-fetches
57 * or actions.
58 */
59struct hlua_function {
60 char *name;
61 int function_ref;
62};
63
Thierry FOURNIER65f34c62015-02-16 20:11:43 +010064/* This struct contains the pointer provided on the most
65 * of internal HAProxy calls during the processing of
66 * rules, converters and sample-fetches. This struct is
67 * associated with the lua object called "TXN".
68 */
69struct hlua_txn {
70 struct session *s;
71 struct proxy *p;
72 void *l7;
73};
74
Thierry FOURNIERd0fa5382015-02-16 20:14:51 +010075/* This struct is used as a closure argument associated
76 * with dynamic sample-fetch created fucntions. This contains
77 * a pointer to the original sample_fetch struct. It is used
78 * to identify the function to execute with the sample fetch
79 * wrapper.
80 */
81struct hlua_sample_fetch {
82 struct sample_fetch *f;
83};
84
Thierry FOURNIER6f1fd482015-01-23 14:06:13 +010085#endif /* _TYPES_HLUA_H */