1

I have a config file from a previous version of my software, the config file is basically a Lua script. I'm using swig to generate the wrapper to interface with the C API of my software.

The problem that I'm having is that some instructions in the previous config file was removed in the current version of the software.

When I load and run the Lua file the execution stop at the first error and the rest of the config file is not executed.

How can I make Lua report an error and continue the script execution at the next instruction?

1
  • BTW, it's Lua not LUA. It's not an acronym, just to give you a heads up. Commented Jan 9, 2012 at 8:28

1 Answer 1

2

You might want to take a look at the error handling section in the Lua Manual (look here for version5.1 ).

It all boils down to putting the "sensitive" code into a function and call it with pcall.

More info on handling errors in Programming in Lua

Sign up to request clarification or add additional context in comments.

2 Comments

Im using the following code: if( luaL_dostring( L, code ) ) { printf( "error:%s\n", lua_tostring( L, -1 ) ); lua_pop( L, 1 ); } Once an error is encountered how can I give the go to resume/continue with the next Lua instruction in the variable code (which is quite a huge block), after the error. I can't really parse the Lua instructions in the variable code since there is some if, function etc... I really have to tell Lua to continue the execution of the script even if an error is found. Is this possible?
No. Like that it's not possible. You should wrap the code that can error in a pcall. Once an error occures, it's only logical Lua can't continue executing the chunk, and it will drop out of the pcall. Execution will be resumed only after the pcall. So you need to dive into the Lua code.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.