development/Common/Utility/source/Script/bind_timer.cpp
// will return timer object which then can be manipulated
// and used
will return timer object which then can be manipulated
and used
will return timer object which then can be manipulated and used
int timer(lua_State* L)    
    {
        float rate = 0;
        bool repeat = false;
        int numValues = lua_gettop(L);
        if (numValues)
        {
            if (lua_isboolean(L, -1))
            {
                repeat = lua_toboolean(L, -1) == 1;
            }
            else if (lua_isnumber(L, -1))
            {
                rate = lua_tonumber(L, -1);
            }
            else
            {
                return luaL_error(L, "Invalid second value passed to timer [rate|repeat]");
            }
            if (numValues > 1)
            {
                if (lua_isboolean(L, -2))
                {
                    repeat = lua_toboolean(L, -2) == 1;
                }
                else if (lua_isnumber(L, -2))
                {
                    rate = lua_tonumber(L, -2);
                }
                else
                {
                    return luaL_error(L, "Invalid first value passed to timer [rate|repeat]");
                }
            }
        }
        if (!Timers)
        {
            luabind::object g = luabind::globals(L);
            luabind::object lua_yaget = luabind::gettable(g, "yaget");
            Dispatcher *dsp = luabind::object_cast<Dispatcher *>(lua_yaget["dsp"]);
            Timers.reset(new LuaTimers(*dsp));
        }
        LuaTimers::Functor functor;
        functor.rate = rate;
        functor.repeat = repeat;
        size_t index = Timers->nextIndex();
        size_t *conUserData = (size_t *)lua_newuserdata(L, sizeof(size_t));
        *conUserData = index;
        (*Timers)[index] = functor;
        luaL_getmetatable(L, "yaget.dispatcher.timer");                 , mt
        lua_setmetatable(L, -2);                                        
        return 1;
    }
int timer ( lua_State * L ) { float rate = 0 ; bool repeat = false ; int numValues = lua_gettop ( L ) ; if ( numValues ) { if ( lua_isboolean ( L , -1 ) ) { repeat = lua_toboolean ( L , -1 ) == 1 ; } else if ( lua_isnumber ( L , -1 ) ) { rate = lua_tonumber ( L , -1 ) ; } else { return luaL_error ( L , " " ) ; } if ( numValues > 1 ) { if ( lua_isboolean ( L , -2 ) ) { repeat = lua_toboolean ( L , -2 ) == 1 ; } else if ( lua_isnumber ( L , -2 ) ) { rate = lua_tonumber ( L , -2 ) ; } else { return luaL_error ( L , " " ) ; } } } if ( ! Timers ) { luabind :: object g = luabind :: globals ( L ) ; luabind :: object lua_yaget = luabind :: gettable ( g , " " ) ; Dispatcher * dsp = luabind :: object_cast < Dispatcher * > ( lua_yaget [ " " ] ) ; Timers . reset ( new LuaTimers ( * dsp ) ) ; } LuaTimers :: Functor functor ; functor . rate = rate ; functor . repeat = repeat ; size_t index = Timers -> nextIndex ( ) ; size_t * conUserData = ( size_t * ) lua_newuserdata ( L , sizeof ( size_t ) ) ; * conUserData = index ; ( * Timers ) [ index ] = functor ; luaL_getmetatable ( L , " " ) ; lua_setmetatable ( L , -2 ) ; return 1 ; }
will return timer object which then can be manipulated
and used
will return timer object which then can be manipulated and used
// rate, repeat (or any combination of number, boolean) // name, udata // name, udata, mt // name, udata // return the user data