mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-09-20 21:31:28 +02:00
MINOR: hlua: add patref class
Implement patref class to expose pat_ref struct internal pattern struct in lua. This is some prerequisite work needed to be able to manipulate exisiting generic pattern object lists (acl/map) from Lua, because the Map class can only be used to perform matching ops on Map files.
This commit is contained in:
parent
f72a66eef2
commit
956a25cf60
@ -36,6 +36,7 @@
|
||||
#include <haproxy/stick_table-t.h>
|
||||
#include <haproxy/xref-t.h>
|
||||
#include <haproxy/event_hdl-t.h>
|
||||
#include <haproxy/pattern-t.h>
|
||||
|
||||
#define CLASS_CORE "Core"
|
||||
#define CLASS_TXN "TXN"
|
||||
@ -53,6 +54,7 @@
|
||||
#define CLASS_SERVER "Server"
|
||||
#define CLASS_LISTENER "Listener"
|
||||
#define CLASS_EVENT_SUB "EventSub"
|
||||
#define CLASS_PATREF "Patref"
|
||||
#define CLASS_REGEX "Regex"
|
||||
#define CLASS_STKTABLE "StickTable"
|
||||
#define CLASS_CERTCACHE "CertCache"
|
||||
|
@ -37,5 +37,6 @@ int hlua_dump_object(lua_State *L);
|
||||
int hlua_fcn_new_proxy(lua_State *L, struct proxy *px);
|
||||
int hlua_fcn_new_server(lua_State *L, struct server *srv);
|
||||
int hlua_fcn_new_event_sub(lua_State *L, struct event_hdl_sub *sub);
|
||||
void hlua_fcn_new_patref(lua_State *L, struct pat_ref *ref);
|
||||
|
||||
#endif /* _HAPROXY_HLUA_FCN_H */
|
||||
|
@ -49,6 +49,7 @@ static int class_proxy_ref;
|
||||
static int class_server_ref;
|
||||
static int class_listener_ref;
|
||||
static int class_event_sub_ref;
|
||||
static int class_patref_ref;
|
||||
static int class_regex_ref;
|
||||
static int class_stktable_ref;
|
||||
static int class_proxy_list_ref;
|
||||
@ -2617,6 +2618,36 @@ static int hlua_regex_free(struct lua_State *L)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int hlua_patref_get_name(lua_State *L)
|
||||
{
|
||||
struct pat_ref *ref;
|
||||
|
||||
ref = hlua_checkudata(L, 1, class_patref_ref);
|
||||
BUG_ON(!ref);
|
||||
|
||||
lua_pushstring(L, ref->reference);
|
||||
return 1;
|
||||
}
|
||||
|
||||
void hlua_fcn_new_patref(lua_State *L, struct pat_ref *ref)
|
||||
{
|
||||
lua_newtable(L);
|
||||
|
||||
/* Pop a class patref metatable and affect it to the userdata
|
||||
* (if provided)
|
||||
*/
|
||||
lua_rawgeti(L, LUA_REGISTRYINDEX, class_patref_ref);
|
||||
lua_setmetatable(L, -2);
|
||||
|
||||
if (ref) {
|
||||
lua_pushlightuserdata(L, ref);
|
||||
lua_rawseti(L, -2, 0);
|
||||
}
|
||||
|
||||
/* set public methods */
|
||||
hlua_class_function(L, "get_name", hlua_patref_get_name);
|
||||
}
|
||||
|
||||
void hlua_fcn_reg_core_fcn(lua_State *L)
|
||||
{
|
||||
hlua_concat_init(L);
|
||||
@ -2675,6 +2706,10 @@ void hlua_fcn_reg_core_fcn(lua_State *L)
|
||||
hlua_class_function(L, "__gc", hlua_event_sub_gc);
|
||||
class_event_sub_ref = hlua_register_metatable(L, CLASS_EVENT_SUB);
|
||||
|
||||
/* Create patref object. */
|
||||
lua_newtable(L);
|
||||
class_patref_ref = hlua_register_metatable(L, CLASS_PATREF);
|
||||
|
||||
/* Create server object. */
|
||||
lua_newtable(L);
|
||||
hlua_class_function(L, "__gc", hlua_server_gc);
|
||||
|
Loading…
x
Reference in New Issue
Block a user