diff --git a/src/lua/trigger.cc b/src/lua/trigger.cc index 558c9d759f8311822b50c2674eccd85914248f29..fb05ba1b4a666de8b9eaf4e1740d0372ff57a9c2 100644 --- a/src/lua/trigger.cc +++ b/src/lua/trigger.cc @@ -66,7 +66,7 @@ lbox_list_all_triggers(struct lua_State *L, struct rlist *list) lua_newtable(L); rlist_foreach_entry_reverse(trigger, list, link) { lua_rawgeti(L, LUA_REGISTRYINDEX, (intptr_t) trigger->data); - if (! lua_isnil(L, -1)) { + if (lua_isfunction(L, -1)) { lua_rawseti(L, -2, count); count++; } else { diff --git a/test/box/on_replace.result b/test/box/on_replace.result index 8b7b5d33311cf8aed8a7a84ccef53bc5a5bbb91b..f431ebb5c4cdc0068d9e8cc4f8aa07b5b640a6d8 100644 --- a/test/box/on_replace.result +++ b/test/box/on_replace.result @@ -1,3 +1,19 @@ +-- test c and lua triggers: must return only lua triggers +#box.space._space:on_replace() +--- +- 0 +... +function f() print('test') end +--- +... +type(box.space._space:on_replace(f)) +--- +- function +... +#box.space._space:on_replace() +--- +- 1 +... ts = box.schema.space.create('test_space') --- ... @@ -101,3 +117,19 @@ type(ts:on_replace(function() test = 1 end)) ts:drop() --- ... +-- test garbage in lua stack +#box.space._space:on_replace() +--- +- 1 +... +function f2() print('test2') end +--- +... +type(box.space._space:on_replace(f2)) +--- +- function +... +#box.space._space:on_replace() +--- +- 2 +... diff --git a/test/box/on_replace.test.lua b/test/box/on_replace.test.lua index c67c86928748303ff98867463ea6e6b0813222a0..d3c6565a340a420d371b9a6b3803766fae2e9ba1 100644 --- a/test/box/on_replace.test.lua +++ b/test/box/on_replace.test.lua @@ -1,6 +1,11 @@ +-- test c and lua triggers: must return only lua triggers +#box.space._space:on_replace() +function f() print('test') end +type(box.space._space:on_replace(f)) +#box.space._space:on_replace() + ts = box.schema.space.create('test_space') ti = ts:create_index('primary', { type = 'hash' }) - type(ts.on_replace) ts.on_replace() ts:on_replace() @@ -25,7 +30,6 @@ ts:get{2} function save_out(told, tnew) o = told n = tnew end type(ts:on_replace(save_out, fail)) - ts:insert{2, 'a', 'b', 'c'} o n @@ -37,3 +41,9 @@ n type(ts:on_replace(function() test = 1 end)) #ts:on_replace() ts:drop() + +-- test garbage in lua stack +#box.space._space:on_replace() +function f2() print('test2') end +type(box.space._space:on_replace(f2)) +#box.space._space:on_replace()