How I can use it from C++ code? #193
-
Hello! How I can use these queues from C++ code? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
It depends of a nature of this C++ code. If we're talking about an external process, one should choose a connector and call queue functions using it. Don't forget to grant privileges to execute those functions to your user/role, consider using If we're about a module (Lua rock) or a stored procedure (registered with A sketchy code: int saved_top = lua_gettop(L);
lua_getfield(L, LUA_GLOBALSINDEX, "queue");
lua_getfield(L, -1, "take");
<..prepare queue.take() args..>
if (lua_pcall(L, <...>) != 0) {
<..handle an error..>
}
<..process return values..>
lua_settop(L, saved_top); If we're in a stored procedure, we have no static struct lua_State *lua_state = NULL;
static int lua_state_ref = LUA_NOREF;
/* Create a Lua stack. */
struct lua_State *global_L = luaT_state();
lua_state = lua_newthread(global_L); /* Popped by luaL_ref(). */
/* We should keep a reference to protect it from GC. */
lua_state_ref = luaL_ref(global_L, LUA_REGISTRYINDEX);
/* Release the Lua stack. */
struct lua_State *global_L = luaT_state();
luaL_unref(global_L, LUA_REGISTRYINDEX, lua_state_ref);
lua_state = NULL;
lua_state_ref = LUA_NOREF; Use this All the code snippets are just to illustrate the idea and show APIs that can be used here. I didn't perform any testing to offer a ready-to-use solution. |
Beta Was this translation helpful? Give feedback.
It depends of a nature of this C++ code.
If we're talking about an external process, one should choose a connector and call queue functions using it. Don't forget to grant privileges to execute those functions to your user/role, consider using
queue.grant({call = true})
. You can look at the list of C/C++ connectors here. At the moment of writting it contains tarantool-c (C) and tntcxx (C++).If we're about a module (Lua rock) or a stored procedure (registered with
box.schema.func.create()
) written on C/C++, things are a bit different. We want to call a queue function locally. Lua/C API is for that.A sketchy code: