From fe394598c5d690897b5e6595d289fe62499a7fa9 Mon Sep 17 00:00:00 2001 From: Aurelien DARRAGON Date: Thu, 21 Nov 2024 16:32:05 +0100 Subject: [PATCH] MINOR: hlua_fcn: add Patref:prepare() method Just like the "prepare map" or "prepare acl" on the cli, but for Lua: it leverages the pattern API to create a subset (ie: a new generation id) that will automatically be used as target for following Patref operations (add/set/del...) until the "commit" method is invoked to atomically push the pending updates. --- doc/lua-api/index.rst | 8 ++++++++ src/hlua_fcn.c | 12 ++++++++++++ 2 files changed, 20 insertions(+) diff --git a/doc/lua-api/index.rst b/doc/lua-api/index.rst index f9d629d0f..c903fe1de 100644 --- a/doc/lua-api/index.rst +++ b/doc/lua-api/index.rst @@ -3456,6 +3456,12 @@ Patref class :returns: true if the pattern reference is used to handle maps instead of acl, false otherwise. +.. js:function:: Patref.prepare(ref) + + Create a new empty version for Patref Object. It can be used to manipulate + the Patref object with update methods without applying the updates until the + commit() method is called. + .. js:function:: Patref.commit(ref) Tries to commit pending Patref object updates, that is updates made to the @@ -3467,6 +3473,8 @@ Patref class :returns: true on success and nil on failure (followed by an error message). + See :js:func:`Patref.prepare()` + .. _applethttp_class: AppletHTTP class diff --git a/src/hlua_fcn.c b/src/hlua_fcn.c index 573f18ec2..f2336bd1e 100644 --- a/src/hlua_fcn.c +++ b/src/hlua_fcn.c @@ -2694,6 +2694,17 @@ int hlua_patref_commit(lua_State *L) return _hlua_patref_clear(L, LUA_OK, 0); } +int hlua_patref_prepare(lua_State *L) +{ + struct hlua_patref *ref; + + ref = hlua_checkudata(L, 1, class_patref_ref); + BUG_ON(!ref); + ref->curr_gen = pat_ref_newgen(ref->ptr); + ref->flags |= HLUA_PATREF_FL_GEN; + return 0; +} + void hlua_fcn_new_patref(lua_State *L, struct pat_ref *ref) { struct hlua_patref *_ref; @@ -2721,6 +2732,7 @@ void hlua_fcn_new_patref(lua_State *L, struct pat_ref *ref) /* set public methods */ hlua_class_function(L, "get_name", hlua_patref_get_name); 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); }