Skip to content
Snippets Groups Projects
Commit 4625b04d authored by Nick Zavaritsky's avatar Nick Zavaritsky Committed by Roman Tsisyk
Browse files

Fix gh-1730: tostring in fiber channel and cond

parent 7daab631
No related branches found
No related tags found
No related merge requests found
......@@ -257,6 +257,18 @@ lbox_ipc_channel_is_closed(struct lua_State *L)
return 1;
}
static int
lbox_ipc_channel_to_string(struct lua_State *L)
{
struct ipc_channel *ch = lbox_check_channel(L, 1, "");
if (ipc_channel_is_closed(ch)) {
lua_pushstring(L, "channel: closed");
} else {
lua_pushfstring(L, "channel: %d", (int)ipc_channel_count(ch));
}
return 1;
}
static int
lbox_ipc_cond(struct lua_State *L)
{
......@@ -318,11 +330,21 @@ lbox_ipc_cond_wait(struct lua_State *L)
return 1;
}
static int
lbox_ipc_cond_to_string(struct lua_State *L)
{
struct ipc_cond *cond = lbox_check_cond(L, 1, "");
(void)cond;
lua_pushstring(L, "cond");
return 1;
}
void
tarantool_lua_ipc_init(struct lua_State *L)
{
static const struct luaL_reg channel_meta[] = {
{"__gc", lbox_ipc_channel_gc},
{"__tostring", lbox_ipc_channel_to_string},
{"is_full", lbox_ipc_channel_is_full},
{"is_empty", lbox_ipc_channel_is_empty},
{"put", lbox_ipc_channel_put},
......@@ -339,6 +361,7 @@ tarantool_lua_ipc_init(struct lua_State *L)
static const struct luaL_reg cond_meta[] = {
{"__gc", lbox_ipc_cond_gc},
{"__tostring", lbox_ipc_cond_to_string},
{"signal", lbox_ipc_cond_signal},
{"broadcast", lbox_ipc_cond_broadcast},
{"wait", lbox_ipc_cond_wait},
......
......@@ -58,6 +58,10 @@ ch:get(.1, nil, unpack(ignored_args))
---
- null
...
tostring(ch)
---
- 'channel: 0'
...
ch:put()
---
- error: 'usage: channel:put(var [, timeout])'
......@@ -70,6 +74,10 @@ ch:put('test')
---
- true
...
tostring(ch)
---
- 'channel: 1'
...
ch:get()
---
- test
......@@ -390,6 +398,10 @@ ch:is_closed()
---
- true
...
tostring(ch)
---
- 'channel: closed'
...
ch = fiber.channel(1)
---
...
......@@ -556,6 +568,10 @@ refs -- must be zero
c = fiber.cond()
---
...
tostring(c)
---
- cond
...
-- args validation
c.wait()
---
......
......@@ -17,9 +17,11 @@ ch:is_empty(unpack(ignored_args))
ch:get(.1)
ch:get(.1, nil)
ch:get(.1, nil, unpack(ignored_args))
tostring(ch)
ch:put()
ch:count()
ch:put('test')
tostring(ch)
ch:get()
ch:put('test', nil), ch:get()
ch:put('test', nil, unpack(ignored_args)), ch:get()
......@@ -108,6 +110,7 @@ ch:get()
ch:get()
ch:put(10)
ch:is_closed()
tostring(ch)
ch = fiber.channel(1)
ch:put(true)
......@@ -189,6 +192,7 @@ refs -- must be zero
-- fiber.cond
c = fiber.cond()
tostring(c)
-- args validation
c.wait()
c.wait('1')
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment