From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Date: Mon, 24 Jun 2019 15:38:05 +0300 From: Vladimir Davydov Subject: Re: [PATCH v4 6/6] box: introduce Lua persistent functions Message-ID: <20190624123805.35oxjrmyhzwro2wd@esperanza> References: <47082b6bbc04a389a3c82ac27174bcdef81de2ce.1561298197.git.kshcherbatov@tarantool.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <47082b6bbc04a389a3c82ac27174bcdef81de2ce.1561298197.git.kshcherbatov@tarantool.org> To: Kirill Shcherbatov Cc: tarantool-patches@freelists.org List-ID: On Sun, Jun 23, 2019 at 04:57:57PM +0300, Kirill Shcherbatov wrote: > diff --git a/src/box/lua/call.c b/src/box/lua/call.c > index f98ab42ac..d3d874477 100644 > --- a/src/box/lua/call.c > +++ b/src/box/lua/call.c > @@ -669,6 +870,22 @@ lbox_func_new(struct lua_State *L, struct func *func) > lua_pushstring(L, "language"); > lua_pushstring(L, func_language_strs[func->def->language]); > lua_settable(L, top); > + lua_pushstring(L, "is_deterministic"); > + lua_pushboolean(L, func->def->is_deterministic); > + lua_settable(L, top); > + if (func->def->body != NULL) { > + lua_pushstring(L, "body"); > + lua_pushstring(L, func->def->body); > + lua_settable(L, top); > + lua_pushstring(L, "is_sandboxed"); > + lua_pushboolean(L, func->def->is_sandboxed); > + lua_settable(L, top); > + } > + if (func->def->comment != NULL) { > + lua_pushstring(L, "comment"); > + lua_pushstring(L, func->def->comment); > + lua_settable(L, top); > + } We must delete 'body' and 'is_sandboxed' in case the function isn't persistent, otherwise it might inherit old values. > diff --git a/src/box/lua/schema.lua b/src/box/lua/schema.lua > index 9c3ee063c..455d1e18a 100644 > --- a/src/box/lua/schema.lua > +++ b/src/box/lua/schema.lua > @@ -2138,7 +2138,10 @@ box.schema.func.create = function(name, opts) > opts = opts or {} > check_param_table(opts, { setuid = 'boolean', > if_not_exists = 'boolean', > - language = 'string'}) > + language = 'string', body = 'string', > + is_deterministic = 'boolean', > + is_sandboxed = 'boolean', opts = 'table', opts = 'table' not needed, apparently. Pushed to master with the following changes: diff --git a/src/box/lua/call.c b/src/box/lua/call.c index d50e23bf..88110c43 100644 --- a/src/box/lua/call.c +++ b/src/box/lua/call.c @@ -868,22 +868,27 @@ lbox_func_new(struct lua_State *L, struct func *func) lua_pushstring(L, "language"); lua_pushstring(L, func_language_strs[func->def->language]); lua_settable(L, top); + lua_pushstring(L, "body"); + if (func->def->body != NULL) + lua_pushstring(L, func->def->body); + else + lua_pushnil(L); + lua_settable(L, top); + lua_pushstring(L, "comment"); + if (func->def->comment != NULL) + lua_pushstring(L, func->def->comment); + else + lua_pushnil(L); + lua_settable(L, top); lua_pushstring(L, "is_deterministic"); lua_pushboolean(L, func->def->is_deterministic); lua_settable(L, top); - if (func->def->body != NULL) { - lua_pushstring(L, "body"); - lua_pushstring(L, func->def->body); - lua_settable(L, top); - lua_pushstring(L, "is_sandboxed"); + lua_pushstring(L, "is_sandboxed"); + if (func->def->body != NULL) lua_pushboolean(L, func->def->is_sandboxed); - lua_settable(L, top); - } - if (func->def->comment != NULL) { - lua_pushstring(L, "comment"); - lua_pushstring(L, func->def->comment); - lua_settable(L, top); - } + else + lua_pushnil(L); + lua_settable(L, top); /* Bless func object. */ lua_getfield(L, LUA_GLOBALSINDEX, "box"); diff --git a/src/box/lua/schema.lua b/src/box/lua/schema.lua index 455d1e18..1ab97440 100644 --- a/src/box/lua/schema.lua +++ b/src/box/lua/schema.lua @@ -2140,8 +2140,8 @@ box.schema.func.create = function(name, opts) if_not_exists = 'boolean', language = 'string', body = 'string', is_deterministic = 'boolean', - is_sandboxed = 'boolean', opts = 'table', - comment = 'string'}) + is_sandboxed = 'boolean', + comment = 'string' }) local _func = box.space[box.schema.FUNC_ID] local _vfunc = box.space[box.schema.VFUNC_ID] local func = _vfunc.index.name:get{name} diff --git a/test/box/function1.result b/test/box/function1.result index 969798ea..7bea2d64 100644 --- a/test/box/function1.result +++ b/test/box/function1.result @@ -448,7 +448,6 @@ func - is_deterministic: false id: 2 setuid: false - comment: Divide two values name: function1.divide language: C ...