mirror of
https://github.com/ThePhD/sol2.git
synced 2024-03-22 13:10:44 +08:00
parent
ba1dc4f9f4
commit
3b4144c6ec
@ -31,7 +31,7 @@
|
|||||||
#include <sol/table_iterator.hpp>
|
#include <sol/table_iterator.hpp>
|
||||||
#include <sol/protected_function.hpp>
|
#include <sol/protected_function.hpp>
|
||||||
|
|
||||||
#include <sol/detail/pairs.hpp>
|
#include <sol/stack/detail/pairs.hpp>
|
||||||
|
|
||||||
namespace sol {
|
namespace sol {
|
||||||
|
|
||||||
@ -120,8 +120,7 @@ namespace sol {
|
|||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
stack::get_field<true, false>(m_L, "next");
|
auto maybe_next = stack::stack_detail::find_lua_next_function(m_L);
|
||||||
auto maybe_next = stack::pop<optional<protected_function>>(m_L);
|
|
||||||
if (maybe_next.has_value()) {
|
if (maybe_next.has_value()) {
|
||||||
m_next_function_ref = std::move(*maybe_next);
|
m_next_function_ref = std::move(*maybe_next);
|
||||||
m_table_ref = source_;
|
m_table_ref = source_;
|
||||||
|
@ -28,10 +28,39 @@
|
|||||||
|
|
||||||
#include <sol/stack.hpp>
|
#include <sol/stack.hpp>
|
||||||
#include <sol/stack_reference.hpp>
|
#include <sol/stack_reference.hpp>
|
||||||
|
#include <sol/protected_function.hpp>
|
||||||
#include <sol/assert.hpp>
|
#include <sol/assert.hpp>
|
||||||
|
|
||||||
|
#include <optional>
|
||||||
|
|
||||||
namespace sol { namespace stack { namespace stack_detail {
|
namespace sol { namespace stack { namespace stack_detail {
|
||||||
|
|
||||||
|
inline bool maybe_push_lua_next_function(lua_State* L_) {
|
||||||
|
stack::get_field<true, false>(L_, "next");
|
||||||
|
bool is_next = stack::check<protected_function>(L_);
|
||||||
|
if (is_next) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
stack::get_field<true, false>(L_, "table");
|
||||||
|
if (!stack::check<table>(L_, -1)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
lua_getfield(L_, -1, "next");
|
||||||
|
bool is_table_next_func = stack::check<protected_function>(L_, -1);
|
||||||
|
if (is_table_next_func) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
lua_pop(L_, 1);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline std::optional<protected_function> find_lua_next_function(lua_State* L_) {
|
||||||
|
if (maybe_push_lua_next_function(L_)) {
|
||||||
|
return stack::pop<protected_function>(L_);
|
||||||
|
}
|
||||||
|
return std::nullopt;
|
||||||
|
}
|
||||||
|
|
||||||
inline int c_lua_next(lua_State* L_) noexcept {
|
inline int c_lua_next(lua_State* L_) noexcept {
|
||||||
stack_reference table_stack_ref(L_, raw_index(1));
|
stack_reference table_stack_ref(L_, raw_index(1));
|
||||||
stateless_stack_reference key_stack_ref(L_, raw_index(2));
|
stateless_stack_reference key_stack_ref(L_, raw_index(2));
|
||||||
@ -45,8 +74,7 @@ namespace sol { namespace stack { namespace stack_detail {
|
|||||||
|
|
||||||
inline int readonly_pairs(lua_State* L_) noexcept {
|
inline int readonly_pairs(lua_State* L_) noexcept {
|
||||||
int pushed = 0;
|
int pushed = 0;
|
||||||
stack::get_field<true, false>(L_, "next");
|
if (!maybe_push_lua_next_function(L_)) {
|
||||||
if (!stack::check<unsafe_function>(L_, -1)) {
|
|
||||||
// we do not have the "next" function in the global namespace
|
// we do not have the "next" function in the global namespace
|
||||||
// from the "table" global entiry, use our own
|
// from the "table" global entiry, use our own
|
||||||
pushed += stack::push(L_, &c_lua_next);
|
pushed += stack::push(L_, &c_lua_next);
|
File diff suppressed because it is too large
Load Diff
24
tests/inclusion/source/detail/build_version.cpp
Normal file
24
tests/inclusion/source/detail/build_version.cpp
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
// sol2
|
||||||
|
|
||||||
|
// The MIT License (MIT)
|
||||||
|
|
||||||
|
// Copyright (c) 2013-2021 Rapptz, ThePhD and contributors
|
||||||
|
|
||||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
|
// this software and associated documentation files (the "Software"), to deal in
|
||||||
|
// the Software without restriction, including without limitation the rights to
|
||||||
|
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||||
|
// the Software, and to permit persons to whom the Software is furnished to do so,
|
||||||
|
// subject to the following conditions:
|
||||||
|
|
||||||
|
// The above copyright notice and this permission notice shall be included in all
|
||||||
|
// copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||||
|
// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||||
|
// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||||
|
// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||||
|
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
|
#include <sol/detail/build_version.hpp>
|
24
tests/inclusion/source/stack/detail/pairs.cpp
Normal file
24
tests/inclusion/source/stack/detail/pairs.cpp
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
// sol2
|
||||||
|
|
||||||
|
// The MIT License (MIT)
|
||||||
|
|
||||||
|
// Copyright (c) 2013-2021 Rapptz, ThePhD and contributors
|
||||||
|
|
||||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
|
// this software and associated documentation files (the "Software"), to deal in
|
||||||
|
// the Software without restriction, including without limitation the rights to
|
||||||
|
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||||
|
// the Software, and to permit persons to whom the Software is furnished to do so,
|
||||||
|
// subject to the following conditions:
|
||||||
|
|
||||||
|
// The above copyright notice and this permission notice shall be included in all
|
||||||
|
// copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||||
|
// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||||
|
// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||||
|
// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||||
|
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
|
#include <sol/stack/detail/pairs.hpp>
|
Loading…
x
Reference in New Issue
Block a user