lua-users home
lua-l archive

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


Hello,

I have a problem using the Lua C API. When lua_pcall fails, the error
is pushed on the stack. So when you pop the stack you get the error
but when you count elements in stack you get 0.

#include <lua5.2/lauxlib.h>
#include <lua5.2/lua.h>
#include <lua5.2/lualib.h>

int main()
{
    lua_State *L = luaL_newstate();
    lua_pcall(L, 0, 0, 0);
    printf("%d %s\n", lua_gettop(L), lua_tostring(L, -1));
}

Compile with: gcc main.c `pkg-config --cflags lua5.2` `pkg-config --libs lua5.2`

This program display:
    0 attempt to call a nil value.

The behavior is the same with the 5.1 version.