mirror of
https://github.com/ThePhD/sol2.git
synced 2024-03-22 13:10:44 +08:00
Merge remote-tracking branch 'zwparchman/develop' into develop
This commit is contained in:
commit
9804d7dd63
|
@ -178,6 +178,18 @@ public:
|
|||
return tuple_get( types<Ret...>( ), std::index_sequence_for<Ret...>( ), std::forward_as_tuple(std::forward<Keys>(keys)...));
|
||||
}
|
||||
|
||||
template<typename Ret, typename Key>
|
||||
Ret get_with_default(Key key, Ret _default) const {
|
||||
|
||||
sol::optional<Ret> option = operator[](key);
|
||||
if( option ){
|
||||
return option.value();
|
||||
}
|
||||
else {
|
||||
return _default;
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T, typename... Keys>
|
||||
decltype(auto) traverse_get( Keys&&... keys ) const {
|
||||
auto pp = stack::push_pop<is_global<Keys...>::value>(*this);
|
||||
|
|
17
tests.cpp
17
tests.cpp
|
@ -505,6 +505,23 @@ TEST_CASE("tables/variables", "Check if tables and variables work as intended")
|
|||
REQUIRE_NOTHROW(lua.script("assert(os.name == \"windows\")"));
|
||||
}
|
||||
|
||||
TEST_CASE("simple/get_default", "Test that table::get_default work corretly") {
|
||||
sol::state lua;
|
||||
|
||||
auto bob_table = lua.create_table("bob");
|
||||
int is_set=0;
|
||||
int is_not_set=0;
|
||||
bob_table.set("is_set",42);
|
||||
|
||||
is_set = bob_table.get_with_default("is_set",3);
|
||||
is_not_set = bob_table.get_with_default("is_not_set",22);
|
||||
|
||||
REQUIRE(is_set == 42);
|
||||
REQUIRE(is_not_set == 22);
|
||||
}
|
||||
|
||||
|
||||
|
||||
TEST_CASE("tables/create", "Check if creating a table is kosher") {
|
||||
sol::state lua;
|
||||
lua["testtable"] = sol::table::create(lua.lua_state(), 0, 0, "Woof", "Bark", 1, 2, 3, 4);
|
||||
|
|
Loading…
Reference in New Issue
Block a user