local BaseCommon = BaseCommon or {} -- event function BaseCommon.DispatchCustomEvent(__name, __data, __cmd) if (not __name) then assert(false, "BaseCommon.DispatchCustomEvent __name is null") end local event = cc.EventCustom:new(__name) event._usedata = __data event._cmd = __cmd cc.Director:getInstance():getEventDispatcher():dispatchEvent(event) end function BaseCommon.AddCustomEvent(__node, __eventName, __handler) if (not __eventName) then assert(false, "BaseCommon.AddCustomEvent __eventName is null") end local listener = cc.EventListenerCustom:create(__eventName, __handler) cc.Director:getInstance():getEventDispatcher():addEventListenerWithSceneGraphPriority(listener, __node) return listener end function BaseCommon.AddFixedCustomEvent(__eventName, __handler) local listener = cc.EventListenerCustom:create(__eventName, __handler) cc.Director:getInstance():getEventDispatcher():addEventListenerWithFixedPriority(listener, 1) return listener end function BaseCommon.RemoveFixedCustomEvent(__listener) cc.Director:getInstance():getEventDispatcher():removeEventListener(__listener) end -- const table function BaseCommon.NewConst( const_table ) local function Const( const_table ) local mt = { __index = function (t,k) if type(const_table[k])=="table" then const_table[k] = BaseCommon.NewConst(const_table[k]) end return const_table[k] end, __newindex = function (t,k,v) error("can't update " .. tostring(t) .."[" .. tostring(k) .."] = " .. tostring(v)) -- dump(t) end } return mt end local t = {} setmetatable(t, Const(const_table)) return t end return BaseCommon