Ejemplo n.º 1
0
static cxInt cxLoadingLuaSetObject(lua_State *L)
{
    CX_LUA_DEF_THIS(cxLoading);
    cxObject any = CX_LUA_GET_PTR(2);
    cxLoadingSetObject(this, any);
    return 0;
}
Ejemplo n.º 2
0
static cxInt cxViewLuaAppendAction(lua_State *L)
{
    CX_LUA_DEF_THIS(cxView);
    cxAction action = CX_LUA_GET_PTR(2);
    cxUInt id = cxViewAppendAction(this, action);
    lua_pushnumber(L, id);
    return 1;
}
Ejemplo n.º 3
0
static cxInt cxViewLuaAppendView(lua_State *L)
{
    CX_LUA_DEF_THIS(cxView);
    cxViewAppend(this, CX_LUA_GET_PTR(2));
    return 0;
}
Ejemplo n.º 4
0
static cxInt cxEventAction(lua_State *L)
{
    CX_LUA_DEF_THIS(cxObject);
    cxAny view = NULL;
    cxConstChars src = NULL;
    cxConstChars viewId = NULL;
    cxBool cache = false;
    cxConstChars curve = NULL;
    cxFloat delay = 0;
    if(!lua_istable(L, 2)){
        luaL_error(L, "args error");
        return 0;
    }
    //
    lua_getfield(L, 2, "delay");
    if(lua_isnumber(L, -1)){
        delay = lua_tonumber(L, -1);
    }
    lua_pop(L,1);
    //
    lua_getfield(L, 2, "src");
    if(lua_isstring(L, -1)){
        src = lua_tostring(L, -1);
    }
    lua_pop(L, 1);
    CX_RETURN(src == NULL, 0);
    //
    lua_getfield(L, 2, "curve");
    if(lua_isstring(L, -1)){
        curve = lua_tostring(L, -1);
    }
    lua_pop(L, 1);
    //
    lua_getfield(L, 2, "view");
    if(lua_isstring(L, -1)){
        viewId = lua_tostring(L, -1);
    }else if(lua_isuserdata(L, -1)){
        view = CX_LUA_GET_PTR(-1);
    }
    lua_pop(L, 1);
    //
    lua_getfield(L, 2, "cache");
    if(lua_isboolean(L, -1)){
        cache = lua_toboolean(L, -1);
    }
    lua_pop(L, 1);
    //get view by id and cxBase
    if(view != NULL){
        viewId = NULL;
    }else if(this->cxBase == cxBaseTypeAction){
        view = cxActionView(this);
    }else if(this->cxBase == cxBaseTypeView){
        view = this;
    }else{
        luaL_error(L,"base view and action can use this event");
        return 0;
    }
    CX_ASSERT(view != NULL, "this event's sender must base cxAction and cxView");
    if(viewId != NULL){
        view = cxViewRootGet(view, viewId);
        CX_RETURN(view == NULL, 0);
    }
    //get action
    cxAny action = NULL;
    cxBool fromcache =  false;
    if(cache){
        action = cxViewGetCache(view, src);
        fromcache = (action != NULL);
    }
    if(action == NULL){
        action = cxActionRootGet(src);
    }
    CX_RETURN(action == NULL, 0);
    if(!fromcache && cache){
        cxViewSetCache(view, src, action);
    }
    if(fromcache){
        cxActionReset(action);
    }
    //set action corve
    cxCurveItem curveitem = cxCurveGet(curve);
    if(curveitem != NULL){
        cxActionSetCurve(action, curveitem->func);
    }
    //delay
    if(delay > 0){
        cxActionSetDelay(action, delay);
    }
    cxViewAppendAction(view, action);
    return 0;
}