mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-09-22 14:21:25 +02:00
MINOR: lua: core: create "core" class and object
This object provides main HAProxy functions. This first version creates an empty object. It will be enhanced later.
This commit is contained in:
parent
6c9b52cbc2
commit
2ba18a2aa6
@ -3,6 +3,8 @@
|
|||||||
|
|
||||||
#include <lua.h>
|
#include <lua.h>
|
||||||
|
|
||||||
|
#define CLASS_CORE "Core"
|
||||||
|
|
||||||
enum hlua_state {
|
enum hlua_state {
|
||||||
HLUA_STOP = 0,
|
HLUA_STOP = 0,
|
||||||
HLUA_RUN,
|
HLUA_RUN,
|
||||||
|
@ -33,6 +33,8 @@
|
|||||||
#define SYSLOG_PORT 514
|
#define SYSLOG_PORT 514
|
||||||
#define UNIQUEID_LEN 128
|
#define UNIQUEID_LEN 128
|
||||||
|
|
||||||
|
/* The array containing the names of the log levels. */
|
||||||
|
extern const char *log_levels[];
|
||||||
|
|
||||||
/* lists of fields that can be logged */
|
/* lists of fields that can be logged */
|
||||||
enum {
|
enum {
|
||||||
|
43
src/hlua.c
43
src/hlua.c
@ -36,6 +36,12 @@ struct pool_head *pool2_hlua_com;
|
|||||||
*/
|
*/
|
||||||
struct eb_root hlua_ctx = EB_ROOT_UNIQUE;
|
struct eb_root hlua_ctx = EB_ROOT_UNIQUE;
|
||||||
|
|
||||||
|
/* The following variables contains the reference of the different
|
||||||
|
* Lua classes. These references are useful for identify metadata
|
||||||
|
* associated with an object.
|
||||||
|
*/
|
||||||
|
static int class_core_ref;
|
||||||
|
|
||||||
/* Used to check an Lua function type in the stack. It creates and
|
/* Used to check an Lua function type in the stack. It creates and
|
||||||
* returns a reference of the function. This function throws an
|
* returns a reference of the function. This function throws an
|
||||||
* error if the rgument is not a "function".
|
* error if the rgument is not a "function".
|
||||||
@ -490,6 +496,8 @@ static struct cfg_kw_list cfg_kws = {{ },{
|
|||||||
|
|
||||||
void hlua_init(void)
|
void hlua_init(void)
|
||||||
{
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
/* Initialise com signals pool session. */
|
/* Initialise com signals pool session. */
|
||||||
pool2_hlua_com = create_pool("hlua_com", sizeof(struct hlua_com), MEM_F_SHARED);
|
pool2_hlua_com = create_pool("hlua_com", sizeof(struct hlua_com), MEM_F_SHARED);
|
||||||
|
|
||||||
@ -507,4 +515,39 @@ void hlua_init(void)
|
|||||||
|
|
||||||
/* Initialise lua. */
|
/* Initialise lua. */
|
||||||
luaL_openlibs(gL.T);
|
luaL_openlibs(gL.T);
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* Create "core" object.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* This integer entry is just used as base value for the object "core". */
|
||||||
|
lua_pushinteger(gL.T, 0);
|
||||||
|
|
||||||
|
/* Create and fill the metatable. */
|
||||||
|
lua_newtable(gL.T);
|
||||||
|
|
||||||
|
/* Create and fill the __index entry. */
|
||||||
|
lua_pushstring(gL.T, "__index");
|
||||||
|
lua_newtable(gL.T);
|
||||||
|
|
||||||
|
/* Push the loglevel constants. */
|
||||||
|
for (i=0; i<NB_LOG_LEVELS; i++)
|
||||||
|
hlua_class_const_int(gL.T, log_levels[i], i);
|
||||||
|
|
||||||
|
/* Store the table __index in the metable. */
|
||||||
|
lua_settable(gL.T, -3);
|
||||||
|
|
||||||
|
/* Register previous table in the registry with named entry. */
|
||||||
|
lua_pushvalue(gL.T, -1); /* Copy the -1 entry and push it on the stack. */
|
||||||
|
lua_setfield(gL.T, LUA_REGISTRYINDEX, CLASS_CORE); /* register class session. */
|
||||||
|
|
||||||
|
/* Register previous table in the registry with reference. */
|
||||||
|
lua_pushvalue(gL.T, -1); /* Copy the -1 entry and push it on the stack. */
|
||||||
|
class_core_ref = luaL_ref(gL.T, LUA_REGISTRYINDEX); /* reference class session. */
|
||||||
|
|
||||||
|
/* Create new object with class Core. */
|
||||||
|
lua_setmetatable(gL.T, -2);
|
||||||
|
lua_setglobal(gL.T, "core");
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user