diff --git a/src/box/lua/call.c b/src/box/lua/call.c index c970d64e97748861d8bb7bc153571ba3a9fc6e41..e4d4947b8761fcc02e30656fadf4410a3838ad2f 100644 --- a/src/box/lua/call.c +++ b/src/box/lua/call.c @@ -60,7 +60,7 @@ box_lua_find(lua_State *L, const char *name, const char *name_end) if (! lua_istable(L, -1)) { diag_set(ClientError, ER_NO_SUCH_PROC, name_end - name, name); - lbox_error(L); + luaT_error(L); } start = end + 1; /* next piece of a.b.c */ index = lua_gettop(L); /* top of the stack */ @@ -75,7 +75,7 @@ box_lua_find(lua_State *L, const char *name, const char *name_end) lua_islightuserdata(L, -1) || lua_isuserdata(L, -1) )) { diag_set(ClientError, ER_NO_SUCH_PROC, name_end - name, name); - lbox_error(L); + luaT_error(L); } start = end + 1; /* next piece of a.b.c */ index = lua_gettop(L); /* top of the stack */ @@ -90,7 +90,7 @@ box_lua_find(lua_State *L, const char *name, const char *name_end) * for us, but our own message is more verbose. */ diag_set(ClientError, ER_NO_SUCH_PROC, name_end - name, name); - lbox_error(L); + luaT_error(L); } /* setting stack that it would contain only * the function pointer. */ @@ -146,7 +146,7 @@ luamp_encode_call(lua_State *L, struct luaL_serializer *cfg, luaL_tofield(L, cfg, i, &field); struct tuple *tuple; if (field.type == MP_EXT && - (tuple = lua_istuple(L, i)) != NULL) { + (tuple = luaT_istuple(L, i)) != NULL) { /* `return ..., box.tuple.new(...), ...` */ tuple_to_mpstream(tuple, stream); } else if (field.type != MP_ARRAY) { @@ -173,7 +173,7 @@ luamp_encode_call(lua_State *L, struct luaL_serializer *cfg, struct luaL_field root; luaL_tofield(L, cfg, 1, &root); struct tuple *tuple; - if (root.type == MP_EXT && (tuple = lua_istuple(L, 1)) != NULL) { + if (root.type == MP_EXT && (tuple = luaT_istuple(L, 1)) != NULL) { /* `return box.tuple()` */ tuple_to_mpstream(tuple, stream); return 1; @@ -201,7 +201,7 @@ luamp_encode_call(lua_State *L, struct luaL_serializer *cfg, lua_rawgeti(L, 1, t); struct luaL_field field; luaL_tofield(L, cfg, -1, &field); - if (field.type == MP_EXT && (tuple = lua_istuple(L, -1))) { + if (field.type == MP_EXT && (tuple = luaT_istuple(L, -1))) { tuple_to_mpstream(tuple, stream); } else if (field.type != MP_ARRAY) { /* The first member of root table is not tuple/array */ @@ -302,7 +302,7 @@ execute_lua_call(lua_State *L) */ /* TODO: forbid explicit yield from __serialize or __index here */ if (iproto_prepare_select(out, svp) != 0) - lbox_error(L); + luaT_error(L); ctx->out_is_dirty = true; struct luaL_serializer *cfg = luaL_msgpack_default; struct mpstream stream; @@ -331,7 +331,7 @@ execute_lua_eval(lua_State *L) uint32_t expr_len = mp_decode_strl(&expr); if (luaL_loadbuffer(L, expr, expr_len, "=eval")) { diag_set(LuajitError, lua_tostring(L, -1)); - lbox_error(L); + luaT_error(L); } /* Unpack arguments */ @@ -369,7 +369,7 @@ box_process_lua(struct request *request, struct obuf *out, lua_CFunction handler lua_State *L = lua_newthread(tarantool_L); int coro_ref = luaL_ref(tarantool_L, LUA_REGISTRYINDEX); - int rc = lbox_cpcall(L, handler, &ctx); + int rc = luaT_cpcall(L, handler, &ctx); luaL_unref(tarantool_L, LUA_REGISTRYINDEX, coro_ref); if (rc != 0) { if (ctx.out_is_dirty) { diff --git a/src/box/lua/cfg.cc b/src/box/lua/cfg.cc index 6a56289efe38691b129588e585107999ff520151..6c6fbcbf5ac277722bd4ac4c0ed478d99fff6679 100644 --- a/src/box/lua/cfg.cc +++ b/src/box/lua/cfg.cc @@ -48,7 +48,7 @@ lbox_cfg_check(struct lua_State *L) try { box_check_config(); } catch (Exception *) { - lbox_error(L); + luaT_error(L); } return 0; } @@ -59,7 +59,7 @@ lbox_cfg_load(struct lua_State *L) try { load_cfg(); } catch (Exception *) { - lbox_error(L); + luaT_error(L); } return 0; } @@ -70,7 +70,7 @@ lbox_cfg_set_wal_mode(struct lua_State *L) try { box_set_wal_mode(); } catch (Exception *) { - lbox_error(L); + luaT_error(L); } return 0; } @@ -81,7 +81,7 @@ lbox_cfg_set_listen(struct lua_State *L) try { box_set_listen(); } catch (Exception *) { - lbox_error(L); + luaT_error(L); } return 0; } @@ -92,7 +92,7 @@ lbox_cfg_set_replication_source(struct lua_State *L) try { box_set_replication_source(); } catch (Exception *) { - lbox_error(L); + luaT_error(L); } return 0; } @@ -103,7 +103,7 @@ lbox_cfg_set_log_level(struct lua_State *L) try { box_set_log_level(); } catch (Exception *) { - lbox_error(L); + luaT_error(L); } return 0; } @@ -114,7 +114,7 @@ lbox_cfg_set_readahead(struct lua_State *L) try { box_set_readahead(); } catch (Exception *) { - lbox_error(L); + luaT_error(L); } return 0; } @@ -125,7 +125,7 @@ lbox_cfg_set_io_collect_interval(struct lua_State *L) try { box_set_io_collect_interval(); } catch (Exception *) { - lbox_error(L); + luaT_error(L); } return 0; } @@ -136,7 +136,7 @@ lbox_cfg_set_too_long_threshold(struct lua_State *L) try { box_set_too_long_threshold(); } catch (Exception *) { - lbox_error(L); + luaT_error(L); } return 0; } @@ -147,7 +147,7 @@ lbox_cfg_set_snap_io_rate_limit(struct lua_State *L) try { box_set_snap_io_rate_limit(); } catch (Exception *) { - lbox_error(L); + luaT_error(L); } return 0; } @@ -158,7 +158,7 @@ lbox_cfg_set_panic_on_wal_error(struct lua_State *L) try { box_set_panic_on_wal_error(); } catch (Exception *) { - lbox_error(L); + luaT_error(L); } return 0; } @@ -169,7 +169,7 @@ lbox_cfg_set_read_only(struct lua_State *L) try { box_set_ro(cfg_geti("read_only") != 0); } catch (Exception *) { - lbox_error(L); + luaT_error(L); } return 0; } diff --git a/src/box/lua/error.cc b/src/box/lua/error.cc index ab4d141298bd3d066a1d6bd6fc7199d784f4bbae..a7907411493449cf769982ddda606a738a2bd0c0 100644 --- a/src/box/lua/error.cc +++ b/src/box/lua/error.cc @@ -43,7 +43,7 @@ extern "C" { #include "box/error.h" static int -lbox_error_raise(lua_State *L) +luaT_error_raise(lua_State *L) { uint32_t code = 0; const char *reason = NULL; @@ -56,7 +56,7 @@ lbox_error_raise(lua_State *L) if (top <= 1) { /* re-throw saved exceptions (if any) */ if (box_error_last()) - lbox_error(L); + luaT_error(L); return 0; } else if (top >= 2 && lua_type(L, 2) == LUA_TNUMBER) { code = lua_tointeger(L, 2); @@ -102,12 +102,12 @@ lbox_error_raise(lua_State *L) } say_debug("box.error() at %s:%i", file, line); box_error_set(file, line, code, reason); - lbox_error(L); + luaT_error(L); return 0; } static int -lbox_error_last(lua_State *L) +luaT_error_last(lua_State *L) { if (lua_gettop(L) >= 1) luaL_error(L, "box.error.last(): bad arguments"); @@ -146,7 +146,7 @@ lbox_error_last(lua_State *L) } static int -lbox_error_clear(lua_State *L) +luaT_error_clear(lua_State *L) { if (lua_gettop(L) >= 1) luaL_error(L, "box.error.clear(): bad arguments"); @@ -206,20 +206,20 @@ box_lua_error_init(struct lua_State *L) { } lua_newtable(L); { - lua_pushcfunction(L, lbox_error_raise); + lua_pushcfunction(L, luaT_error_raise); lua_setfield(L, -2, "__call"); lua_newtable(L); { - lua_pushcfunction(L, lbox_error_last); + lua_pushcfunction(L, luaT_error_last); lua_setfield(L, -2, "last"); } { - lua_pushcfunction(L, lbox_error_clear); + lua_pushcfunction(L, luaT_error_clear); lua_setfield(L, -2, "clear"); } { - lua_pushcfunction(L, lbox_error_raise); + lua_pushcfunction(L, luaT_error_raise); lua_setfield(L, -2, "raise"); } lua_setfield(L, -2, "__index"); diff --git a/src/box/lua/index.c b/src/box/lua/index.c index 83e62181df1eba7c785dd3d0a4af512250f73be8..35a10d5e881d62359adef143a142e8c7d943958c 100644 --- a/src/box/lua/index.c +++ b/src/box/lua/index.c @@ -53,8 +53,8 @@ lbox_insert(lua_State *L) struct tuple *result; if (box_insert(space_id, tuple, tuple + tuple_len, &result) != 0) - return lbox_error(L); - return lbox_pushtupleornil(L, result); + return luaT_error(L); + return luaT_pushtupleornil(L, result); } static int @@ -69,16 +69,16 @@ lbox_replace(lua_State *L) struct tuple *result; if (box_replace(space_id, tuple, tuple + tuple_len, &result) != 0) - return lbox_error(L); - return lbox_pushtupleornil(L, result); + return luaT_error(L); + return luaT_pushtupleornil(L, result); } static int lbox_index_update(lua_State *L) { if (lua_gettop(L) != 4 || !lua_isnumber(L, 1) || !lua_isnumber(L, 2) || - (lua_type(L, 3) != LUA_TTABLE && lua_istuple(L, 3) == NULL) || - (lua_type(L, 4) != LUA_TTABLE && lua_istuple(L, 4) == NULL)) + (lua_type(L, 3) != LUA_TTABLE && luaT_istuple(L, 3) == NULL) || + (lua_type(L, 4) != LUA_TTABLE && luaT_istuple(L, 4) == NULL)) return luaL_error(L, "Usage index:update(key, ops)"); uint32_t space_id = lua_tointeger(L, 1); @@ -91,16 +91,16 @@ lbox_index_update(lua_State *L) struct tuple *result; if (box_update(space_id, index_id, key, key + key_len, ops, ops + ops_len, 1, &result) != 0) - return lbox_error(L); - return lbox_pushtupleornil(L, result); + return luaT_error(L); + return luaT_pushtupleornil(L, result); } static int lbox_index_upsert(lua_State *L) { if (lua_gettop(L) != 4 || !lua_isnumber(L, 1) || !lua_isnumber(L, 2) || - (lua_type(L, 3) != LUA_TTABLE && lua_istuple(L, 3) == NULL) || - (lua_type(L, 4) != LUA_TTABLE && lua_istuple(L, 4) == NULL)) + (lua_type(L, 3) != LUA_TTABLE && luaT_istuple(L, 3) == NULL) || + (lua_type(L, 4) != LUA_TTABLE && luaT_istuple(L, 4) == NULL)) return luaL_error(L, "Usage index:upsert(tuple_key, ops)"); uint32_t space_id = lua_tointeger(L, 1); @@ -113,15 +113,15 @@ lbox_index_upsert(lua_State *L) struct tuple *result; if (box_upsert(space_id, index_id, tuple, tuple + tuple_len, ops, ops + ops_len, 1, &result) != 0) - return lbox_error(L); - return lbox_pushtupleornil(L, result); + return luaT_error(L); + return luaT_pushtupleornil(L, result); } static int lbox_index_delete(lua_State *L) { if (lua_gettop(L) != 3 || !lua_isnumber(L, 1) || !lua_isnumber(L, 2) || - (lua_type(L, 3) != LUA_TTABLE && lua_istuple(L, 3) == NULL)) + (lua_type(L, 3) != LUA_TTABLE && luaT_istuple(L, 3) == NULL)) return luaL_error(L, "Usage space:delete(key)"); uint32_t space_id = lua_tointeger(L, 1); @@ -131,8 +131,8 @@ lbox_index_delete(lua_State *L) struct tuple *result; if (box_delete(space_id, index_id, key, key + key_len, &result) != 0) - return lbox_error(L); - return lbox_pushtupleornil(L, result); + return luaT_error(L); + return luaT_pushtupleornil(L, result); } static int @@ -148,8 +148,8 @@ lbox_index_random(lua_State *L) struct tuple *tuple; if (box_index_random(space_id, index_id, rnd, &tuple) != 0) - return lbox_error(L); - return lbox_pushtupleornil(L, tuple); + return luaT_error(L); + return luaT_pushtupleornil(L, tuple); } static int @@ -165,8 +165,8 @@ lbox_index_get(lua_State *L) struct tuple *tuple; if (box_index_get(space_id, index_id, key, key + key_len, &tuple) != 0) - return lbox_error(L); - return lbox_pushtupleornil(L, tuple); + return luaT_error(L); + return luaT_pushtupleornil(L, tuple); } static int @@ -182,8 +182,8 @@ lbox_index_min(lua_State *L) struct tuple *tuple; if (box_index_min(space_id, index_id, key, key + key_len, &tuple) != 0) - return lbox_error(L); - return lbox_pushtupleornil(L, tuple); + return luaT_error(L); + return luaT_pushtupleornil(L, tuple); } static int @@ -199,8 +199,8 @@ lbox_index_max(lua_State *L) struct tuple *tuple; if (box_index_max(space_id, index_id, key, key + key_len, &tuple) != 0) - return lbox_error(L); - return lbox_pushtupleornil(L, tuple); + return luaT_error(L); + return luaT_pushtupleornil(L, tuple); } static int @@ -221,7 +221,7 @@ lbox_index_count(lua_State *L) ssize_t count = box_index_count(space_id, index_id, iterator, key, key + key_len); if (count == -1) - return lbox_error(L); + return luaT_error(L); lua_pushinteger(L, count); return 1; } @@ -255,7 +255,7 @@ lbox_index_iterator(lua_State *L) struct iterator *it = box_index_iterator(space_id, index_id, iterator, mpkey, mpkey + mpkey_len); if (it == NULL) - return lbox_error(L); + return luaT_error(L); assert(CTID_STRUCT_ITERATOR_REF != 0); struct iterator **ptr = (struct iterator **) luaL_pushcdata(L, @@ -280,8 +280,8 @@ lbox_iterator_next(lua_State *L) struct iterator *itr = *(struct iterator **) data; struct tuple *tuple; if (box_iterator_next(itr, &tuple) != 0) - return lbox_error(L); - return lbox_pushtupleornil(L, tuple); + return luaT_error(L); + return luaT_pushtupleornil(L, tuple); } /* }}} */ diff --git a/src/box/lua/init.c b/src/box/lua/init.c index 4e0e11fc371c882a481b7fb3111503c57bc99d33..01f4924b3451d8572619ce3b4c458d997e4aca02 100644 --- a/src/box/lua/init.c +++ b/src/box/lua/init.c @@ -34,7 +34,7 @@ #include <lauxlib.h> #include <lualib.h> -#include "lua/utils.h" /* lbox_error() */ +#include "lua/utils.h" /* luaT_error() */ #include "box/box.h" #include "box/txn.h" @@ -77,7 +77,7 @@ static int lbox_commit(lua_State *L) { if (box_txn_commit() != 0) - return lbox_error(L); + return luaT_error(L); return 0; } diff --git a/src/box/lua/misc.cc b/src/box/lua/misc.cc index c89829fd2a4214139be1f97d6b5a054c05a09afa..4214277d41e643394004d3f9b902e1963474bd37 100644 --- a/src/box/lua/misc.cc +++ b/src/box/lua/misc.cc @@ -65,7 +65,7 @@ lbox_port_buf_to_table(lua_State *L, struct port_buf *port_buf) lua_createtable(L, port_buf->size, 0); struct port_buf_entry *entry = port_buf->first; for (size_t i = 0 ; i < port_buf->size; i++) { - lbox_pushtuple(L, entry->tuple); + luaT_pushtuple(L, entry->tuple); lua_rawseti(L, -2, i + 1); entry = entry->next; } @@ -94,7 +94,7 @@ lbox_select(lua_State *L) if (box_select((struct port *) &port, space_id, index_id, iterator, offset, limit, key, key + key_len) != 0) { port_buf_destroy(&port); - return lbox_error(L); + return luaT_error(L); } /* diff --git a/src/box/lua/session.c b/src/box/lua/session.c index b733ae3f8edffc79dabe94249eb67677dc6a8b00..5397b8786954b22ee70db77d9b23a829f093b1cf 100644 --- a/src/box/lua/session.c +++ b/src/box/lua/session.c @@ -120,7 +120,7 @@ lbox_session_su(struct lua_State *L) user = user_find(lua_tointeger(L, 1)); } if (user == NULL) - lbox_error(L); + luaT_error(L); struct credentials orig_cr; credentials_copy(&orig_cr, &session->credentials); credentials_init(&session->credentials, user); @@ -131,7 +131,7 @@ lbox_session_su(struct lua_State *L) int error = lua_pcall(L, top - 2, LUA_MULTRET, 0); credentials_copy(&session->credentials, &orig_cr); if (error) - lbox_error(L); + luaT_error(L); return lua_gettop(L) - 1; } diff --git a/src/box/lua/space.cc b/src/box/lua/space.cc index 0906e8a420e1df3aab24030ff3eb929d0a4608fa..9148e22342aaf533874a5d2737687db1aa491872 100644 --- a/src/box/lua/space.cc +++ b/src/box/lua/space.cc @@ -55,12 +55,12 @@ lbox_push_on_replace_event(struct lua_State *L, void *event) struct txn_stmt *stmt = txn_current_stmt((struct txn *) event); if (stmt->old_tuple) { - lbox_pushtuple(L, stmt->old_tuple); + luaT_pushtuple(L, stmt->old_tuple); } else { lua_pushnil(L); } if (stmt->new_tuple) { - lbox_pushtuple(L, stmt->new_tuple); + luaT_pushtuple(L, stmt->new_tuple); } else { lua_pushnil(L); } diff --git a/src/box/lua/tuple.c b/src/box/lua/tuple.c index c904a9a30a51266c0d728703e135c74f1b42acf0..955c3dfefea90d9a3d5b22110d3942ea4d6395a8 100644 --- a/src/box/lua/tuple.c +++ b/src/box/lua/tuple.c @@ -30,7 +30,7 @@ */ #include "box/lua/tuple.h" -#include "lua/utils.h" /* lbox_error() */ +#include "lua/utils.h" /* luaT_error() */ #include "lua/msgpack.h" /* luamp_encode_XXX() */ #include "diag.h" /* diag_set() */ #include <small/ibuf.h> @@ -57,10 +57,10 @@ extern char tuple_lua[]; /* Lua source */ uint32_t CTID_CONST_STRUCT_TUPLE_REF; -static inline struct tuple * +static inline box_tuple_t * lua_checktuple(struct lua_State *L, int narg) { - struct tuple *tuple = lua_istuple(L, narg); + struct tuple *tuple = luaT_istuple(L, narg); if (tuple == NULL) { luaL_error(L, "Invalid argument #%d (box.tuple expected, got %s)", narg, lua_typename(L, lua_type(L, narg))); @@ -69,8 +69,8 @@ lua_checktuple(struct lua_State *L, int narg) return tuple; } -struct tuple * -lua_istuple(struct lua_State *L, int narg) +box_tuple_t * +luaT_istuple(struct lua_State *L, int narg) { assert(CTID_CONST_STRUCT_TUPLE_REF != 0); uint32_t ctypeid; @@ -101,7 +101,7 @@ lbox_tuple_new(lua_State *L) mpstream_init(&stream, buf, ibuf_reserve_cb, ibuf_alloc_cb, luamp_error, L); - if (argc == 1 && (lua_istable(L, 1) || lua_istuple(L, 1))) { + if (argc == 1 && (lua_istable(L, 1) || luaT_istuple(L, 1))) { /* New format: box.tuple.new({1, 2, 3}) */ luamp_encode_tuple(L, luaL_msgpack_default, &stream, 1); } else { @@ -117,9 +117,9 @@ lbox_tuple_new(lua_State *L) struct tuple *tuple = box_tuple_new(fmt, buf->buf, buf->buf + ibuf_used(buf)); if (tuple == NULL) - lbox_error(L); + luaT_error(L); /* box_tuple_new() doesn't leak on exception, see public API doc */ - lbox_pushtuple(L, tuple); + luaT_pushtuple(L, tuple); ibuf_reinit(tarantool_lua_ibuf); return 1; } @@ -199,10 +199,10 @@ lbox_tuple_slice(struct lua_State *L) lua_pushlightuserdata(L, it); lua_pushinteger(L, start); lua_pushinteger(L, end); - int rc = lbox_call(L, 3, end - start); + int rc = luaT_call(L, 3, end - start); box_tuple_iterator_free(it); if (rc != 0) - return lbox_error(L); + return luaT_error(L); return end - start; } @@ -212,7 +212,7 @@ luamp_convert_key(struct lua_State *L, struct luaL_serializer *cfg, { /* Performs keyfy() logic */ - struct tuple *tuple = lua_istuple(L, index); + struct tuple *tuple = luaT_istuple(L, index); if (tuple != NULL) return tuple_to_mpstream(tuple, stream); @@ -236,12 +236,12 @@ void luamp_encode_tuple(struct lua_State *L, struct luaL_serializer *cfg, struct mpstream *stream, int index) { - struct tuple *tuple = lua_istuple(L, index); + struct tuple *tuple = luaT_istuple(L, index); if (tuple != NULL) { return tuple_to_mpstream(tuple, stream); } else if (luamp_encode(L, cfg, stream, index) != MP_ARRAY) { diag_set(ClientError, ER_TUPLE_NOT_ARRAY); - lbox_error(L); + luaT_error(L); } } @@ -259,7 +259,7 @@ static enum mp_type luamp_encode_extension_box(struct lua_State *L, int idx, struct mpstream *stream) { - struct tuple *tuple = lua_istuple(L, idx); + struct tuple *tuple = luaT_istuple(L, idx); if (tuple != NULL) { tuple_to_mpstream(tuple, stream); return MP_ARRAY; @@ -317,7 +317,7 @@ lbox_tuple_transform(struct lua_State *L) if (op_cnt == 0) { /* tuple_update() does not accept an empty operation list. */ - lbox_pushtuple(L, tuple); + luaT_pushtuple(L, tuple); return 1; } @@ -350,15 +350,15 @@ lbox_tuple_transform(struct lua_State *L) struct tuple *new_tuple = box_tuple_update(tuple, buf->buf, buf->buf + ibuf_used(buf)); if (tuple == NULL) - lbox_error(L); + luaT_error(L); /* box_tuple_update() doesn't leak on exception, see public API doc */ - lbox_pushtuple(L, new_tuple); + luaT_pushtuple(L, new_tuple); ibuf_reset(buf); return 1; } void -lbox_pushtuple(struct lua_State *L, struct tuple *tuple) +luaT_pushtuple(struct lua_State *L, box_tuple_t *tuple) { assert(CTID_CONST_STRUCT_TUPLE_REF != 0); struct tuple **ptr = (struct tuple **) @@ -366,7 +366,7 @@ lbox_pushtuple(struct lua_State *L, struct tuple *tuple) *ptr = tuple; /* The order is important - first reference tuple, next set gc */ if (box_tuple_ref(tuple) != 0) { - lbox_error(L); + luaT_error(L); return; } lua_pushcfunction(L, lbox_tuple_gc); diff --git a/src/box/lua/tuple.h b/src/box/lua/tuple.h index e58272188d73f69cd89f239d0c7d388967d0136d..aac4e62b58ff9c95dd126665c6dda43b9ad81783 100644 --- a/src/box/lua/tuple.h +++ b/src/box/lua/tuple.h @@ -37,28 +37,44 @@ extern "C" { #endif /* defined(__cplusplus) */ struct tuple; +typedef struct tuple box_tuple_t; struct lua_State; struct mpstream; struct luaL_serializer; +/** \cond public */ + /** - * Push tuple on lua stack + * Push a tuple onto the stack. + * @param L Lua State + * @sa luaT_istuple + * @throws on OOM */ void -lbox_pushtuple(struct lua_State *L, struct tuple *tuple); +luaT_pushtuple(struct lua_State *L, box_tuple_t *tuple); + +/** + * Checks whether argument idx is a tuple + * + * @param L Lua State + * @param idx the stack index + * @retval non-NULL argument is tuple + * @retval NULL argument is not tuple + */ +box_tuple_t * +luaT_istuple(struct lua_State *L, int idx); + +/** \endcond public */ static inline int -lbox_pushtupleornil(struct lua_State *L, struct tuple *tuple) +luaT_pushtupleornil(struct lua_State *L, struct tuple *tuple) { if (tuple == NULL) return 0; - lbox_pushtuple(L, tuple); + luaT_pushtuple(L, tuple); return 1; } -struct tuple * -lua_istuple(struct lua_State *L, int narg); - void luamp_convert_key(struct lua_State *L, struct luaL_serializer *cfg, struct mpstream *stream, int index); diff --git a/src/lua/fiber.c b/src/lua/fiber.c index 43e84b8897e41d9fe31d12f948c38d5e691b023e..2e5424af533609d6df26d2729ca9a70ea2d55d6a 100644 --- a/src/lua/fiber.c +++ b/src/lua/fiber.c @@ -43,7 +43,7 @@ luaL_testcancel(struct lua_State *L) { if (fiber_is_cancelled()) { diag_set(FiberIsCancelled); - lbox_error(L); + luaT_error(L); } } @@ -277,7 +277,7 @@ lua_fiber_run_f(va_list ap) int coro_ref = va_arg(ap, int); struct lua_State *L = va_arg(ap, struct lua_State *); - result = lbox_call(L, lua_gettop(L) - 1, 0); + result = luaT_call(L, lua_gettop(L) - 1, 0); /* Destroy local storage */ int storage_ref = (int)(intptr_t) @@ -306,7 +306,7 @@ lbox_fiber_create(struct lua_State *L) struct fiber *f = fiber_new("lua", lua_fiber_run_f); if (f == NULL) { luaL_unref(L, LUA_REGISTRYINDEX, coro_ref); - lbox_error(L); + luaT_error(L); } /* Move the arguments to the new coro */ diff --git a/src/lua/init.c b/src/lua/init.c index 02ad35f7370ea4082de7ea2b1b257448b1bfaf11..6636d92cc6c7481bb8a2a1ad086be88385f5a3e1 100644 --- a/src/lua/init.c +++ b/src/lua/init.c @@ -447,7 +447,7 @@ run_script_f(va_list ap) lua_checkstack(L, argc - 1); for (int i = 1; i < argc; i++) lua_pushstring(L, argv[i]); - if (lbox_call(L, lua_gettop(L) - 1, 0) != 0) { + if (luaT_call(L, lua_gettop(L) - 1, 0) != 0) { struct error *e = diag_last_error(&fiber()->diag); panic("%s", e->errmsg); } diff --git a/src/lua/pickle.c b/src/lua/pickle.c index 211863e0c943bdc4608cd772e6c02c1f39fc69e7..393e84daba57c7cb72229a4d2afe779522beb522 100644 --- a/src/lua/pickle.c +++ b/src/lua/pickle.c @@ -49,7 +49,7 @@ luaL_region_dup(struct lua_State *L, struct region *region, void *to = region_alloc(region, size); if (to == NULL) { diag_set(OutOfMemory, size, "region", "luaL_region_dup"); - lbox_error(L); + luaT_error(L); } (void) memcpy(to, ptr, size); } @@ -167,7 +167,7 @@ lbox_pack(struct lua_State *L) if (res == NULL) { region_truncate(buf, used); diag_set(OutOfMemory, size, "region", "region_join"); - lbox_error(L); + luaT_error(L); } lua_pushlstring(L, res, len); region_truncate(buf, used); diff --git a/src/lua/socket.c b/src/lua/socket.c index 1f8c008841eec8b9572834201023a489cfb4583f..b15eb1568798986eb72a5943a99607eb8dc26799 100644 --- a/src/lua/socket.c +++ b/src/lua/socket.c @@ -720,11 +720,11 @@ lbox_socket_getaddrinfo(struct lua_State *L) lua_pushcfunction(L, lbox_getaddrinfo_result_wrapper); lua_pushlightuserdata(L, result); - int rc = lbox_call(L, 1, 1); + int rc = luaT_call(L, 1, 1); freeaddrinfo(result); if (rc != 0) - return lbox_error(L); + return luaT_error(L); return 1; } @@ -822,9 +822,9 @@ lbox_socket_accept(struct lua_State *L) lua_pushnumber(L, sc); lua_pushlightuserdata(L, &fa); lua_pushinteger(L, len); - if (lbox_call(L, 3, 2)) { + if (luaT_call(L, 3, 2)) { close(sc); - return lbox_error(L); + return luaT_error(L); } return 2; } @@ -867,10 +867,10 @@ lbox_socket_recvfrom(struct lua_State *L) lua_pushcfunction(L, lbox_socket_recvfrom_wrapper); lua_pushlightuserdata(L, buf); lua_pushinteger(L, res); - int rc = lbox_call(L, 2, 1); + int rc = luaT_call(L, 2, 1); free(buf); if (rc) - return lbox_error(L); + return luaT_error(L); lbox_socket_push_addr(L, (struct sockaddr *)&fa, len); return 2; } diff --git a/src/lua/trigger.c b/src/lua/trigger.c index 2d6e86804eabaf38b10c8995888af1ae8a90ffbe..c904248304b91310ddd96beaa536fad285ea1075 100644 --- a/src/lua/trigger.c +++ b/src/lua/trigger.c @@ -78,7 +78,7 @@ lbox_trigger_run(struct trigger *ptr, void *event) int coro_ref = luaL_ref(tarantool_L, LUA_REGISTRYINDEX); lua_rawgeti(L, LUA_REGISTRYINDEX, trigger->ref); int top = trigger->push_event(L, event); - if (lbox_call(L, top, 0)) { + if (luaT_call(L, top, 0)) { luaL_unref(tarantool_L, LUA_REGISTRYINDEX, coro_ref); diag_raise(); } diff --git a/src/lua/utils.c b/src/lua/utils.c index a48d2c96475b4fb66b7fec03f9f671bd09899b43..df2c0d7bea6d64678b43d2d7da65cec2a2273cc7 100644 --- a/src/lua/utils.c +++ b/src/lua/utils.c @@ -906,7 +906,7 @@ luaL_pusherror(struct lua_State *L, struct error *e) } int -lbox_error(lua_State *L) +luaT_error(lua_State *L) { struct error *e = diag_last_error(&fiber()->diag); assert(e != NULL); @@ -939,7 +939,7 @@ lbox_catch(lua_State *L) } int -lbox_call(struct lua_State *L, int nargs, int nreturns) +luaT_call(struct lua_State *L, int nargs, int nreturns) { if (lua_pcall(L, nargs, nreturns, 0)) return lbox_catch(L); @@ -947,7 +947,7 @@ lbox_call(struct lua_State *L, int nargs, int nreturns) } int -lbox_cpcall(lua_State *L, lua_CFunction func, void *ud) +luaT_cpcall(lua_State *L, lua_CFunction func, void *ud) { if (lua_cpcall(L, func, ud)) return lbox_catch(L); diff --git a/src/lua/utils.h b/src/lua/utils.h index af80f6148c33f8cfb0a1312d89d016f0d3a9903e..23aaecf52ffcff68d28409dcd3697a87838abc3e 100644 --- a/src/lua/utils.h +++ b/src/lua/utils.h @@ -428,6 +428,15 @@ luaL_touint64(struct lua_State *L, int idx); LUA_API int64_t luaL_toint64(struct lua_State *L, int idx); +LUA_API int +luaT_error(lua_State *L); + +LUA_API int +luaT_call(lua_State *L, int nargs, int nreturns); + +LUA_API int +luaT_cpcall(lua_State *L, lua_CFunction func, void *ud); + /** \endcond public */ struct error * @@ -487,15 +496,6 @@ luaL_checkfinite(struct lua_State *L, struct luaL_serializer *cfg, int tarantool_lua_utils_init(struct lua_State *L); -int -lbox_error(lua_State *L); - -int -lbox_call(lua_State *L, int nargs, int nreturns); - -int -lbox_cpcall(lua_State *L, lua_CFunction func, void *ud); - #if defined(__cplusplus) } /* extern "C" */ @@ -503,9 +503,9 @@ lbox_cpcall(lua_State *L, lua_CFunction func, void *ud); #include <fiber.h> static inline void -lbox_call_xc(lua_State *L, int nargs, int nreturns) +luaT_call_xc(lua_State *L, int nargs, int nreturns) { - if (lbox_call(L, nargs, nreturns) != 0) + if (luaT_call(L, nargs, nreturns) != 0) diag_raise(); }