From 720c3aeac4004c64ac60f82a2a08c0bc43217572 Mon Sep 17 00:00:00 2001 From: mihacooper Date: Sun, 18 Jun 2017 18:40:30 +0300 Subject: [PATCH] implement shared_table constructor (#52) --- libs/sol | 2 +- src/cpp/lua-module.cpp | 8 +++++++- tests/lua/shared-table.lua | 10 ++++++++++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/libs/sol b/libs/sol index 3342e65..0fb52a1 160000 --- a/libs/sol +++ b/libs/sol @@ -1 +1 @@ -Subproject commit 3342e65b385aac57caca3b8284713682c9ea1211 +Subproject commit 0fb52a11520e049c0cf809254f7e862bac3a55fa diff --git a/src/cpp/lua-module.cpp b/src/cpp/lua-module.cpp index 7992f69..754905a 100644 --- a/src/cpp/lua-module.cpp +++ b/src/cpp/lua-module.cpp @@ -18,7 +18,13 @@ sol::object createThread(const sol::this_state& lua, return sol::make_object(lua, std::make_shared(path, cpath, step, function, args)); } -sol::object createTable(sol::this_state lua) { +sol::object createTable(sol::this_state lua, const sol::optional& 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()); } diff --git a/tests/lua/shared-table.lua b/tests/lua/shared-table.lua index a4cc507..45557da 100644 --- a/tests/lua/shared-table.lua +++ b/tests/lua/shared-table.lua @@ -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 }