diff --git a/appveyor.yml b/appveyor.yml index cffe6928..91f53943 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -156,8 +156,9 @@ init: before_build: - md build-sol2 - cd build-sol2 +- cd - echo %vcvars_script% -- cd && %vcvars_script% +- %vcvars_script% - cmake .. -G "%CMAKE_GENERATOR%" %build_compiler% -DCMAKE_BUILD_TYPE=Release "-DSOL2_LUA_VERSION=%SOL2_LUA_VERSION%" -DSOL2_PLATFORM=%PLATFORM% -DSOL2_CI=ON -DSOL2_BUILD_LUA=ON -DBUILD_LUA_AS_DLL=ON -DSOL2_TESTS=ON -DSOL2_EXAMPLES=ON -DSOL2_TESTS_EXAMPLES=ON build_script: diff --git a/cmake/Modules/FindLuaBuild/LuaJIT.cmake b/cmake/Modules/FindLuaBuild/LuaJIT.cmake index 0d91aaec..9e745154 100644 --- a/cmake/Modules/FindLuaBuild/LuaJIT.cmake +++ b/cmake/Modules/FindLuaBuild/LuaJIT.cmake @@ -299,16 +299,16 @@ set(LUA_JIT_POSTBUILD_COMMENTS "Executable - Moving \"${LUA_JIT_SOURCE_LUA_INTER set(LUA_JIT_POSTBUILD_COMMANDS COMMAND "${CMAKE_COMMAND}" -E copy "${LUA_JIT_SOURCE_LUA_INTERPRETER}" "${LUA_JIT_DESTINATION_LUA_INTERPRETER}") if (BUILD_LUA_AS_DLL) if (MSVC) - set(LUA_JIT_POSTBUILD_COMMENTS "${LUA_JIT_POSTBUILD_COMMENTS} | Import Library - Moving \"${LUA_JIT_SOURCE_LUA_IMP_LIB}\" to \"${LUA_JIT_DESTINATION_LUA_IMP_LIB}\"...") + set(LUA_JIT_POSTBUILD_COMMENTS "${LUA_JIT_POSTBUILD_COMMENTS} Import Library - Moving \"${LUA_JIT_SOURCE_LUA_IMP_LIB}\" to \"${LUA_JIT_DESTINATION_LUA_IMP_LIB}\"...") set(LUA_JIT_POSTBUILD_COMMANDS ${LUA_JIT_POSTBUILD_COMMANDS} COMMAND "${CMAKE_COMMAND}" -E copy "${LUA_JIT_SOURCE_LUA_IMP_LIB}" "${LUA_JIT_DESTINATION_LUA_IMP_LIB}") - set(LUA_JIT_POSTBUILD_COMMENTS "${LUA_JIT_POSTBUILD_COMMENTS} | Library - Moving \"${LUA_JIT_SOURCE_LUA_LIB_EXP}\" to \"${LUA_JIT_DESTINATION_LUA_LIB_EXP}\"...") + set(LUA_JIT_POSTBUILD_COMMENTS "${LUA_JIT_POSTBUILD_COMMENTS} Library - Moving \"${LUA_JIT_SOURCE_LUA_LIB_EXP}\" to \"${LUA_JIT_DESTINATION_LUA_LIB_EXP}\"...") set(LUA_JIT_POSTBUILD_COMMANDS ${LUA_JIT_POSTBUILD_COMMANDS} && "${CMAKE_COMMAND}" -E copy "${LUA_JIT_SOURCE_LUA_LIB_EXP}" "${LUA_JIT_DESTINATION_LUA_LIB_EXP}") endif() - set(LUA_JIT_POSTBUILD_COMMENTS "${LUA_JIT_POSTBUILD_COMMENTS} | Dynamic Library - Moving \"${LUA_JIT_SOURCE_LUA_DLL}\" to \"${LUA_JIT_DESTINATION_LUA_DLL}\"...") + set(LUA_JIT_POSTBUILD_COMMENTS "${LUA_JIT_POSTBUILD_COMMENTS} Dynamic Library - Moving \"${LUA_JIT_SOURCE_LUA_DLL}\" to \"${LUA_JIT_DESTINATION_LUA_DLL}\"...") set(LUA_JIT_POSTBUILD_COMMANDS ${LUA_JIT_POSTBUILD_COMMANDS} COMMAND "${CMAKE_COMMAND}" -E copy "${LUA_JIT_SOURCE_LUA_DLL}" "${LUA_JIT_DESTINATION_LUA_DLL}") else() - set(LUA_JIT_POSTBUILD_COMMENTS "${LUA_JIT_POSTBUILD_COMMENTS} | Library - Moving \"${LUA_JIT_SOURCE_LUA_LIB}\" to \"${LUA_JIT_DESTINATION_LUA_LIB}\"...") + set(LUA_JIT_POSTBUILD_COMMENTS "${LUA_JIT_POSTBUILD_COMMENTS} Library - Moving \"${LUA_JIT_SOURCE_LUA_LIB}\" to \"${LUA_JIT_DESTINATION_LUA_LIB}\"...") set(LUA_JIT_POSTBUILD_COMMANDS ${LUA_JIT_POSTBUILD_COMMANDS} COMMAND "${CMAKE_COMMAND}" -E copy "${LUA_JIT_SOURCE_LUA_LIB}" "${LUA_JIT_DESTINATION_LUA_LIB}") endif() diff --git a/examples/source/allocation_limit.cpp b/examples/source/allocation_limit.cpp index 3134cffd..c9293b3b 100644 --- a/examples/source/allocation_limit.cpp +++ b/examples/source/allocation_limit.cpp @@ -110,6 +110,9 @@ int main() { std::cout << "=== memory tracker ===" << std::endl; +#if defined(SOL_LUAJIT) && SOL_LUA_VERSION < 20100 && (UINTPTR_MAX > 0xFFFFFFFF) + std::cout << "LuaJIT in x64 mode on LuaJIT 2.0.X versions does not support using a custom allocator!" << std::endl; +#else memory_tracker box; std::cout << "memory at start: " << box.currently_used() << " bytes / " << box.memory_limit() << " bytes" << std::endl; sol::state lua(&sol::default_at_panic, &memory_tracker::allocate, &box); @@ -127,6 +130,6 @@ int main() { lua.safe_script("local obj = my_type.new() print(obj.a, obj.b, obj.c) obj.b = true print(obj.a, obj.b, obj.c)"); std::cout << "memory at end: " << box.currently_used() << " bytes / " << box.memory_limit() << " bytes" << std::endl; - +#endif return 0; } diff --git a/include/sol/stack_field.hpp b/include/sol/stack_field.hpp index 90615874..036ad3ed 100644 --- a/include/sol/stack_field.hpp +++ b/include/sol/stack_field.hpp @@ -29,13 +29,15 @@ #include "stack_get.hpp" #include "stack_check_get.hpp" -namespace sol { -namespace stack { +namespace sol { namespace stack { template struct field_getter { - static constexpr int default_table_index = meta::conditional_t || (std::is_integral_v && !std::is_same_v) - || (std::is_integral_v && !std::is_same_v) || (raw && std::is_void_v>), - std::integral_constant, std::integral_constant> ::value; + static constexpr int default_table_index = meta::conditional_t < meta::is_c_str_v +#if SOL_LUA_VERSION >= 503 + || (std::is_integral_v && !std::is_same_v) +#endif // integer global keys 5.3 or better + || (raw && std::is_void_v>), + std::integral_constant, std::integral_constant> ::value; template void get(lua_State* L, Key&& key, int tableindex = default_table_index) { @@ -61,7 +63,7 @@ namespace stack { if (lua_getmetatable(L, tableindex) == 0) push(L, lua_nil); } - else if constexpr(raw) { + else if constexpr (raw) { if constexpr (std::is_integral_v && !std::is_same_v) { lua_rawgeti(L, tableindex, static_cast(key)); } @@ -69,7 +71,7 @@ namespace stack { else if constexpr (std::is_void_v>) { lua_rawgetp(L, tableindex, key); } -#endif // Lua 5.3.x +#endif // Lua 5.2.x+ else { push(L, std::forward(key)); lua_rawget(L, tableindex); @@ -89,7 +91,7 @@ namespace stack { else if constexpr (std::is_integral_v && !std::is_same_v) { lua_geti(L, tableindex, static_cast(key)); } -#endif // Lua 5.3.x +#endif // Lua 5.3.x+ else { push(L, std::forward(key)); lua_gettable(L, tableindex); @@ -103,7 +105,7 @@ namespace stack { template void apply(std::index_sequence<0, I...>, lua_State* L, Keys&& keys, int tableindex) { get_field(L, std::get<0>(std::forward(keys)), tableindex); - void(detail::swallow { (get_field(L, std::get(std::forward(keys))), 0)... }); + void(detail::swallow{ (get_field(L, std::get(std::forward(keys))), 0)... }); reference saved(L, -1); lua_pop(L, static_cast(sizeof...(I))); saved.push(); @@ -143,9 +145,10 @@ namespace stack { template struct field_setter { - static constexpr int default_table_index = meta::conditional_t<(meta::is_c_str_v || meta::is_string_of_v) || (std::is_integral_v && !std::is_same_v) + static constexpr int default_table_index + = meta::conditional_t < (meta::is_c_str_v || meta::is_string_of_v) || (std::is_integral_v && !std::is_same_v) || (std::is_integral_v && !std::is_same_v) || (raw && std::is_void_v>), - std::integral_constant, std::integral_constant> ::value; + std::integral_constant, std::integral_constant> ::value; template void set(lua_State* L, Key&& key, Value&& value, int tableindex = default_table_index) { @@ -190,7 +193,7 @@ namespace stack { } } #if SOL_LUA_VERSION >= 503 - else if constexpr(std::is_integral_v && !std::is_same_v) { + else if constexpr (std::is_integral_v && !std::is_same_v) { push(L, std::forward(value)); lua_seti(L, tableindex, static_cast(key)); } @@ -240,7 +243,6 @@ namespace stack { lua_pop(L, 1); } }; -} -} // namespace sol::stack +}} // namespace sol::stack #endif // SOL_STACK_FIELD_HPP diff --git a/include/sol/table_proxy.hpp b/include/sol/table_proxy.hpp index 52b787be..f0905b57 100644 --- a/include/sol/table_proxy.hpp +++ b/include/sol/table_proxy.hpp @@ -224,8 +224,9 @@ namespace sol { int push(lua_State* L) const noexcept { if constexpr (std::is_same_v, global_table> || is_stack_table_v>) { auto pp = stack::push_pop(tbl); + int tableindex = pp.index_of(tbl); int top_index = lua_gettop(L); - stack::get_field(lua_state(), key, -1); + stack::get_field(lua_state(), key, tableindex); lua_replace(L, top_index + 1); lua_settop(L, top_index + 1); } diff --git a/single/include/sol/forward.hpp b/single/include/sol/forward.hpp index 3eafdfaf..ca2d772d 100644 --- a/single/include/sol/forward.hpp +++ b/single/include/sol/forward.hpp @@ -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 2019-11-12 17:52:53.774510 UTC -// This header was generated with sol v3.0.3 (revision ce32549) +// Generated 2019-11-13 04:15:36.931580 UTC +// This header was generated with sol v3.0.3 (revision 2ca27ee) // https://github.com/ThePhD/sol2 #ifndef SOL_SINGLE_INCLUDE_FORWARD_HPP diff --git a/single/include/sol/sol.hpp b/single/include/sol/sol.hpp index fad455a8..253a1640 100644 --- a/single/include/sol/sol.hpp +++ b/single/include/sol/sol.hpp @@ -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 2019-11-12 17:52:53.422846 UTC -// This header was generated with sol v3.0.3 (revision ce32549) +// Generated 2019-11-13 04:15:36.384800 UTC +// This header was generated with sol v3.0.3 (revision 2ca27ee) // https://github.com/ThePhD/sol2 #ifndef SOL_SINGLE_INCLUDE_HPP @@ -14254,13 +14254,15 @@ namespace stack { // beginning of sol/stack_field.hpp -namespace sol { -namespace stack { +namespace sol { namespace stack { template struct field_getter { - static constexpr int default_table_index = meta::conditional_t || (std::is_integral_v && !std::is_same_v) - || (std::is_integral_v && !std::is_same_v) || (raw && std::is_void_v>), - std::integral_constant, std::integral_constant> ::value; + static constexpr int default_table_index = meta::conditional_t < meta::is_c_str_v +#if SOL_LUA_VERSION >= 503 + || (std::is_integral_v && !std::is_same_v) +#endif // integer global keys 5.3 or better + || (raw && std::is_void_v>), + std::integral_constant, std::integral_constant> ::value; template void get(lua_State* L, Key&& key, int tableindex = default_table_index) { @@ -14286,7 +14288,7 @@ namespace stack { if (lua_getmetatable(L, tableindex) == 0) push(L, lua_nil); } - else if constexpr(raw) { + else if constexpr (raw) { if constexpr (std::is_integral_v && !std::is_same_v) { lua_rawgeti(L, tableindex, static_cast(key)); } @@ -14294,7 +14296,7 @@ namespace stack { else if constexpr (std::is_void_v>) { lua_rawgetp(L, tableindex, key); } -#endif // Lua 5.3.x +#endif // Lua 5.2.x+ else { push(L, std::forward(key)); lua_rawget(L, tableindex); @@ -14314,7 +14316,7 @@ namespace stack { else if constexpr (std::is_integral_v && !std::is_same_v) { lua_geti(L, tableindex, static_cast(key)); } -#endif // Lua 5.3.x +#endif // Lua 5.3.x+ else { push(L, std::forward(key)); lua_gettable(L, tableindex); @@ -14328,7 +14330,7 @@ namespace stack { template void apply(std::index_sequence<0, I...>, lua_State* L, Keys&& keys, int tableindex) { get_field(L, std::get<0>(std::forward(keys)), tableindex); - void(detail::swallow { (get_field(L, std::get(std::forward(keys))), 0)... }); + void(detail::swallow{ (get_field(L, std::get(std::forward(keys))), 0)... }); reference saved(L, -1); lua_pop(L, static_cast(sizeof...(I))); saved.push(); @@ -14368,9 +14370,10 @@ namespace stack { template struct field_setter { - static constexpr int default_table_index = meta::conditional_t<(meta::is_c_str_v || meta::is_string_of_v) || (std::is_integral_v && !std::is_same_v) + static constexpr int default_table_index + = meta::conditional_t < (meta::is_c_str_v || meta::is_string_of_v) || (std::is_integral_v && !std::is_same_v) || (std::is_integral_v && !std::is_same_v) || (raw && std::is_void_v>), - std::integral_constant, std::integral_constant> ::value; + std::integral_constant, std::integral_constant> ::value; template void set(lua_State* L, Key&& key, Value&& value, int tableindex = default_table_index) { @@ -14415,7 +14418,7 @@ namespace stack { } } #if SOL_LUA_VERSION >= 503 - else if constexpr(std::is_integral_v && !std::is_same_v) { + else if constexpr (std::is_integral_v && !std::is_same_v) { push(L, std::forward(value)); lua_seti(L, tableindex, static_cast(key)); } @@ -14465,8 +14468,7 @@ namespace stack { lua_pop(L, 1); } }; -} -} // namespace sol::stack +}} // namespace sol::stack // end of sol/stack_field.hpp @@ -22577,8 +22579,9 @@ namespace sol { int push(lua_State* L) const noexcept { if constexpr (std::is_same_v, global_table> || is_stack_table_v>) { auto pp = stack::push_pop(tbl); + int tableindex = pp.index_of(tbl); int top_index = lua_gettop(L); - stack::get_field(lua_state(), key, -1); + stack::get_field(lua_state(), key, tableindex); lua_replace(L, top_index + 1); lua_settop(L, top_index + 1); }