mirror of
https://github.com/ThePhD/sol2.git
synced 2024-03-22 13:10:44 +08:00
Fix most of the most pressing warnings
- Fixes #1000 - Fixes #1060 - Fixes #1062 - Fixes #1067
This commit is contained in:
parent
62804667ee
commit
ef33531df4
|
@ -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
|
||||
|
|
|
@ -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:
|
||||
|
||||
|
||||
|
|
|
@ -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}
|
||||
|
|
|
@ -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
|
||||
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
13
tests/regression_tests/simple/source/1067.cpp
Normal file
13
tests/regression_tests/simple/source/1067.cpp
Normal file
|
@ -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;
|
||||
}
|
|
@ -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[] = { ®ression_1008, ®ression_1000 };
|
||||
const f_ptr regressions[] = { ®ression_1008, ®ression_1000, ®ression_1067 };
|
||||
const int sizeof_regressions = sizeof(regressions) / sizeof(regressions[0]);
|
||||
int r = 0;
|
||||
for (std::size_t i = 0; i < sizeof_regressions; ++i) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user