lua-users home
lua-l archive

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


I switched on assertion in lua.conf:

#define LUA_USE_APICHECK
#if defined(LUA_USE_APICHECK)
#include <assert.h>
#define luai_apicheck(L,o)    { (void)L; assert(o); }
#else
#define luai_apicheck(L,o)    { (void)L; }
#endif

and wrote small test code in my program
...
 int load_err=luaL_loadfile (code, fileName);
    if (load_err)
    {
        sprintf(lastError, "%s", lua_tostring(code, -1));
        SetState(STATE_STOPPED);
        ShowError();
        return 0;
    }

    luaL_openlibs(code);
...
    int luaErr = lua_pcall(code, 0, 0, 0);
...
    char func_name[256];
    bool res = false;
    for (int i=0; i<30; i++)
    {
        sprintf(func_name, "function_%d", i);
        res = isFunction(code, func_name);
    }
....
bool isFunction(lua_State *lvm, char *functionName)
{
    lua_getglobal (lvm, functionName);

    int type = lua_type(lvm, -1);

    if (type != LUA_TNIL && type == LUA_TFUNCTION)
    {
        return true;
    }
    else
    {
        return false;
    }
}

and it always crashes when i reach 20.