-
Notifications
You must be signed in to change notification settings - Fork 41
Proposed mods to callWithHandler
#179
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Proposed mods to callWithHandler
#179
Conversation
I figured out why the null check wasn't working and have now applied a fix. So this PR addresses both of my issues now. |
I also think |
It turns out there is no way to suppress the error return from If we aren't going to throw when there is an error handler present (my preference is that we do throw), then I need a way to create a LuaException from the LuaResult, so that I can throw it myself. |
I have fixed issues that broke the tests and added tests for
Marking ready for review. |
When you use the error handler, the invocation should never throw, it's responsibility of the handler to decide what to do with the error and throw or not depending on the use case. If we always throw, there is no way to call a method without raising exceptions. |
Improved in #180 |
Something else I just discovered is that the error message gets suppressed if the handler is a I was going to add to the test to guarantee that the error message was returned in the LuaResult, but I see you've started your own PR for this. So I'll just flag it here for now. |
Well the error handler should not return anything for luabridge to recover correctly the error message |
The error handler is int-valued. It has to return an integer. |
That's fair, but understand that there is no way to suppress the error return from This will will work okay if I can construct a |
So in theory, the returned value of the error handler should be the one that will be seen by the pcall. When using a std::function, it should return a std::string, and when is a lua_CFunction it must push a string on the stack and return 1. |
This is exactly the way I use it, which is why I would have preferred a throw upon return from
I think this may be misleading, just tracing the Lua code. Yes, the error func is called with the error message on the top of the Lua stack, but the message is also returned on the Lua stack (not the return value of the C function.) Without modifying the stack at all, I've tried returning both 0 and 1 from error functions and seen no difference in behavior. I'm guessing no positive value makes a difference, but I haven't tried it. The Lua code expects the error function always to return an integer. It is possible for the error function to add a new or additional message on the Lua stack, but the error function itself should always be a Lua CFunction. I don't plan to use |
closing, since #180 takes care of it. |
This is a draft PR for discussion purposes. I am trying to address 2 additional issues that I raised in (now closed) #120.
nullptr
.I propose a modification in this PR, but for some reason it doesn't work. When there is an an error, the error code returned bylua_pcall
is 5 ("error in error handling") instead of the actual error. I cannot find any difference in the code path fromcall
vs. callingcallWithHandler
with a null handler. But Lua is obviously seeing one. I'd appreciate your ideas on why this might be.lua_pcall
to know which is which, because if the error is handled, it shouldn't return an error status. If the error is not handled, then theif
block should happen. So there is no need for the conditional. It should always raise the error in the if block. This modification is working for me.Also, a final question. When the error handler is not null, this code is working as I would like it to. My question is if there is a need to clean up the stack that has the error handler pushed on it.