From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Date: Fri, 17 Aug 2018 18:15:36 +0300 From: Vladimir Davydov Subject: Re: [tarantool-patches] Re: [PATCH 1/1] box: expose on_commit/rollback triggers for Lua Message-ID: <20180817151536.qbb4pwgdagnd367t@esperanza> References: <6aff0ac07499e8d43a0b8cd64edbe1c40a31cbff.1534441147.git.v.shpilevoy@tarantool.org> <20180817112128.cg4wyh6vtnwxx4lc@esperanza> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: To: Vladislav Shpilevoy Cc: tarantool-patches@freelists.org List-ID: On Fri, Aug 17, 2018 at 05:45:24PM +0300, Vladislav Shpilevoy wrote: > Hi! Thanks for the review. > > On 17/08/2018 14:21, Vladimir Davydov wrote: > > On Thu, Aug 16, 2018 at 08:57:10PM +0300, Vladislav Shpilevoy wrote: > > > +/** > > > + * Update the transaction on_commit/rollback triggers. > > > + * @sa lbox_trigger_reset. > > > + */ > > > +#define lbox_on_txn_end(name) do { \ > > > + struct txn *txn = in_txn(); \ > > > + int top = lua_gettop(L); \ > > > + if (top > 2 || txn == NULL) { \ > > > + return luaL_error(L, "Usage inside a transaction: " \ > > > + "box.on_" #name "([function | nil, " \ > > > + "[function | nil]])"); \ > > > + } \ > > > + txn_init_triggers(txn); \ > > > + return lbox_trigger_reset(L, 2, &txn->on_##name, lbox_push_txn, NULL); \ > > > +} while (0) > > > + > > > +static int > > > +lbox_on_commit(struct lua_State *L) > > > +{ > > > + lbox_on_txn_end(commit); > > > +} > > > + > > > +static int > > > +lbox_on_rollback(struct lua_State *L) > > > +{ > > > + lbox_on_txn_end(rollback); > > > +} > > > + > > > > This is nit-picking, but IMHO better define the whole function > > in a macro. > > > > #define LBOX_TXN_TRIGGER(name) \ > > static int \ > > lbox_on_##name(struct lua_State *L) \ > > ... > > > > LBOX_TXN_TRIGGER(commit) > > LBOX_TXN_TRIGGER(rollback) > > > > Other than that the patch looks good to me. > > > > Fixed. ACK for 9a8da517177a1b2609615252b7cec4348145b543 box: expose on_commit/rollback triggers for Lua