C++ error handling #1635
Replies: 3 comments 1 reply
-
You can catch |
Beta Was this translation helpful? Give feedback.
-
We plan to make This will make it match the documentation of Lua 5.1 better ("It returns false if it cannot grow the stack to that size") even though Lua 5.1 did not implement this guarantee for allocation failure. Lua 5.2 extended the documentation to explicitly call this out ("or because it cannot allocate memory for the new stack size") and implement handling for it. We'll post an update when it's implemented. |
Beta Was this translation helpful? Give feedback.
-
You can now use |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
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