C++ error handling #1635
Unanswered
PonasKovas
asked this question in
Q&A
Replies: 1 comment 1 reply
-
You can catch |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello, I'm trying to work with the C++ interface of Luau and I'm wondering about the error handling.
As I understand, the correct procedure is to use
lua_pcall
, but for that (forgive me if I get something wrong, I'm still only getting familiarised with lua and luau) you need to push your function that you need to call to the stack, along with it's arguments, right?But isn't pushing to the stack fallible in itself (out of memory errors)? From the Lua spec I understand that whenever lua calls C, it guarantees at least
LUA_MINSTACK = 20
free stack spaces, but obviously (though not documented) pushing something like a string will need an extra allocation which might fail.So to safely (handling the errors) call a your own API function like
lua_create_table
, which (though undocumented, but I assume) is fallible due to allocations and might throw, I need to make a wrapper C++ function that calls it, push it to the stack (which is fallible in itself) along with the arguments, and then calllua_pcall
?It seems for me that this whole system is very convoluted (and I understand this is original lua legacy), but since luau is rewritten in C++ and you're already using C++ exceptions internally, why not expose the
luau_exception
class and let C++ users justcatch
the errors instead of going through all these hoops?Beta Was this translation helpful? Give feedback.
All reactions