Skip to content

Commit

Permalink
Fix up protected function returns and fix/use the horrible size ext…
Browse files Browse the repository at this point in the history
…ension point derp. Fixes #973
  • Loading branch information
ThePhD committed May 27, 2020
1 parent 465b472 commit e09d2ff
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 13 deletions.
4 changes: 2 additions & 2 deletions include/sol/protected_function_result.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,15 @@ namespace sol {
using ValueType = typename UT::value_type;
if constexpr (std::is_same_v<ValueType, error>) {
if (valid()) {
return UT(nullopt);
return UT();
}
return UT(error(detail::direct_error, stack::get<std::string>(L, target)));
}
else {
if (!valid()) {
return UT();
}
return UT(stack::get<ValueType>(L, target));
return stack::get<UT>(L, target);
}
}
else {
Expand Down
4 changes: 2 additions & 2 deletions single/include/sol/forward.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

// This file was generated with a script.
// Generated 2020-05-22 13:37:42.297619 UTC
// This header was generated with sol v3.2.0 (revision d9c034d)
// Generated 2020-05-27 00:07:01.142852 UTC
// This header was generated with sol v3.2.0 (revision 465b472)
// https://github.com/ThePhD/sol2

#ifndef SOL_SINGLE_INCLUDE_FORWARD_HPP
Expand Down
8 changes: 4 additions & 4 deletions single/include/sol/sol.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

// This file was generated with a script.
// Generated 2020-05-22 13:37:38.805887 UTC
// This header was generated with sol v3.2.0 (revision d9c034d)
// Generated 2020-05-27 00:07:00.664617 UTC
// This header was generated with sol v3.2.0 (revision 465b472)
// https://github.com/ThePhD/sol2

#ifndef SOL_SINGLE_INCLUDE_HPP
Expand Down Expand Up @@ -15197,15 +15197,15 @@ namespace sol {
using ValueType = typename UT::value_type;
if constexpr (std::is_same_v<ValueType, error>) {
if (valid()) {
return UT(nullopt);
return UT();
}
return UT(error(detail::direct_error, stack::get<std::string>(L, target)));
}
else {
if (!valid()) {
return UT();
}
return UT(stack::get<ValueType>(L, target));
return stack::get<UT>(L, target);
}
}
else {
Expand Down
14 changes: 9 additions & 5 deletions tests/runtime_tests/source/container_shims.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,18 +143,20 @@ namespace sol {

template <>
struct usertype_container<my_vec> {
// Hooks Lua's syntax for #c
static int size(lua_State* L) {
my_vec& v = sol::stack::get<my_vec&>(L, 1);
return stack::push(L, v.size());
}

// Used by default implementation
static auto begin(lua_State*, my_vec& self) {
return self.begin();
}
static auto end(lua_State*, my_vec& self) {
return self.end();
}

static std::size_t size(lua_State* L) {
my_vec& v = sol::stack::get<my_vec&>(L, 1);
return v.size();
}

static std::ptrdiff_t index_adjustment(lua_State*, my_vec&) {
return 0;
}
Expand Down Expand Up @@ -216,6 +218,8 @@ TEST_CASE("containers/custom indexing", "allow containers to set a custom indexi
REQUIRE(result2.valid());
auto result3 = lua.safe_script("assert(c[-1] == nil)", sol::script_pass_on_error);
REQUIRE(result3.valid());
auto result4 = lua.safe_script("assert(#c == 10)", sol::script_pass_on_error);
REQUIRE(result4.valid());
}

TEST_CASE("containers/containers of pointers", "containers of pointers shouldn't have their value_type's overly stripped") {
Expand Down

0 comments on commit e09d2ff

Please sign in to comment.