lua-users home
lua-l archive

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


Hi,

Is it possible to check in C if a requested table entry is present before 
(after?) calling the lua_gettable()? I want to get the function from the 
script and call it if it exists, so I'm doing the following:

    lua_getglobal(LuaState, "some_func"); // The macro calling lua_gettable()
    if (!lua_isfunction(LuaState, -1))
        return; // No such function in the script?
    int r=lua_pcall(LuaState, 0, 0, 0);

and the program crashes somewhere in lua_pcall() if the function some_func() 
is absent in the script. I thought the if () statement above would avoid 
this. What's wrong in my code?

Regards, Dmitry Samoyloff