Пример #1
0
CLuaTimer* CLuaTimerManager::AddTimer ( const CLuaFunctionRef& iLuaFunction, CTickCount llTimeDelay, unsigned int uiRepeats, const CLuaArguments& Arguments )
{
    // Check for the minimum interval
    if ( llTimeDelay.ToLongLong () < LUA_TIMER_MIN_INTERVAL )
        return NULL;

    if ( VERIFY_FUNCTION ( iLuaFunction ) )
    {
        // Add the timer
        CLuaTimer* pLuaTimer = new CLuaTimer ( iLuaFunction, Arguments );
        pLuaTimer->SetStartTime ( CTickCount::Now () );
        pLuaTimer->SetDelay ( llTimeDelay );
        pLuaTimer->SetRepeats ( uiRepeats );
        m_TimerList.push_back ( pLuaTimer );
        return pLuaTimer;
    }

    return NULL;
}
Пример #2
0
CLuaTimer* CLuaTimerManager::AddTimer ( lua_State* luaVM )
{
    if ( luaVM )
    {
        int iArgument2 = lua_type ( luaVM, 2 );
        int iArgument3 = lua_type ( luaVM, 3 );
        if ( lua_type ( luaVM, 1 ) &&
             (( iArgument2 == LUA_TNUMBER || iArgument2 == LUA_TSTRING ) ||
              ( iArgument3 == LUA_TNUMBER || iArgument3 == LUA_TSTRING ) ))
        {
            // Grab the string argument, start-time, delay and repeats
            unsigned long ulTimeDelay = static_cast < unsigned long > ( lua_tonumber ( luaVM, 2 ) );
            unsigned int uiRepeats = static_cast < unsigned int > ( lua_tonumber ( luaVM, 3 ) );

            // Check for the minimum interval
            if ( ulTimeDelay < LUA_TIMER_MIN_INTERVAL ) return NULL;

            // Grab the arguments from argument 4 and up
            CLuaArguments Arguments;
            Arguments.ReadArguments ( luaVM, 4 );

            int iLuaFunction = luaM_toref ( luaVM, 1 );

            if ( iLuaFunction != LUA_REFNIL )
            {
                // Add the timer
                CLuaTimer* pLuaTimer = new CLuaTimer ( iLuaFunction, Arguments );
                pLuaTimer->SetStartTime ( GetTime () );
                pLuaTimer->SetDelay ( ulTimeDelay );
                pLuaTimer->SetRepeats ( uiRepeats );
                m_TimerList.push_back ( pLuaTimer );
                return pLuaTimer;
            }
        }
    }
    return false;
}