diff --git a/core/tarantool_lua.m b/core/tarantool_lua.m index 2a55b9abb555ad7adfdafcdc620899866f8906c4..663e2cfeb5a07fe2991e8fb78360774960a83112 100644 --- a/core/tarantool_lua.m +++ b/core/tarantool_lua.m @@ -136,6 +136,7 @@ static char format_to_opcode(char format) case '|': return 4; case ':': return 5; case '#': return 6; + case '!': return 7; default: return format; } } @@ -231,7 +232,8 @@ lbox_pack(struct lua_State *L) case '|': /* set field|=val */ case '^': /* set field^=val */ case ':': /* splice */ - case '#': /* splice */ + case '#': /* delete field */ + case '!': /* insert field */ u32buf= (u32) lua_tointeger(L, i); /* field no */ luaL_addlstring(&b, (char *) &u32buf, sizeof(u32)); luaL_addchar(&b, format_to_opcode(*format)); diff --git a/test/box/lua.result b/test/box/lua.result index 5b943038c82da41c41a7140e38770becfcad4cd2..b4a0d10173f2cecd74c5f506d639d6960526254e 100644 --- a/test/box/lua.result +++ b/test/box/lua.result @@ -966,3 +966,22 @@ error: 'UPDATE error: the new tuple has no fields' lua box.space[0]:truncate() --- ... + +# test box.update: insert fieled + +lua box.insert(0, 1, 3, 6, 9) +--- + - 1: {3, 6, 9} +... +lua box.update(0, 1, '!p', 1, 2) +--- + - 1: {2, 3, 6, 9} +... +lua box.update(0, 1, '!p!p!p!p', 3, 4, 3, 5, 4, 7, 4, 8) +--- + - 1: {2, 3, 4, 5, 6, 7, 8, 9} +... +lua box.update(0, 1, '!p!p!p', 9, 10, 9, 11, 9, 12) +--- + - 1: {2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12} +... diff --git a/test/box/lua.test b/test/box/lua.test index 3b78c27bfcc11a67ba43c11744cf557145e5e034..7b6e4a197b21441e6630177821b5907dafc01ee1 100644 --- a/test/box/lua.test +++ b/test/box/lua.test @@ -297,3 +297,11 @@ exec sql "call box.update(0, 'tes3', '#p', 0, '')" exec sql "call box.update(0, 'tes4', '#p', 0, '')" exec admin "lua box.update(0, 'tes5', '#p', 0, '')" exec admin "lua box.space[0]:truncate()" + +print """ +# test box.update: insert fieled +""" +exec admin "lua box.insert(0, 1, 3, 6, 9)" +exec admin "lua box.update(0, 1, '!p', 1, 2)" +exec admin "lua box.update(0, 1, '!p!p!p!p', 3, 4, 3, 5, 4, 7, 4, 8)" +exec admin "lua box.update(0, 1, '!p!p!p', 9, 10, 9, 11, 9, 12)"