Пример #1
0
static void
thread_prog(cyg_addrword_t data) 
{
    lua_State        *L     = (lua_State *) data;
    lua_ecos_state_t *state = (lua_ecos_state_t *) lua_getuserspace(L);
    int i, n, ref;
   
    // get arguments table size 
    n = luaL_getn(L, 1);

    // push arguments from table 
    for (i = 1; i <= n; i++) 
        lua_rawgeti(L, 1, i);
    lua_remove(L, 1);

    // run program  
    lua_call(L, n, 0);

    ref = state->thread->ref;
    
    // put ourselves into terminated list
    cyg_scheduler_lock();
    {
        state->thread->next = terminated_threads;
        terminated_threads = state->thread;
        state->thread = NULL;
    }
    cyg_scheduler_unlock();

    // unreference the lua thread  
    lua_unref(L, ref);
}
Пример #2
0
void LuaEventHandler::unhandle(){
	if(_handler > 0){
		lua_unref(_lua, _handlerRef);
		_handlerRef = 0;
		_handler = 0;
	}
}
Пример #3
0
static void lxpclose (lua_State *L, lxp_userdata *xpu) {
  lua_unref(L, xpu->tableref);
  xpu->tableref = LUA_REFNIL;
  if (xpu->parser)
    XML_ParserFree(xpu->parser);
  xpu->parser = NULL;
}
Пример #4
0
static void profile_stop(lua_State *L) {
    check_start(L);
    lua_setcallhook(L, NULL); // disable hook
    free_array(get_metadata_array(L), STACK_INDEX);
    lua_unref(L, META_REF); // Remove the old reference (new block of memory).
    PROFILE_INIT = false;
}
Пример #5
0
I32	__timer_destroy(lua_State* ls)
{
	I32 id = -1;
	list_node*node = NULL;
	timer_t body;
	LUA_STACK;
	LUA_WATCH(ls);
	if(lua_gettop(ls) != 1 || lua_type(ls, 1) != LUA_TNUMBER)
	{
		GLog(LT_ERROR, "__timer_destroy : invalid parameters!");
		return 0;
	}
	id = (I32)lua_tointeger(ls, 1);
	memset(&body, 0, sizeof(body));
	body.id = id;
	node = list_find(s_timer_list, &body, __timer_compare);
	if(node != NULL)
	{
		timer_t* timer = list_del(s_timer_list, node);
		if(timer != NULL)
		{
			lua_unref(ls, timer->cb_ref);
			LUA_WATCH(ls);
			FREE(timer);
		}
	}
	return 0;
}
Пример #6
0
void CScriptSystem::ReleaseFunc(HSCRIPTFUNCTION f)
{
    if (f)
    {
        lua_unref(m_pLS, f);
    }
}
Пример #7
0
static void cfTreeSetTableId(void)
{
  Ihandle* ih = iuplua_checkihandle(1);
  int id = luaL_check_int(2);

  lua_Object o3 = lua_getparam(3);
  if(lua_isnil(o3))
  {
		int ref;
		/* Setting in the id table the reference as nil */
		o3 = tree_gettable(ih, id);
		if(o3 != LUA_NOOBJECT)
		  tree_setnumberintable(o3, 0);

    ref = (int)IupTreeGetUserId(ih, id);
    lua_unref(ref);
    lua_pushnumber(IupTreeSetUserId(ih, id, NULL));
  }
  else
  {
    int ref;
    lua_pushobject(o3);
    ref = lua_ref(1);
    lua_pushnumber(IupTreeSetUserId(ih, id, (void*)(ref+1)));
		tree_setnumberintable(o3, ref+1);
  }
} 
Пример #8
0
static void IupSetIdle(void)
{
  lua_Object obj = lua_getparam(1);
  lua_Object old;
  if (idle_ref != 0)
    old = lua_getref(idle_ref);
  else
    old = LUA_NOOBJECT;
  if (lua_isnil(obj)) 
  {
    lua_unref(idle_ref);
    idle_ref = 0;
    IupSetFunction("IDLE_ACTION", (Icallback) NULL);
  } 
  else 
  {
    if (!lua_isfunction(obj) && !lua_iscfunction(obj))
      lua_error("IupSetIdle: parameter must be a function or a cfunction");
    lua_pushobject(obj);
    idle_ref = lua_ref(1);
    IupSetFunction("IDLE_ACTION", (Icallback) default_idle);
  }

  if (old == LUA_NOOBJECT)
    lua_pushnil();
  else
    lua_pushobject(old);
}
Пример #9
0
static void _get_scores_cb(DArray* data) {
	assert(live_scores_req);
	if(data) {
		GameCenterScore* scores = DARRAY_DATA_PTR(*data, GameCenterScore);
		lua_createtable(cb_l, data->size, 0);
		int tbl = lua_gettop(cb_l);

		for(uint i = 0; i < data->size; ++i) {
			GameCenterScore* s = &scores[i];
			_score_to_tbl(cb_l, s);
			lua_rawseti(cb_l, tbl, i+1);
		}
	}
	else {
		// Call with empty table
		lua_createtable(cb_l, 0, 0);
	}

	lua_getref(cb_l, cb_score_ref);
	assert(lua_isfunction(cb_l, -1));
	lua_call(cb_l, 1, 0);	
	lua_unref(cb_l, cb_score_ref);

	live_scores_req = false;
}
Пример #10
0
static int TreeSetUserId(lua_State *L)
{  
  Ihandle *ih = iuplua_checkihandle(L,1);
  int id = luaL_checkinteger(L,2);
  int ref = (int)IupTreeGetUserId(ih, id);
  if (ref != 0) /* userid is not NULL */
  {
    if (ref > 0) ref--; /* only positive references are shifted */

    /* release the previous object referenced there */
    lua_getref(L, ref);
    tree_settableref(L, 4, LUA_NOREF);
    lua_unref(L, ref);
    lua_pop(L, 1);
  }

  if (lua_isnil(L, 3))
    IupTreeSetUserId(ih, id, NULL);
  else
  {
    /* add a new reference */
    lua_pushvalue(L, 3);
    ref = lua_ref(L, 1);
    tree_settableref(L, 3, ref);

    if (ref >= 0) ref++;  /* only positive references are shifted */
    IupTreeSetUserId(ih, id, (void*)ref);
  }

  return 0;
}
Пример #11
0
static void _get_achievements_cb(DArray* data) {
	assert(live_achievements_req);
    
    lua_getref(cb_l, cb_achievement_ref);
	assert(lua_isfunction(cb_l, -1));

	if(data) {
		GameCenterAchievement* achievements = DARRAY_DATA_PTR(*data, GameCenterAchievement);
		lua_createtable(cb_l, data->size, 0);
		int tbl = lua_gettop(cb_l);

		for(uint i = 0; i < data->size; ++i) {
			GameCenterAchievement* a = &achievements[i];
			_achievement_to_tbl(cb_l, a);
			lua_rawseti(cb_l, tbl, i+1);
		}
	}
	else {
		lua_createtable(cb_l, 0, 0);
	}

	lua_call(cb_l, 1, 0);
	lua_unref(cb_l, cb_achievement_ref);

	live_achievements_req = false;
}
Пример #12
0
	inline void unhandle(){
		if(_handler > 0){
			toluafix_remove_function_by_refid(_lua, _handler);
			lua_unref(_lua, _handlerRef);
			_handlerRef = 0;
			_handler = 0;
		}
	}
Пример #13
0
	LuaObject::~LuaObject(void)
	{
		// 解除引用
		if( isvalid() )
		{
			lua_unref( m_state, m_luaobject );
		}
	}
CBaseScripted::~CBaseScripted( void )
{
	// Andrew; This is actually done in CBaseEntity. I'm doing it here because
	// this is the class that initialized the reference.
#ifdef LUA_SDK
	lua_unref( L, m_nTableReference );
#endif
}
Пример #15
0
int Lua_DestroyLuaEvent(lua_State * L)
{
    //Simply remove the reference, CallFunctionByReference will find the reference has been freed and skip any processing.
    int ref = luaL_checkinteger(L,1);
    lua_unref(L,ref);
    g_luaMgr.getFunctionRefs().erase(ref);
    sEventMgr.RemoveEvents(World::getSingletonPtr(),ref+LUA_EVENTS_END);
    return 1;
}
Пример #16
0
static int alien_callback_gc(lua_State *L) {
  ffi_closure *ud = alien_checkcallback(L, 1);
  alien_Callback *ac = (alien_Callback *)ud->user_data;
  lua_unref(ac->L, ac->fn_ref);
  if(ac->params) free(ac->params);
  if(ac->ffi_params) free(ac->ffi_params);
  free_closure(ud);
  return 0;
}
//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
CHL2MPScriptedWeapon::~CHL2MPScriptedWeapon( void )
{
	delete m_pLuaWeaponInfo;
	// Andrew; This is actually done in CBaseEntity. I'm doing it here because
	// this is the class that initialized the reference.
#ifdef LUA_SDK
	lua_unref( L, m_nTableReference );
#endif
}
Пример #18
0
//
// * CloseState
//
// makes script end
//
void CQuestManager::CloseState(QuestState& qs)
{
    if (qs.co)
    {
        //cerr << "ICO "<<qs.ico <<endl;
        lua_unref(L, qs.ico);
        qs.co = 0;
    }
}
Пример #19
0
void JPLua_Event_Shutdown( void )
{
#ifdef JPLUA
	for ( JPLua.currentPlugin = JPLua.plugins;
			JPLua.currentPlugin;
			JPLua.currentPlugin = JPLua.currentPlugin->next
		)
	{
		jplua_plugin_command_t *consoleCmd = JPLua.currentPlugin->consoleCmds, *nextConsoleCmd = consoleCmd;
		jplua_plugin_command_t *serverCmd = JPLua.currentPlugin->serverCmds, *nextServerCmd = serverCmd;

		if ( JPLua.currentPlugin->eventListeners[JPLUA_EVENT_UNLOAD] )
		{//Fire the unload event
			lua_rawgeti( JPLua.state, LUA_REGISTRYINDEX, JPLua.currentPlugin->eventListeners[JPLUA_EVENT_UNLOAD] );
			JPLUACALL( JPLua.state, 0, 0 );
		}

		//RAZTODO: Refcount because multiple plugins can register the same command
		while ( nextConsoleCmd )
		{//Remove all console commands
			lua_unref( JPLua.state, consoleCmd->handle );
			#ifndef OPENJK
				ENG_Cmd_RemoveCommand( consoleCmd->command );
			#endif // !OPENJK
			nextConsoleCmd = consoleCmd->next;

			free( consoleCmd );
			consoleCmd = nextConsoleCmd;
		}

		while ( nextServerCmd )
		{//Remove all server commands
			lua_unref( JPLua.state, serverCmd->handle );
			nextServerCmd = serverCmd->next;

			free( serverCmd );
			serverCmd = nextServerCmd;
		}

		JPLua.currentPlugin->consoleCmds = NULL;
		JPLua.currentPlugin->serverCmds = NULL;
	}
#endif // JPLUA
}
Пример #20
0
CScriptSerializableNode::~CScriptSerializableNode()
{
    for (int i = 0; i < (int)m_children.size(); i++)
    {
        BEHAVIAC_DELETE(m_children)[i];
    }

    lua_State* L = GetScriptState();
    lua_unref(L, m_table);
}
Пример #21
0
void CScriptTable::Attach()
{
    if (m_nRef != NULL_REF)
        lua_unref(L, m_nRef);
    m_nRef = lua_ref(L,1);

#ifdef DEBUG_LUA_STATE
    gAllScriptTables.insert(this);
#endif
}
Пример #22
0
//
// LUA_MarketSetCallback(callback (function))
//
static int LUA_MarketSetCallback(lua_State *lua)
{
	int count = lua_gettop(lua);
	if (count < 1)
	{
		CzScriptEngineLua::DisplayError(lua, "market.setCallback() not enough parameters, expected callback (function)");
		lua_pushboolean(lua, false);
		return 1;
	}

	if (PLATFORM_MARKET->getActiveMarket() == NULL)
	{
		CzScriptEngineLua::DisplayError(lua, "market.purchase() Market has not been created");
		lua_pushboolean(lua, false);
		return 1;
	}

	if (PLATFORM_MARKET->getActiveMarket()->isBusy())
	{
		CzScriptEngineLua::DisplayError(lua, "market.purchase() Market is busy");
		lua_pushboolean(lua, false);
		return 1;
	}

	// Get the callback
	void* callback = NULL;
	if (lua_isfunction(lua, 1))
		callback = (void*)lua_topointer(lua, 1);
	else
	{
		CzScriptEngineLua::DisplayError(lua, "market.purchase() Invalid callback, expected function for Param0");
		lua_pushboolean(lua, false);
		return 1;
	}

	// If previous callback ref set then free it
	CzScriptCallback& cb = PLATFORM_MARKET->getActiveMarket()->getScriptCallback();
	if (cb.Valid)
		lua_unref(((CzScriptEngineLua*)cb.ScriptEngine)->getState(), cb.FunctionRef);

	// Generate a new callback reference to callback function
	int callback_index = luaL_ref(lua, LUA_REGISTRYINDEX);
	cb.FunctionRef = callback_index;
	CzScene* container = (CzScene*)lua->user_data;
	if (container == NULL)
		cb.ScriptEngine = CZ_GLOBAL_RESOURCES->getScriptEngine();
	else
		cb.ScriptEngine = container->getScriptEngine();
	cb.Valid = true;

	lua_pushboolean(lua, true);

	return 1;
}
Пример #23
0
	 void LuaRef::drop()
	 {
		 if (refPtr != NULL)
		 {
			 --(*refPtr);
			 if (*refPtr == 0)
			 {
				lua_unref(L, handle);
				delete refPtr;
			 }
		 }
	 }
Пример #24
0
void LuaEngineMgr::DestroyAllLuaEvents()
{
	CREATE_L_PTR;
	//Clean up for all events.
	set<int>::iterator itr = m_functionRefs.begin();
	for(; itr != m_functionRefs.end(); ++itr)
	{
		sEventMgr.RemoveEvents(World::getSingletonPtr(), (*itr)+LUA_EVENTS_END);
		lua_unref(L, (*itr));
	}
	m_functionRefs.clear();
}
Пример #25
0
static void testC (void) {
#define getnum(s)	((*s++) - '0')
#define getname(s)	(nome[0] = *s++, nome)

  static int locks[10];
  lua_Object reg[10];
  char nome[2];
  char *s = luaL_check_string(1);
  nome[1] = 0;
  for (;;) {
    switch (*s++) {
      case '0': case '1': case '2': case '3': case '4':
      case '5': case '6': case '7': case '8': case '9':
        lua_pushnumber(*(s-1) - '0');
        break;

      case 'c': reg[getnum(s)] = lua_createtable(); break;
      case 'C': { lua_CFunction f = lua_getcfunction(lua_getglobal(getname(s)));
                  lua_pushcclosure(f, getnum(s));
                  break;
                }
      case 'P': reg[getnum(s)] = lua_pop(); break;
      case 'g': { int n=getnum(s); reg[n]=lua_getglobal(getname(s)); break; }
      case 'G': { int n = getnum(s);
                  reg[n] = lua_rawgetglobal(getname(s));
                  break;
                }
      case 'l': locks[getnum(s)] = lua_ref(1); break;
      case 'L': locks[getnum(s)] = lua_ref(0); break;
      case 'r': { int n=getnum(s); reg[n]=lua_getref(locks[getnum(s)]); break; }
      case 'u': lua_unref(locks[getnum(s)]); break;
      case 'p': { int n = getnum(s); reg[n] = lua_getparam(getnum(s)); break; }
      case '=': lua_setglobal(getname(s)); break;
      case 's': lua_pushstring(getname(s)); break;
      case 'o': lua_pushobject(reg[getnum(s)]); break;
      case 'f': lua_call(getname(s)); break;
      case 'i': reg[getnum(s)] = lua_gettable(); break;
      case 'I': reg[getnum(s)] = lua_rawgettable(); break;
      case 't': lua_settable(); break;
      case 'T': lua_rawsettable(); break;
      case 'N' : lua_pushstring(lua_nextvar(lua_getstring(reg[getnum(s)])));
                 break;
      case 'n' : { int n=getnum(s);
                   n=lua_next(reg[n], (int)lua_getnumber(reg[getnum(s)]));
                   lua_pushnumber(n); break;
                 }
      default: luaL_verror("unknown command in `testC': %c", *(s-1));
    }
  if (*s == 0) return;
  if (*s++ != ' ') lua_error("missing ` ' between commands in `testC'");
  }
}
Пример #26
0
int CScriptSystem::GCTagHandler(lua_State* L)
{
    USER_DATA_CHUNK* udc = (USER_DATA_CHUNK*)lua_touserdata(L, 1);

    if (udc)
    {
        BEHAVIAC_DELETE(udc)->userData;
        lua_unref(L, udc->nRef);
        udc->userData = (CDynamicType*)0xDEADBEEF;
    }

    return 0;
}
    //! Creates a new script controller with a new node.
	inline LuaActorState(CoreEngine* engine, int ref) :
        engine_(engine) {
            
        LuaScript* script = static_cast<LuaScript*>(engine_->script());
		lua_State* env = script->env();
		lua_getref(env, ref);
		lua_unref(env, ref);
        
        self_ = luabind::object(luabind::from_stack(env, -1));  
    
		lua_pop(env, 1);
		assert(!lua_gettop(env));
	}
Пример #28
0
static void setlinehook (void) {
  lua_Object f = lua_getparam(1);
  lua_unref(linehook);
  if (f == LUA_NOOBJECT) {
    linehook = -1;
    lua_setlinehook(NULL);
  }
  else {
    lua_pushobject(f);
    linehook = lua_ref(1);
    lua_setlinehook(linef);
  }
}
Пример #29
0
static void setcallhook (void) {
  lua_Object f = lua_getparam(1);
  lua_unref(callhook);
  if (f == LUA_NOOBJECT) {
    callhook = -1;
    lua_setcallhook(NULL);
  }
  else {
    lua_pushobject(f);
    callhook = lua_ref(1);
    lua_setcallhook(callf);
  }
}
Пример #30
0
	LuaObject& LuaObject::operator=( LuaObject& obj )
	{
		if( obj.isvalid() )
		{
			obj.push();
			int luaobject = luaL_ref( obj.m_state, LUA_REGISTRYINDEX );

			if( isvalid() )
			{
				lua_unref( m_state, m_luaobject );
			}
			m_state		= obj.m_state;
			m_luaobject = luaobject;
		}
		return *this;
	}