Thierry FOURNIER | 6f1fd48 | 2015-01-23 14:06:13 +0100 | [diff] [blame] | 1 | #ifndef _TYPES_HLUA_H |
| 2 | #define _TYPES_HLUA_H |
| 3 | |
| 4 | #include <lua.h> |
| 5 | |
Thierry FOURNIER | 2ba18a2 | 2015-01-23 14:07:08 +0100 | [diff] [blame] | 6 | #define CLASS_CORE "Core" |
Thierry FOURNIER | 65f34c6 | 2015-02-16 20:11:43 +0100 | [diff] [blame] | 7 | #define CLASS_TXN "TXN" |
| 8 | |
| 9 | struct session; |
Thierry FOURNIER | 2ba18a2 | 2015-01-23 14:07:08 +0100 | [diff] [blame] | 10 | |
Thierry FOURNIER | 380d093 | 2015-01-23 14:27:52 +0100 | [diff] [blame] | 11 | enum hlua_state { |
| 12 | HLUA_STOP = 0, |
| 13 | HLUA_RUN, |
| 14 | }; |
| 15 | |
| 16 | enum 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 | |
| 25 | struct 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 FOURNIER | 9ff7e6e | 2015-01-23 11:08:20 +0100 | [diff] [blame] | 35 | struct list com; /* The list head of the signals attached to this task. */ |
Thierry FOURNIER | 380d093 | 2015-01-23 14:27:52 +0100 | [diff] [blame] | 36 | struct ebpt_node node; |
| 37 | }; |
| 38 | |
Thierry FOURNIER | 9ff7e6e | 2015-01-23 11:08:20 +0100 | [diff] [blame] | 39 | struct 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 FOURNIER | a4a0f3d | 2015-01-23 12:08:30 +0100 | [diff] [blame] | 47 | /* This is a part of the list containing references to functions |
| 48 | * called at the initialisation time. |
| 49 | */ |
| 50 | struct hlua_init_function { |
| 51 | struct list l; |
| 52 | int function_ref; |
| 53 | }; |
| 54 | |
Thierry FOURNIER | 65f34c6 | 2015-02-16 20:11:43 +0100 | [diff] [blame] | 55 | /* This struct contains the pointer provided on the most |
| 56 | * of internal HAProxy calls during the processing of |
| 57 | * rules, converters and sample-fetches. This struct is |
| 58 | * associated with the lua object called "TXN". |
| 59 | */ |
| 60 | struct hlua_txn { |
| 61 | struct session *s; |
| 62 | struct proxy *p; |
| 63 | void *l7; |
| 64 | }; |
| 65 | |
Thierry FOURNIER | d0fa538 | 2015-02-16 20:14:51 +0100 | [diff] [blame] | 66 | /* This struct is used as a closure argument associated |
| 67 | * with dynamic sample-fetch created fucntions. This contains |
| 68 | * a pointer to the original sample_fetch struct. It is used |
| 69 | * to identify the function to execute with the sample fetch |
| 70 | * wrapper. |
| 71 | */ |
| 72 | struct hlua_sample_fetch { |
| 73 | struct sample_fetch *f; |
| 74 | }; |
| 75 | |
Thierry FOURNIER | 6f1fd48 | 2015-01-23 14:06:13 +0100 | [diff] [blame] | 76 | #endif /* _TYPES_HLUA_H */ |