LuaBridge3 icon indicating copy to clipboard operation
LuaBridge3 copied to clipboard

Introduce expected, safety when calling Stack::get without exceptions

Open kunitoki opened this issue 3 years ago • 0 comments

This PR aims at improving safety of interacting with Stack objects:

  • Introduced the luabridge::expected type, that works similarly as http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2021/p0323r10.html, in order to hold the result of luabridge::LuaRef::cast<T> and for holding the result of a luabridge::LuaResult instead of raising an exception (or going UB with exceptions disabled).
  • The previous T luabridge::LuaRef::cast<T> has been preserved with a more explicit name T luabridge::LuaRef::unsafe_cast<T>
  • luabridge::get has been added to mimic luabridge::push.
  • Free function luabridge::LuaRef luabridge::getGlobalRef has been added.

Breaking changes

  • luabridge::Stack<T>::get now takes a std::error_code& as last parameter and should never call luaL_error directly, allowing to be used safely in methods like luabridge::getGlobal or luabridge::get.
  • T luabridge::LuaRef::cast<T> became luabridge::expected<T, std::error_code> LuaRef::cast<T>
  • T luabridge::getGlobal became luabridge::expected<T, std::error_code> luabridge::getGlobal

WIP

  • [ ] Adapt Stack to handle std::error_code
  • [ ] fix Userdata::get to handle std::error_code
  • [ ] fix remaing Stack::get to never call luaL_error

kunitoki avatar Dec 20 '21 22:12 kunitoki