mirror of
https://github.com/ThePhD/sol2.git
synced 2024-03-22 13:10:44 +08:00
error detection for coroutine and protected function
This commit is contained in:
parent
33e846602b
commit
6a3b0adf0d
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -67,3 +67,4 @@ main.exe
|
||||||
main.o
|
main.o
|
||||||
lua-5.3.3/
|
lua-5.3.3/
|
||||||
*.pdf
|
*.pdf
|
||||||
|
main.lua
|
||||||
|
|
|
@ -63,6 +63,9 @@ namespace sol {
|
||||||
luacall(n, LUA_MULTRET);
|
luacall(n, LUA_MULTRET);
|
||||||
int poststacksize = lua_gettop(lua_state());
|
int poststacksize = lua_gettop(lua_state());
|
||||||
int returncount = poststacksize - (firstreturn - 1);
|
int returncount = poststacksize - (firstreturn - 1);
|
||||||
|
if (error()) {
|
||||||
|
return protected_function_result(lua_state(), lua_absindex(lua_state(), -1), 1, returncount, status());
|
||||||
|
}
|
||||||
return protected_function_result(lua_state(), firstreturn, returncount, returncount, status());
|
return protected_function_result(lua_state(), firstreturn, returncount, returncount, status());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -64,8 +64,8 @@ namespace sol {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
int luacall(std::ptrdiff_t argcount, std::ptrdiff_t resultcount, handler& h) const {
|
call_status luacall(std::ptrdiff_t argcount, std::ptrdiff_t resultcount, handler& h) const {
|
||||||
return lua_pcallk(base_t::lua_state(), static_cast<int>(argcount), static_cast<int>(resultcount), h.stackindex, 0, nullptr);
|
return static_cast<call_status>(lua_pcallk(base_t::lua_state(), static_cast<int>(argcount), static_cast<int>(resultcount), h.stackindex, 0, nullptr));
|
||||||
}
|
}
|
||||||
|
|
||||||
template<std::size_t... I, typename... Ret>
|
template<std::size_t... I, typename... Ret>
|
||||||
|
@ -104,9 +104,12 @@ namespace sol {
|
||||||
};
|
};
|
||||||
try {
|
try {
|
||||||
#endif // No Exceptions
|
#endif // No Exceptions
|
||||||
code = static_cast<call_status>(luacall(n, LUA_MULTRET, h));
|
code = luacall(n, LUA_MULTRET, h);
|
||||||
int poststacksize = lua_gettop(base_t::lua_state());
|
int poststacksize = lua_gettop(base_t::lua_state());
|
||||||
returncount = poststacksize - (stacksize - 1);
|
returncount = poststacksize - (stacksize - 1);
|
||||||
|
if (code != call_status::yielded && != call_status::ok) {
|
||||||
|
return protected_function_result(base_t::lua_state(), lua_absindex(base_t::lua_state(), -1), returncount, returncount, code);
|
||||||
|
}
|
||||||
#ifndef SOL_NO_EXCEPTIONS
|
#ifndef SOL_NO_EXCEPTIONS
|
||||||
}
|
}
|
||||||
// Handle C++ errors thrown from C++ functions bound inside of lua
|
// Handle C++ errors thrown from C++ functions bound inside of lua
|
||||||
|
|
Loading…
Reference in New Issue
Block a user