lua-users home
lua-l archive

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


On Tue, Mar 9, 2010 at 10:53 AM, sagasw <sagasw@gmail.com> wrote:
>     for(int i = 0; i < 500; i++)
>     {
>         printf("%d\n", i);
>         loadfile1(LA);
>     }
> ...
> bool loadfile1(lua_State* LA)
> {
>     if(!LA)
>         return false;
>
>     lua_State* LB = lua_newthread(LA);
>     return true;
> }

lua_newthread(LA) will leave the created thread on LA's stack, so your
for loop pushes 500 elements onto the Lua stack. If you ever want to
use more than 20 stack slots, you must call lua_checkstack to ensure
that enough stack slots are allocated. Otherwise, you'll be writing
beyond the end of the stack array, causing bad things like random
crashes.