lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Thank you for your suggestion Patrick, but to be honest, I was only trying Lua out; YAML seems to better fit my needs. I will remember to do proper error checking in the future.



On Wed, Sep 28, 2011 at 6:39 AM, Patrick Rapin <toupie300@gmail.com> wrote:
You do not deal correctly with errors. If the script file have syntax error, lua_pcall will be called on a nil argument, crashing the program.
I take the opportunity to advertize my C++ binding named LuaClassBasedCall[1] on which I worked recently. Version 2.0 will be in fact soon announced.

Using the simple binding, your loadLuaFile function can become very short:

void loadLuaFile (char *filename, int *width, int *height) {
    Lua L;
    L.PCall("dofile(...) return width, height", Input(filename), Outputs(*width, *height));
}

And it will not crash in case of errors. Normally, you have to check the return value of PCall, which is the error message or NULL if no error occured.

[1] https://github.com/prapin/LuaClassBasedCall