--[[
-- lua物件導向設計--]
]--儲存類型別的虛表
local _class =
local _classname =
classtype =
function baseclass
(classname, super)
assert
(type
(classname)
=="string" and #classname >0)
-- 生成乙個類型別
local class_type =
-- 在建立物件的時候自動呼叫
class_type.__init = false
class_type.__delete = false
class_type.__cname = classname
class_type.__ctype = classtype.class
class_type.super = super
class_type.new =
function(.
..)-- 生成乙個類物件
local obj =
obj._class_type = class_type
obj.__ctype = classtype.instance
-- 在初始化之前註冊基類方法
setmetatable
(obj,
)-- 呼叫初始化方法
dolocal create
create =
function
(c,...
)if c.super then
create
(c.super,..
.)end
if c.__init then
c.__init
(obj,..
.)end
endcreate
(class_type,..
.)end
-- 註冊乙個delete方法
obj.delete =
function
(self)
if self.__isdeleted then
logger.
logerror
(string.
format
("trying to delete object which was already deleted. %s"
, table.
dump
(self)))
;return
; end
if(debugmanager ~
= nil and debugmanager:
logdeletecall()
)then
logger.
log(
" delete self : "..
tostring
(self)..
"\n"..
truncate
(table.
dump
(self)
,1024))
end
self.__isdeleting = true;
local now_super = self._class_type
while now_super ~
= nil do
if now_super.__delete then
now_super.
__delete
(self)
endnow_super = now_super.super
endself.__isdeleting = nil;
self.__isdeleted = true;
endobj.getclasstype =
function
(self)
return self._class_type;
endobj.isalive =
function
(self)
return not self:
isdeleting
() and not self:
isdeleted()
; end
obj.isdeleting =
function
(self)
return self.__isdeleting;
end
obj.isdeleted =
function
(self)
return self.__isdeleted;
endif
(debugmanager ~
= nil and debugmanager:
logcreatecall()
)then
logger.
log(
" create : "..
tostring
(obj)..
"\n"..
truncate
(table.
dump
(obj)
,1024))
endreturn obj
endlocal vtbl =
assert
(_class[class_type]
== nil,
"aready defined class : "
, classname)
_class[class_type]
= vtbl
_classname[classname]
= class_type
setmetatable
(class_type,
)if super then
setmetatable
(vtbl,
) end
return class_type
endfunction class
(classname)
return _classname[classname]
;end
當你需要繼承的時候可以使用
local uioperatetippanel =
baseclass
("uioperatetippanel"
, uibaseview)
xlua學習之路(二)xlua基礎
1.執行字串 xlua.luaenv luaenv new xlua.luaenv luaenv.dostring cs.unityengine.debug.log hello world luaenv.dispose 1 dostring引數為string,可輸入任意合法的lua 本示例在lua裡...
物件導向 初識物件導向
面向過程思想 步驟清晰簡單,第一步做什麼,第二步做什麼.面向過程適合處理一些較為簡單的問題 物件導向思想 物以類聚,分類的思維模式,思考問題首先會解決問題需要分哪些類,然後對這些類進行單獨思考,最後才是對某個分類下的細節進行面向過程的思索 物件導向適合處理複雜的問題,適合處理需要多人協作的問題 對於...
Xlua 學習記錄(一)Xlua 案例學習
有空看了下lua,研究下xlua。筆記如下 void start 1 dostring引數為string,可輸入任意合法的lua 本示例在lua裡呼叫c 的unityengine.debug.log列印了個日誌。2 乙個luaenv例項對應lua虛擬機器,出於開銷的考慮,建議全域性唯一。考慮全域性唯...