implement shared_table constructor (#52)

This commit is contained in:
mihacooper 2017-06-18 18:40:30 +03:00 committed by Ilia
parent cfd2e9b39d
commit 720c3aeac4
3 changed files with 18 additions and 2 deletions

@ -1 +1 @@
Subproject commit 3342e65b385aac57caca3b8284713682c9ea1211
Subproject commit 0fb52a11520e049c0cf809254f7e862bac3a55fa

View File

@ -18,7 +18,13 @@ sol::object createThread(const sol::this_state& lua,
return sol::make_object(lua, std::make_shared<Thread>(path, cpath, step, function, args));
}
sol::object createTable(sol::this_state lua) {
sol::object createTable(sol::this_state lua, const sol::optional<sol::object>& tbl) {
if (tbl)
{
REQUIRE(tbl->get_type() == sol::type::table) << "Unexpected type for effil.table, table expected got: "
<< lua_typename(lua, (int)tbl->get_type());
return createStoredObject(*tbl)->unpack(lua);
}
return sol::make_object(lua, GC::instance().create<SharedTable>());
}

View File

@ -2,6 +2,16 @@ require "bootstrap-tests"
test.shared_table.tear_down = default_tear_down
test.shared_table.constructor = function ()
local share = effil.table {
key = "value"
}
test.equal(share.key, "value")
test.equal(pcall(effil.table, ""), false)
test.equal(pcall(effil.table, 22), false)
test.equal(pcall(effil.table, effil.table()), false)
end
test.shared_table.pairs = function ()
local share = effil.table()
local data = { 0, 0, 0, ["key1"] = 0, ["key2"] = 0, ["key3"] = 0 }