lua-users home
lua-l archive

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


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