int CCLuaEngine::pushCCLuaValue(const CCLuaValue& value) { const CCLuaValueType type = value.getType(); if (type == CCLuaValueTypeInt) { return pushInt(value.intValue()); } else if (type == CCLuaValueTypeFloat) { return pushFloat(value.floatValue()); } else if (type == CCLuaValueTypeBoolean) { return pushBoolean(value.booleanValue()); } else if (type == CCLuaValueTypeString) { return pushString(value.stringValue().c_str()); } else if (type == CCLuaValueTypeDict) { pushCCLuaValueDict(value.dictValue()); } else if (type == CCLuaValueTypeArray) { pushCCLuaValueArray(value.arrayValue()); } else if (type == CCLuaValueTypeCCObject) { pushCCObject(value.ccobjectValue(), value.getCCObjectTypename().c_str()); } return lua_gettop(m_state); }
void CCLuaStack::executeObjectDestructor(CCObject* obj) { pushCCObject(obj, getLuaTypeNameByTypeId(typeid(*obj).name())); // obj lua_pushstring(m_state, "dtor"); // obj "dtor" lua_gettable(m_state, -2); // obj dtor if(lua_isnil(m_state, -1) || !lua_isfunction(m_state, -1)) { lua_pop(m_state, 2); } else { // push obj lua_pushvalue(m_state, -2); // obj dtor obj lua_remove(m_state, -3); // dtor obj executeFunction(1); } }
int CCLuaEngine::executeCallFuncActionEvent(CCCallFunc* pAction, CCObject* pTarget/* = NULL*/) { int ret = 0; do { int nScriptHandler = pAction->getScriptHandler(); CC_BREAK_IF(0 == nScriptHandler); cleanStack(); if (pTarget != NULL) { pushCCObject(pTarget, "CCNode"); } else { pushNil(); } ret = executeFunctionByHandler(nScriptHandler, 1); } while (0); return ret; }