lua-users home
lua-l archive

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


Ok here's a simple script and how were running it...  lets assumed its
pre-compiled..

-- our script
print("hello\n")

//-  now our function is this..

static int Print(lua_State *L)
{
    int n=lua_gettop(L);
    int i;

    printf("Running Script Command : Print\n");
    for (i=1; i<=n; i++)
    {
        if (i>1)
            printf("     ");
        if (lua_isstring(L,i))
            printf("%s",lua_tostring(L,i));
        else

printf("%s:%p",lua_typename(L,lua_type(L,i)),lua_topointer(L,i));
    }
    return 0;
}

// - now this function is in a lib, heres the mappings.


static const struct luaL_reg Our_funcs[] =
{
    {"print",Print},
};


LUALIB_API void lua_Ourlibopen (lua_State *L)
{
  luaL_openl(L, Our_funcs);
}

// - to run this pre compiled script were calling... note gLState has been
pre-initialized.
// and some globals (3 in this case) added to it before running these
scripts.

iReturn = lua_dobuffer (gLState,buff,size,name);

// now after doing this our memory prints keep going up.. and taking a look
at the
// check garbage collector it seems that as nblocks is << threshold for this
script
// and when we call lua_dobuffer it runs the protected parser which does
this.

luaC_checkGC(L);
old_blocks = L->nblocks;
status = luaD_runprotected(L, f_parser, &p);
if (status == 0) {
    /* add new memory to threshold (as it probably will stay) */
    L->GCthreshold += (L->nblocks - old_blocks);

// this adding to the threshold constantly makes it luaC_checkGC(L); not
clean up next time around
// until I'm out of memory... so I had to call this after the do_buffer to
fix it.

    lua_setgcthreshold(gLState,1);








-----Original Message-----
From:	owner-lua-l@tecgraf.puc-rio.br [mailto:owner-lua-l@tecgraf.puc-rio.br]
On Behalf Of Roberto Ierusalimschy
Sent:	Friday, January 26, 2001 10:56 AM
To:	Multiple recipients of list
Subject:	Re: .. garbage collection...

> Hi I'm fairly new to lua and just had a quick question for you guys.  I'm
> running a single lua state with a bunch of precompiled small lua scripts.
> Now the problem I had was that a single script never went anywhere close
to
> the default garbage collection threshold.  When running another script
> though the threshold was bumped up once again, this eventually cascades
> until I'm out of memory (small memory model constraints for what I'm
doing).

Could you send us a minimum version of the scripts that reproduce the
problem? That should not happen :-(

-- Roberto