sol2
sol2 copied to clipboard
traverse_raw_set is untested
trafficstars
In this example traverse_raw_set doesn't even compile.
#include <iostream>
#define SOL_ALL_SAFETIES_ON 1
#define SOL_PRINT_ERRORS 1
#include <sol/sol.hpp>
int main() {
sol::state lua;
lua.open_libraries();
lua.create_table().traverse_raw_set("a", "b", "c");
}
In file included from sol/sol2/include/sol/metatable.hpp:27,
from sol/sol2/include/sol/usertype.hpp:31,
from sol/sol2/include/sol/sol.hpp:56,
from sol/main.cpp:4:
sol/sol2/include/sol/table_core.hpp: In instantiation of ‘sol::basic_table_core<<anonymous>, <template-parameter-1-2> >& sol::basic_table_core<<anonymous>, <template-parameter-1-2> >::traverse_raw_set(Keys&& ...) [with Keys = {const char (&)[2], const char (&)[2], const char (&)[2]}; bool top_level = false; ref_t = sol::basic_reference<false>]’:
sol/main.cpp:9:40: required from here
sol/sol2/include/sol/table_core.hpp:519:66: error: no matching function for call to ‘sol::basic_table_core<false, sol::basic_reference<false> >::traverse_set_deep<false, true, false>(const char [2], const char [2], const char [2])’
519 | traverse_set_deep<top_level, true, false>(std::forward<Keys>(keys)...);
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
sol/sol2/include/sol/table_core.hpp:236:22: note: candidate: ‘template<bool global, bool raw, sol::detail::insert_mode mode, class Key, class ... Keys> void sol::basic_table_core<<anonymous>, <template-parameter-1-2> >::traverse_set_deep(int, Key&&, Keys&& ...) const [with bool global = global; bool raw = raw; sol::detail::insert_mode mode = mode; Keys = Key; bool top_level = false; ref_t = sol::basic_reference<false>]’
236 | void traverse_set_deep(int table_index, Key&& key, Keys&&... keys) const {
| ^~~~~~~~~~~~~~~~~
sol/sol2/include/sol/table_core.hpp:236:22: note: template argument deduction/substitution failed:
sol/sol2/include/sol/table_core.hpp:519:66: error: could not convert ‘false’ from ‘bool’ to ‘sol::detail::insert_mode’
519 | traverse_set_deep<top_level, true, false>(std::forward<Keys>(keys)...);
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| |
| bool
Source code:
template <typename... Keys>
basic_table_core& traverse_set(Keys&&... keys) {
static_assert(sizeof...(Keys) > 1, "must pass at least 1 key and 1 value to set");
constexpr static bool global
= (meta::count_when_for_to_pack_v < detail::is_not_insert_mode, 1, is_set_direct_tableless, meta::unqualified_t<Keys>... >> 0);
auto pp = stack::push_pop<global>(*this);
int table_index = pp.index_of(*this);
lua_State* L = base_t::lua_state();
auto pn = stack::pop_n(L, static_cast<int>(sizeof...(Keys) - 2 - meta::count_for_pack_v<detail::is_insert_mode, meta::unqualified_t<Keys>...>));
traverse_set_deep<top_level, false, detail::insert_mode::none>(table_index, std::forward<Keys>(keys)...);
return *this;
}
template <typename... Keys>
basic_table_core& traverse_raw_set(Keys&&... keys) {
constexpr static bool global = (meta::count_for_to_pack_v < 1, is_raw_set_direct_tableless, meta::unqualified_t<Keys>... >> 0);
auto pp = stack::push_pop<global>(*this);
lua_State* L = base_t::lua_state();
auto pn = stack::pop_n(L, static_cast<int>(sizeof...(Keys) - 2 - meta::count_for_pack_v<detail::is_insert_mode, meta::unqualified_t<Keys>...>));
traverse_set_deep<top_level, true, false>(std::forward<Keys>(keys)...);
return *this;
}
Is there a reason they are different? The only thing that should change is raw template parameter to true.