Added cycle detection to Variant

We accidentally enabled nested tables previously, and now it errors properly when the tables contain cycles. Before you'd get (or at least I got) a nice lua stack overflow error.

--HG--
branch : minor
This commit is contained in:
Bart van Strien
2017-08-30 13:07:57 +02:00
parent d35f69bcff
commit 5ddc89a033
7 changed files with 44 additions and 18 deletions
+13 -9
View File
@@ -33,21 +33,25 @@ Channel *luax_checkchannel(lua_State *L, int idx)
int w_Channel_push(lua_State *L)
{
Channel *c = luax_checkchannel(L, 1);
Variant var = Variant::fromLua(L, 2);
if (var.getType() == Variant::UNKNOWN)
return luaL_argerror(L, 2, "boolean, number, string, love type, or flat table expected");
uint64 id = c->push(var);
lua_pushnumber(L, (lua_Number) id);
luax_catchexcept(L, [&]() {
Variant var = Variant::fromLua(L, 2);
if (var.getType() == Variant::UNKNOWN)
luaL_argerror(L, 2, "boolean, number, string, love type, or table expected");
uint64 id = c->push(var);
lua_pushnumber(L, (lua_Number) id);
});
return 1;
}
int w_Channel_supply(lua_State *L)
{
Channel *c = luax_checkchannel(L, 1);
Variant var = Variant::fromLua(L, 2);
if (var.getType() == Variant::UNKNOWN)
return luaL_argerror(L, 2, "boolean, number, string, love type, or flat table expected");
c->supply(var);
luax_catchexcept(L, [&]() {
Variant var = Variant::fromLua(L, 2);
if (var.getType() == Variant::UNKNOWN)
luaL_argerror(L, 2, "boolean, number, string, love type, or table expected");
c->supply(var);
});
return 0;
}