Skip to content

Commit

Permalink
Fix most of the most pressing warnings
Browse files Browse the repository at this point in the history
- Fixes ThePhD#1000
- Fixes ThePhD#1060
- Fixes ThePhD#1062
- Fixes ThePhD#1067
  • Loading branch information
ThePhD committed Nov 19, 2020
1 parent 6280466 commit ef33531
Show file tree
Hide file tree
Showing 12 changed files with 45 additions and 27 deletions.
2 changes: 1 addition & 1 deletion cmake/Modules/FindLuaBuild/LuaVanilla.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ if (LUA_BUILD_LUA_COMPILER)
endif()
set(LUA_VANILLA_GENERATE_LUA_HPP false)
else()
MESSAGE(WARNING "Using Lua 5.4.0-work1 file list for ${LUA_VERSION} version")
MESSAGE(WARNING "Using Lua 5.4.1 file list for ${LUA_VERSION} version")
set(LUA_VANILLA_LIB_SOURCES lapi.c lauxlib.c lbaselib.c lcode.c lcorolib.c
lctype.c ldblib.c ldebug.c ldo.c ldump.c lfunc.c lgc.c linit.c liolib.c
llex.c lmathlib.c lmem.c loadlib.c lobject.c lopcodes.c loslib.c
Expand Down
2 changes: 1 addition & 1 deletion docs/source/tutorial/all-the-things.rst
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ transferring functions (dumping bytecode)

You can dump the bytecode of a function, which allows you to transfer it to another state (or save it, or load it). Note that bytecode is *typically specific to the Lua version*!

.. literalinclude:: ../../../examples/source//dump.cpp
.. literalinclude:: ../../../examples/source/dump.cpp
:linenos:


Expand Down
4 changes: 2 additions & 2 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ function (MAKE_EXAMPLE example_source_file example_suffix target_sol)

if (MSVC)
target_compile_options(${example_name}
PRIVATE /std:c++latest /EHsc)
PRIVATE /std:c++latest /EHsc /W4)
target_compile_definitions(${example_name}
PRIVATE UNICODE _UNICODE
PRIVATE UNICODE _UNICODE
_CRT_SECURE_NO_WARNINGS _CRT_SECURE_NO_DEPRECATE )
else()
target_compile_options(${example_name}
Expand Down
8 changes: 4 additions & 4 deletions examples/source/dump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
#include "assert.hpp"


int main () {
int main() {
std::cout << "=== dump (serialize between states) ===" << std::endl;

// 2 states, transferring function from 1 to another
sol::state lua;
sol::state lua2;

// we're not going to run the code on the first
// state, so we only actually need
// the base lib on the second state
Expand All @@ -24,10 +24,10 @@ int main () {
c_assert(lr.valid());

// turn it into a function, then dump the bytecode
sol::protected_function target = lr;
sol::protected_function target = lr.get<sol::protected_function>();
sol::bytecode target_bc = target.dump();

// reload the byte code
// reload the byte code
// in the SECOND state
auto result2 = lua2.safe_script(target_bc.as_string_view(), sol::script_pass_on_error);
// check if it was done properly
Expand Down
16 changes: 10 additions & 6 deletions examples/source/script_error_handling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ return 24
// Handling code like this can be robust
// If you disable exceptions, then obviously you would remove
// the try-catch branches,
// and then rely on the `lua_atpanic` function being called
// and then rely on the `lua_atpanic` function being called
// and trapping errors there before exiting the application
{
// script_default_on_error throws / panics when the code is bad: trap the error
Expand All @@ -30,7 +30,8 @@ return 24
c_assert(value == 24);
}
catch (const sol::error& err) {
std::cout << "Something went horribly wrong: thrown error" << "\n\t" << err.what() << std::endl;
std::cout << "Something went horribly wrong: thrown error"
<< "\n\t" << err.what() << std::endl;
}
}

Expand All @@ -45,7 +46,8 @@ return 24
if (!result.valid()) {
sol::error err = result;
sol::call_status status = result.status();
std::cout << "Something went horribly wrong: " << sol::to_string(status) << " error" << "\n\t" << err.what() << std::endl;
std::cout << "Something went horribly wrong: " << sol::to_string(status) << " error"
<< "\n\t" << err.what() << std::endl;
}
}

Expand All @@ -63,19 +65,21 @@ return 24
if (!loaded_chunk.valid()) {
sol::error err = loaded_chunk;
sol::load_status status = loaded_chunk.status();
std::cout << "Something went horribly wrong loading the code: " << sol::to_string(status) << " error" << "\n\t" << err.what() << std::endl;
std::cout << "Something went horribly wrong loading the code: " << sol::to_string(status) << " error"
<< "\n\t" << err.what() << std::endl;
}
else {
// Because the syntax is bad, this will never be reached
c_assert(false);
// If there is a runtime error (lua GC memory error, nil access, etc.)
// it will be caught here
sol::protected_function script_func = loaded_chunk;
sol::protected_function script_func = loaded_chunk.get<sol::protected_function>();
sol::protected_function_result result = script_func();
if (!result.valid()) {
sol::error err = result;
sol::call_status status = result.status();
std::cout << "Something went horribly wrong running the code: " << sol::to_string(status) << " error" << "\n\t" << err.what() << std::endl;
std::cout << "Something went horribly wrong running the code: " << sol::to_string(status) << " error"
<< "\n\t" << err.what() << std::endl;
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions include/sol/demangle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ namespace sol { namespace detail {
{ "operator<", "operator<<", "operator<<=", "operator<=", "operator>", "operator>>", "operator>>=", "operator>=", "operator->", "operator->*" }
};
int level = 0;
std::ptrdiff_t idx = 0;
for (idx = static_cast<std::ptrdiff_t>(realname.empty() ? 0 : realname.size() - 1); idx > 0; --idx) {
std::size_t idx = 0;
for (idx = static_cast<std::size_t>(realname.empty() ? 0 : realname.size() - 1); idx > 0; --idx) {
if (level == 0 && realname[idx] == ':') {
break;
}
Expand Down
4 changes: 2 additions & 2 deletions single/include/sol/config.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-11-19 20:04:06.393002 UTC
// This header was generated with sol v3.2.3 (revision b8aa189e)
// Generated 2020-11-19 21:39:27.536445 UTC
// This header was generated with sol v3.2.3 (revision 62804667)
// https://github.com/ThePhD/sol2

#ifndef SOL_SINGLE_CONFIG_HPP
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-11-19 20:04:06.378005 UTC
// This header was generated with sol v3.2.3 (revision b8aa189e)
// Generated 2020-11-19 21:39:27.514445 UTC
// This header was generated with sol v3.2.3 (revision 62804667)
// 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-11-19 20:04:05.545004 UTC
// This header was generated with sol v3.2.3 (revision b8aa189e)
// Generated 2020-11-19 21:39:26.848444 UTC
// This header was generated with sol v3.2.3 (revision 62804667)
// https://github.com/ThePhD/sol2

#ifndef SOL_SINGLE_INCLUDE_HPP
Expand Down Expand Up @@ -8309,8 +8309,8 @@ namespace sol { namespace detail {
{ "operator<", "operator<<", "operator<<=", "operator<=", "operator>", "operator>>", "operator>>=", "operator>=", "operator->", "operator->*" }
};
int level = 0;
std::ptrdiff_t idx = 0;
for (idx = static_cast<std::ptrdiff_t>(realname.empty() ? 0 : realname.size() - 1); idx > 0; --idx) {
std::size_t idx = 0;
for (idx = static_cast<std::size_t>(realname.empty() ? 0 : realname.size() - 1); idx > 0; --idx) {
if (level == 0 && realname[idx] == ':') {
break;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/regression_tests/simple/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function(CREATE_TEST test_target_name test_name target_sol)

if (MSVC)
target_compile_options(${test_target_name}
PRIVATE /EHsc /std:c++latest)
PRIVATE /EHsc /std:c++latest /W4)
target_compile_definitions(${test_target_name}
PRIVATE UNICODE _UNICODE
_CRT_SECURE_NO_WARNINGS _CRT_SECURE_NO_DEPRECATE)
Expand Down
13 changes: 13 additions & 0 deletions tests/regression_tests/simple/source/1067.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#define SOL_ALL_SAFETIES_ON 1

#include <sol/sol.hpp>

int regression_1067() {
sol::state lua;

lua.open_libraries(sol::lib::base);
lua["fct"] = std::function<int()> { []() { return 42; } };
lua.script("print(fct())");

return 0;
}
5 changes: 3 additions & 2 deletions tests/regression_tests/simple/source/main.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#include <cstddef>

extern int regression_1008();
extern int regression_1000();
extern int regression_1008();
extern int regression_1067();

int main(int, char*[]) {
using f_ptr = int (*)();
const f_ptr regressions[] = { &regression_1008, &regression_1000 };
const f_ptr regressions[] = { &regression_1008, &regression_1000, &regression_1067 };
const int sizeof_regressions = sizeof(regressions) / sizeof(regressions[0]);
int r = 0;
for (std::size_t i = 0; i < sizeof_regressions; ++i) {
Expand Down

0 comments on commit ef33531

Please sign in to comment.