lua-users home
lua-l archive

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


I'm writing some code which prepares the Lua stack and then calls a
function. It's essential to me that Lua never exits the application,
so I need to have a panic function replacing the standard one.

Given that I have a panic function, is there any benefit to using
lua_pcall over lua_call?

Specifically, my code goes something like:

    if (setjmp(my_buf) != 0)
        /* Return from an error */
    oldpanic = lua_atpanic(L, my_error_handler);
    lua_pushXXX /* Setting up the stack, etc */
    error = luaL_loadbuffer(L, ..);
    error = error || lua_pcall(L, ...);
    if (error) {
        /* Print the error */
        lua_atpanic(L, oldpanic);
        /* Return from an error */
    }
    lua_atpanic(L, oldpanic);
    /* Normal return */

In this situation, is there any value in lua_pcall, or can I just use
lua_call? Would the following be just as good?

    if (setjmp(my_buf) != 0)
        /* Return from an error */
    oldpanic = lua_atpanic(L, my_error_handler);
    lua_pushXXX /* Setting up the stack, etc */
    if (luaL_loadbuffer(L, ..))
        lua_error(L);
    lua_call(L, ...);
    lua_atpanic(L, oldpanic);
    /* Normal return */

The control flow is certainly cleaner.

Paul.