mirror of
https://github.com/ThePhD/sol2.git
synced 2024-03-22 13:10:44 +08:00
Fix slight error when error handler was called and the result wasn't properly moved.
This commit is contained in:
parent
91aff613bc
commit
fb06c8a754
|
@ -27,14 +27,33 @@ int main() {
|
||||||
// You can just pass it through to let the call-site handle it
|
// You can just pass it through to let the call-site handle it
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
// the above lambda is identical to sol::simple_on_error, but it's
|
||||||
|
// shown here to show you can write whatever you like
|
||||||
|
|
||||||
|
//
|
||||||
|
{
|
||||||
auto result = lua.script("print('hello hello again, world') \n return 24", simple_handler);
|
auto result = lua.script("print('hello hello again, world') \n return 24", simple_handler);
|
||||||
if (result.valid()) {
|
if (result.valid()) {
|
||||||
std::cout << "the code worked, and a double-hello statement should appear above this one!" << std::endl;
|
std::cout << "the third script worked, and a double-hello statement should appear above this one!" << std::endl;
|
||||||
int value = result;
|
int value = result;
|
||||||
assert(value == 24);
|
assert(value == 24);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
std::cout << "the code failed, check the result type for more information!" << std::endl;
|
std::cout << "the third script failed, check the result type for more information!" << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
auto result = lua.script("does.not.exist", simple_handler);
|
||||||
|
if (result.valid()) {
|
||||||
|
std::cout << "the fourth script worked, which it wasn't supposed to! Panic!" << std::endl;
|
||||||
|
int value = result;
|
||||||
|
assert(value == 24);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
sol::error err = result;
|
||||||
|
std::cout << "the fourth script failed, which was intentional!\t\nError: " << err.what() << std::endl;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
|
|
|
@ -20,8 +20,8 @@
|
||||||
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
// This file was generated with a script.
|
// This file was generated with a script.
|
||||||
// Generated 2017-03-31 21:37:49.518087 UTC
|
// Generated 2017-04-01 02:39:08.628086 UTC
|
||||||
// This header was generated with sol v2.16.0 (revision 1e367ab)
|
// This header was generated with sol v2.16.0 (revision 91aff61)
|
||||||
// https://github.com/ThePhD/sol2
|
// https://github.com/ThePhD/sol2
|
||||||
|
|
||||||
#ifndef SOL_SINGLE_INCLUDE_HPP
|
#ifndef SOL_SINGLE_INCLUDE_HPP
|
||||||
|
@ -921,7 +921,7 @@ extern "C" {
|
||||||
|
|
||||||
/* LuaJIT does not have the updated error codes for thread status/function returns */
|
/* LuaJIT does not have the updated error codes for thread status/function returns */
|
||||||
#ifndef LUA_ERRGCMM
|
#ifndef LUA_ERRGCMM
|
||||||
#define LUA_ERRGCMM (LUA_ERRERR + 1)
|
#define LUA_ERRGCMM (LUA_ERRERR + 2)
|
||||||
#endif // LUA_ERRGCMM
|
#endif // LUA_ERRGCMM
|
||||||
|
|
||||||
/* LuaJIT does not support continuation contexts / return error codes? */
|
/* LuaJIT does not support continuation contexts / return error codes? */
|
||||||
|
@ -7204,7 +7204,7 @@ namespace sol {
|
||||||
if (count < 1)
|
if (count < 1)
|
||||||
return;
|
return;
|
||||||
int top = lua_gettop(L);
|
int top = lua_gettop(L);
|
||||||
if (index == -1 || top == index) {
|
if (index == -count || top == index) {
|
||||||
// Slice them right off the top
|
// Slice them right off the top
|
||||||
lua_pop(L, static_cast<int>(count));
|
lua_pop(L, static_cast<int>(count));
|
||||||
return;
|
return;
|
||||||
|
@ -12731,7 +12731,11 @@ namespace sol {
|
||||||
return kb;
|
return kb;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline protected_function_result default_on_error( lua_State* L, const protected_function_result& pfr ) {
|
inline protected_function_result simple_on_error(lua_State*, sol::protected_function_result result) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline protected_function_result default_on_error( lua_State* L, protected_function_result pfr ) {
|
||||||
type t = type_of(L, pfr.stack_index());
|
type t = type_of(L, pfr.stack_index());
|
||||||
std::string err = to_string(pfr.status()) + " error";
|
std::string err = to_string(pfr.status()) + " error";
|
||||||
if (t == type::string) {
|
if (t == type::string) {
|
||||||
|
@ -12953,7 +12957,7 @@ namespace sol {
|
||||||
protected_function_result script(const std::string& code, Fx&& on_error) {
|
protected_function_result script(const std::string& code, Fx&& on_error) {
|
||||||
protected_function_result pfr = do_string(code);
|
protected_function_result pfr = do_string(code);
|
||||||
if (!pfr.valid()) {
|
if (!pfr.valid()) {
|
||||||
return on_error(L, pfr);
|
return on_error(L, std::move(pfr));
|
||||||
}
|
}
|
||||||
return pfr;
|
return pfr;
|
||||||
}
|
}
|
||||||
|
@ -12962,7 +12966,7 @@ namespace sol {
|
||||||
protected_function_result script_file(const std::string& filename, Fx&& on_error) {
|
protected_function_result script_file(const std::string& filename, Fx&& on_error) {
|
||||||
protected_function_result pfr = do_file(filename);
|
protected_function_result pfr = do_file(filename);
|
||||||
if (!pfr.valid()) {
|
if (!pfr.valid()) {
|
||||||
return on_error(L, pfr);
|
return on_error(L, std::move(pfr));
|
||||||
}
|
}
|
||||||
return pfr;
|
return pfr;
|
||||||
}
|
}
|
||||||
|
|
|
@ -109,7 +109,7 @@ namespace sol {
|
||||||
if (count < 1)
|
if (count < 1)
|
||||||
return;
|
return;
|
||||||
int top = lua_gettop(L);
|
int top = lua_gettop(L);
|
||||||
if (index == -1 || top == index) {
|
if (index == -count || top == index) {
|
||||||
// Slice them right off the top
|
// Slice them right off the top
|
||||||
lua_pop(L, static_cast<int>(count));
|
lua_pop(L, static_cast<int>(count));
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -52,7 +52,11 @@ namespace sol {
|
||||||
return kb;
|
return kb;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline protected_function_result default_on_error( lua_State* L, const protected_function_result& pfr ) {
|
inline protected_function_result simple_on_error(lua_State*, sol::protected_function_result result) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline protected_function_result default_on_error( lua_State* L, protected_function_result pfr ) {
|
||||||
type t = type_of(L, pfr.stack_index());
|
type t = type_of(L, pfr.stack_index());
|
||||||
std::string err = to_string(pfr.status()) + " error";
|
std::string err = to_string(pfr.status()) + " error";
|
||||||
if (t == type::string) {
|
if (t == type::string) {
|
||||||
|
@ -274,7 +278,7 @@ namespace sol {
|
||||||
protected_function_result script(const std::string& code, Fx&& on_error) {
|
protected_function_result script(const std::string& code, Fx&& on_error) {
|
||||||
protected_function_result pfr = do_string(code);
|
protected_function_result pfr = do_string(code);
|
||||||
if (!pfr.valid()) {
|
if (!pfr.valid()) {
|
||||||
return on_error(L, pfr);
|
return on_error(L, std::move(pfr));
|
||||||
}
|
}
|
||||||
return pfr;
|
return pfr;
|
||||||
}
|
}
|
||||||
|
@ -283,7 +287,7 @@ namespace sol {
|
||||||
protected_function_result script_file(const std::string& filename, Fx&& on_error) {
|
protected_function_result script_file(const std::string& filename, Fx&& on_error) {
|
||||||
protected_function_result pfr = do_file(filename);
|
protected_function_result pfr = do_file(filename);
|
||||||
if (!pfr.valid()) {
|
if (!pfr.valid()) {
|
||||||
return on_error(L, pfr);
|
return on_error(L, std::move(pfr));
|
||||||
}
|
}
|
||||||
return pfr;
|
return pfr;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user