gracefully handling lua foulness..
hey all:
In previous posts, many of you were quite helpful in getting lua built, and integrated into my current codebase. Everything works hunky dory, except for one thing: when my c++ code executes a lua script that contains lua code with syntax errors , or just does something the lua interpreter simply doesnt like, it crashes my c++ code.
There must be some way to catch script errors from lua, and handle them gracefully. I''d imagine the lua interpreter, upon running a script with errors, must return with some sort of error message like "invalid script" or an error code...can I trap this in my code? Remember that since the core system is c++, simply handling exceptions within a lua script is not a suitable answer.
thanks!!
neko
nekoflux
If you find this, I''m interested. It''s the final straw that made me quit lua.
As mentioned in the manual, you can use lua_pcall() to explicitly specify an error handling function. If you don't, though, the lua_call() will simply return an error code. I'm guessing that the reason your program is crashing is because you aren't checking for that error code.
EDIT: if you're talking about errors produced by lua_load and its relatives, those functions also return error codes, which you should check for.
"Sneftel is correct, if rather vulgar." --Flarelocke
[edited by - sneftel on March 1, 2004 11:07:27 PM]
EDIT: if you're talking about errors produced by lua_load and its relatives, those functions also return error codes, which you should check for.
"Sneftel is correct, if rather vulgar." --Flarelocke
[edited by - sneftel on March 1, 2004 11:07:27 PM]
My problems with LUA simply aborted my app when it encountered some internal error. No warning, no returns, nothing.
Lua gracefully handles errors in scripts, but on the C/C++ side you're expected not to do error-causing things like overrunning the stack. IIRC, there are macros you can set in the Lua headers to help you find some of these bugs in your program, basically runtime assertions you can add.
EDIT: also, if you don't really feel comfortable with the Lua C/C++ interface (it is rather alien to a lot of programmers) the use of binding generators like SWIG and tolua will reduce the amount of direct API access you need to do.
"Sneftel is correct, if rather vulgar." --Flarelocke
[edited by - sneftel on March 1, 2004 11:12:23 PM]
EDIT: also, if you don't really feel comfortable with the Lua C/C++ interface (it is rather alien to a lot of programmers) the use of binding generators like SWIG and tolua will reduce the amount of direct API access you need to do.
"Sneftel is correct, if rather vulgar." --Flarelocke
[edited by - sneftel on March 1, 2004 11:12:23 PM]
I was using a wrapper and the app bombed when attempting to compile a script. It didn''t seem as graceful as the manual said.
another option is LuaBind which throws exceptions when things go screawy
quote: Original post by downgradedWhat wrapper were you using? There are, unfortunately, some rather low-quality wrappers out there.
I was using a wrapper and the app bombed when attempting to compile a script. It didn''t seem as graceful as the manual said.
"Sneftel is correct, if rather vulgar." --Flarelocke
I''m curently using luabind, but have been unable to locate any resources on how to prevent my engine from crashing whilst appempting to execute a malformed lua script.
any thoughts?
Im so close...
any thoughts?
Im so close...
nekoflux
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement