codea runtime

I am new to this interesting platform. Recently I am trying to implement the codea into Xcode using runtime, where I encountered this strange problem: although the code runs no problem in ipad codea app, the xcode always gives me error of bad access. I follows exactly the same procedure as described and have the newest version of both xcode, code app, and runtime library.

here is the place where xcode throws the warning (in lapi.c) :
LUA_API int lua_setfenv (lua_State *L, int idx){
StkId o;
int res=1;

if (res) luaC_objbarrier(L,gcvalue(o),hvalue(L->top-1)) <------- bad access


I also notice that if I did not call any function in main from other classes, the runtime works fine.

Hope someone could help me with this!