[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: getglobal with variable that does not exist
- From: Eike Decker <eike@...>
- Date: Fri, 4 Jul 2008 10:53:37 +0200
You are flooding the stack with nil values:
> lua_getglobal(L,"timer"); //line 826
> if(!lua_isfunction(L,-1))
> {
> mutex=1;
> return;
> }
gets a global (that does not exist) from the stack and return. And again and
again, until (doesn't need so many iterations) the stack is full.
You need to pop off the value you push on the stack before returning (or setting
the stack size to 0 when starting), i.e.
> lua_settop(L,0);// stackreset (a bit ugly, but gets the job done in any case)
> lua_getglobal(L,"timer"); //line 826
eike
> What if I call lua_getglobal in c to the variables that does not exist in
> lua script, what will happen?
>
> I am calling Lua function from C, every second
> Here is my code:
> void UCSimScript::TimerSignal()
> {
> GetMutex();
> //get the function!
> lua_getglobal(L,"timer"); //line 826
> if(!lua_isfunction(L,-1))
> {
> mutex=1;
> return;
> }
> if ( lua_pcall(L, 0, 0, 0)!=0 )
> {
> Lua_Error("error: %s\n",lua_tostring(L, -1));
> }
> mutex=1;
>
> }
>
> but my lua script does not have the timer(), initially, it does not trigger
> any errors But after few hours, i get segmentation fault. with below are the
> traceback from gdb.
>
> Core was generated by `./HostSim -w sim.lua'.
> Program terminated with signal 11, Segmentation fault.
> #0 0x080af44d in luaV_gettable ()
> (gdb) bt
> #0 0x080af44d in luaV_gettable ()
> #1 0x080a5a0d in lua_getfield ()
> #2 0x0808e176 in UCSimScript::TimerSignal (this=0x80dd710) at
> src/UCSimScript.cpp:826
> #3 0x08070959 in TimerCB () at src/main.cpp:82
> #4 0x080a3a49 in TimerThread (data_ptr=0x80dd720) at
> ucstdlib/ttimer.cpp:318
> #5 0x005a550b in start_thread () from /lib/libpthread-2.7.so
> #6 0x004e6b2e in clone () from /lib/libc-2.7.so
>
> -------------------------------------------------------------------
>
>
>
> Hean Kuan Ong
> http://linux.byexamples.com
> http://cc.byexamples.com
> http://wordpress.byexamples.com
>