From fda5ca3472a91afb7169339700936dc982bd21f9 Mon Sep 17 00:00:00 2001 From: Aurelien DARRAGON Date: Thu, 21 Nov 2024 16:46:26 +0100 Subject: [PATCH] MINOR: hlua_fcn: add Patref:purge() method It is a special Lua Patref method: it bypasses the commit/prepare logic and purges the whole pattern reference items pointed to by Patref Lua object (all versions, not just the current one). It doesn't have a cli equivalent: it leverages pat_ref_purge_range(). --- doc/lua-api/index.rst | 5 +++++ src/hlua_fcn.c | 13 +++++++++++++ 2 files changed, 18 insertions(+) diff --git a/doc/lua-api/index.rst b/doc/lua-api/index.rst index c903fe1de..db594c5cc 100644 --- a/doc/lua-api/index.rst +++ b/doc/lua-api/index.rst @@ -3456,6 +3456,11 @@ Patref class :returns: true if the pattern reference is used to handle maps instead of acl, false otherwise. +.. js:function:: Patref.purge(ref) + + Completely prune all pattern reference entries pointed to by Patref object. + This special operation doesn't require committing. + .. js:function:: Patref.prepare(ref) Create a new empty version for Patref Object. It can be used to manipulate diff --git a/src/hlua_fcn.c b/src/hlua_fcn.c index f2336bd1e..49219e26a 100644 --- a/src/hlua_fcn.c +++ b/src/hlua_fcn.c @@ -2705,6 +2705,18 @@ int hlua_patref_prepare(lua_State *L) return 0; } +int hlua_patref_purge(lua_State *L) +{ + struct hlua_patref *ref; + + ref = hlua_checkudata(L, 1, class_patref_ref); + BUG_ON(!ref); + + lua_pushinteger(L, 0); // from + lua_pushinteger(L, ~0); // to + return _hlua_patref_clear(L, LUA_OK, 0); +} + void hlua_fcn_new_patref(lua_State *L, struct pat_ref *ref) { struct hlua_patref *_ref; @@ -2734,6 +2746,7 @@ void hlua_fcn_new_patref(lua_State *L, struct pat_ref *ref) hlua_class_function(L, "is_map", hlua_patref_is_map); hlua_class_function(L, "prepare", hlua_patref_prepare); hlua_class_function(L, "commit", hlua_patref_commit); + hlua_class_function(L, "purge", hlua_patref_purge); } int hlua_patref_gc(lua_State *L)