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.
This commit is contained in:
Aurelien DARRAGON 2024-11-21 16:32:05 +01:00
parent 8bce7ff854
commit fe394598c5
2 changed files with 20 additions and 0 deletions

View File

@ -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

View File

@ -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);
}