[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: getglobal with variable that does not exist
- From: "Ong hean kuan" <mysurface@...>
- Date: Fri, 4 Jul 2008 15:41:55 +0800
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