lua-users home
lua-l archive

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

> lua.c defines a function for opening all standard libraries. Here is the

> static void openstdlibs (lua_State *l) {
>  const luaL_reg *lib = lualibs;
>  /*lua_checkstack(l, 1000); <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
>  for (; lib->func; lib++) {
>    lib->func(l);  /* open library */
>    lua_settop(l, 0);  /* discard any results */
>  }
> }

> I added the line marked by'<<<<...'.

Why? (Just curious.)

> Uncommenting this line leads to a failed assert in traversestack()
(line:245 / lgc.c)
> while still in openstdlibs above. Basically, growing Lua stack to a much
larger size
> than what Lua creates by default causes some kind of a problem.

I'm just guessing but I think the actual statement is "growing Lua stack to
a much
larger size than *you are using* causes some kind of a problem"

> Is this a problem indeed or am I misusing lua_checkstack?

You should always check the return value of lua_checkstack. (It may fail.)
However, this is not the problem in this case.

I'm curious about the check in line 247 of lgc.c, which excludes C frames.
In the case where a C function had reserved a huge stack and not used it
(so that its stack top was still considerably below the stack limit), and a
garbage collection happens, would that not result in the stack being shrunk
in checkstacksizes()? (at least if the reservation were at least four times
the size of the actually used portion of the stack at that point) and
thereby lead to the phenomenon that Alex notes?


"Milking It", Oxfam's first online resource for secondary schools, is now
live. Find out how Oxfam is encouraging young people to learn about trade
and dumping.

Oxfam works with others to find lasting solutions to poverty and suffering.

Oxfam GB is a member of Oxfam International, a company limited by guarantee and registered in England No. 612172.
Registered office: 274 Banbury Road, Oxford OX2 7DZ.
Registered charity No. 202918.

Visit the web site at