static cxInt cxEventMessagePost(lua_State *L) { CX_LUA_DEF_THIS(cxObject); cxConstChars skey = luaL_checkstring(L, 2); cxMessagePost(skey, this); return 0; }
static cxInt cxEventSetTexture(lua_State *L) { CX_LUA_DEF_THIS(cxView); cxConstChars url = NULL; cxConstChars viewid = NULL; cxBool uts = false; lua_getfield(L, 2, "src"); if(lua_isstring(L, -1)){ url = lua_tostring(L, -1); } lua_pop(L,1); lua_getfield(L, 2, "view"); if(lua_isstring(L, -1)){ viewid = lua_tostring(L, -1); } lua_pop(L,1); lua_getfield(L, 2, "useTexSize"); if(lua_isboolean(L, -1)){ uts = lua_toboolean(L, -1); } lua_pop(L,1); if(viewid == NULL){ return 0; } cxView pview = cxViewRootGet(this, viewid); if(pview == NULL){ return 0; } //use texture size cxSpriteSetTextureURL(pview, url, uts); return 0; }
static cxInt cxStreamLuaAllBytes(lua_State *L) { CX_LUA_DEF_THIS(cxStream); cxString bytes = cxStreamAllBytes(this); CX_LUA_PUSH_OBJECT(bytes); return 1; }
static cxInt cxStreamLuaOpen(lua_State *L) { CX_LUA_DEF_THIS(cxStream); cxBool ret = cxStreamOpen(this); lua_pushboolean(L, ret); return 1; }
static cxInt cxLoadingLuaSetObject(lua_State *L) { CX_LUA_DEF_THIS(cxLoading); cxObject any = CX_LUA_GET_PTR(2); cxLoadingSetObject(this, any); return 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; }
static cxInt cxShaderLuaUsing(lua_State *L) { cxInt top = lua_gettop(L); CX_LUA_DEF_THIS(cxShader); cxBool atlas = top >= 2 ? lua_toboolean(L, 2) : false; cxShaderUsing(this, atlas); return 0; }
static cxInt cxStringLuaPrint(lua_State *L) { CX_LUA_DEF_THIS(cxString); if(this != NULL){ CX_LOGGER("%s",cxStringBody(this)); } return 0; }
static cxInt cxViewLuaCreateTimer(lua_State *L) { CX_LUA_DEF_THIS(cxView); cxFloat time = luaL_checknumber(L, 2); cxInt repeat = luaL_checkinteger(L, 3); cxAny timer = cxViewAppendTimer(this, time, repeat); CX_LUA_PUSH_OBJECT(timer); return 1; }
static cxInt cxViewLuaSetColor(lua_State *L) { CX_LUA_DEF_THIS(cxView); cxColor4f color = cxLuaColor4fValue(L, 2, this->color); cxViewSetAlpha(this, color.a); cxViewSetColor(this, cxColor3fv(color.r, color.g, color.b)); lua_pushvalue(L, 1); return 1; }
static cxInt cxStreamLuaSeek(lua_State *L) { CX_LUA_DEF_THIS(cxStream); cxInt off = cxLuaIntValue(L, 2, 0); cxInt flag = cxLuaIntValue(L, 3, SEEK_SET); off = cxStreamSeek(this, off, flag); lua_pushinteger(L, off); return 1; }
static cxInt cxSpriteLuaSetTexture(lua_State *L) { CX_LUA_DEF_THIS(cxSprite); cxBool ust = cxLuaBoolValue(L, 3, true); cxBool cache = cxLuaBoolValue(L, 4, true); cxConstChars url = luaL_checkstring(L, 2); cxSpriteSetTextureURL(this, url, ust, cache); return 0; }
static cxInt cxNumberLuaToColor4f(lua_State *L) { CX_LUA_DEF_THIS(cxNumber); if(this->type != cxNumberTypeColor4f){ luaL_error(L, "number type error"); lua_pushnil(L); }else{ cxLuaPushColor4f(L, this->value.color4f); } return 1; }
static cxInt cxNumberLuaToFloat(lua_State *L) { CX_LUA_DEF_THIS(cxNumber); if(this->type != cxNumberTypeFloat){ luaL_error(L, "number type error"); lua_pushnil(L); }else{ lua_pushnumber(L, this->value.vf); } return 1; }
static cxInt cxStreamLuaWrite(lua_State *L) { CX_LUA_DEF_THIS(cxStream); size_t len = 0; cxInt rv = 0; cxConstChars buffer = lua_tolstring(L, 2, &len); if(len > 0){ rv = cxStreamWrite(this, (cxPointer)buffer, len); } lua_pushinteger(L, rv); return 1; }
static cxInt cxEventSetView(lua_State *L) { CX_LUA_DEF_THIS(cxView); cxConstChars viewid = NULL; lua_getfield(L, 2, "view"); if(lua_isstring(L, -1)){ viewid = lua_tostring(L, -1); } lua_pop(L, 1); cxView pview = cxViewRootGet(this, viewid); CX_RETURN(pview == NULL, 0); lua_getfield(L, 2, "scale"); if(lua_isstring(L, -1)){ cxVec2f vscale = pview->scale; cxReadFloats(lua_tostring(L, -1), &vscale.x); cxViewSetScale(pview, vscale); } lua_pop(L, 1); lua_getfield(L, 2, "size"); if(lua_isstring(L, -1)){ cxSize2f vsize = pview->size; cxReadFloats(lua_tostring(L, -1), &vsize.w); cxViewSetSize(pview, vsize); } lua_pop(L, 1); lua_getfield(L, 2, "position"); if(lua_isstring(L, -1)){ cxVec2f vposition = pview->position; cxReadFloats(lua_tostring(L, -1), &vposition.x); cxViewSetPos(pview, vposition); } lua_pop(L, 1); lua_getfield(L, 2, "degress"); if(lua_isnumber(L, -1)){ cxViewSetDegrees(pview, lua_tonumber(L, -1)); } lua_pop(L, 1); lua_getfield(L, 2, "anchor"); if(lua_isstring(L, -1)){ cxVec2f vanchor = pview->anchor; cxReadFloats(lua_tostring(L, -1), &vanchor.x); cxViewSetAnchor(pview, vanchor); } lua_pop(L, 1); return 0; }
static cxInt cxStreamLuaRead(lua_State *L) { CX_LUA_DEF_THIS(cxStream); cxInt size = cxLuaIntValue(L, 2, 0); if(size <= 0){ luaL_error(L, "size args error"); return 0; } cxPointer buffer = allocator->malloc(size); cxInt bytes = cxStreamRead(this, buffer, size); cxString rv = cxStringAttach(buffer, bytes); CX_LUA_PUSH_OBJECT(rv); return 1; }
static cxInt cxViewLuaSetFixScale(lua_State *L) { cxInt top = lua_gettop(L); CX_LUA_DEF_THIS(cxView); cxVec2f fixscale = this->fixscale; if(lua_istable(L, 2)){ fixscale = cxLuaVec2fValue(L, 2, this->position); }else if(top == 3){ fixscale.x = luaL_checknumber(L, 2); fixscale.y = luaL_checknumber(L, 3); }else{ luaL_error(L, "args error"); } cxViewSetFixScale(this, fixscale); lua_pushvalue(L, 1); return 1; }
static cxInt cxViewLuaSetSize(lua_State *L) { cxInt top = lua_gettop(L); CX_LUA_DEF_THIS(cxView); cxSize2f size = this->size; if(lua_istable(L, 2)){ size = cxLuaSize2fValue(L, 2, this->size); }else if(top == 3){ size.w = luaL_checknumber(L, 2); size.h = luaL_checknumber(L, 3); }else{ luaL_error(L, "args error"); } cxViewSetSize(this, size); lua_pushvalue(L, 1); return 1; }
static cxInt cxViewLuaSetPosition(lua_State *L) { cxInt top = lua_gettop(L); CX_LUA_DEF_THIS(cxView); cxVec2f pos = this->position; if(lua_istable(L, 2)){ pos = cxLuaVec2fValue(L, 2, this->position); }else if(top == 3){ pos.x = luaL_checknumber(L, 2); pos.y = luaL_checknumber(L, 3); }else{ luaL_error(L, "args error"); } cxViewSetPos(this, pos); lua_pushvalue(L, 1); return 1; }
static cxInt cxLoadingLuaStart(lua_State *L) { CX_LUA_DEF_THIS(cxLoading); cxLoadingStart(this); return 0; }
static cxInt cxLoadingLuaGetObject(lua_State *L) { CX_LUA_DEF_THIS(cxLoading); CX_LUA_PUSH_OBJECT(this->object); return 1; }
static cxInt cxViewLuaGetFixScale(lua_State *L) { CX_LUA_DEF_THIS(cxView); cxLuaPushVec2fv(L, this->fixscale); return 1; }
static cxInt cxViewLuaGetSize(lua_State *L) { CX_LUA_DEF_THIS(cxView); cxLuaPushSize2fv(L, this->size); return 1; }
static cxInt cxViewLuaGetPosition(lua_State *L) { CX_LUA_DEF_THIS(cxView); cxLuaPushVec2fv(L, this->position); return 1; }
static cxInt cxViewLuaGetColor(lua_State *L) { CX_LUA_DEF_THIS(cxView); cxLuaPushColor4f(L, this->color); return 1; }
static cxInt cxStreamLuaClose(lua_State *L) { CX_LUA_DEF_THIS(cxStream); cxStreamClose(this); return 0; }
static cxInt cxStreamLuaPosition(lua_State *L) { CX_LUA_DEF_THIS(cxStream); lua_pushinteger(L, cxStreamPosition(this)); return 1; }
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; }
static cxInt cxViewLuaAppendView(lua_State *L) { CX_LUA_DEF_THIS(cxView); cxViewAppend(this, CX_LUA_GET_PTR(2)); return 0; }