[分享] Lua OO Library - bmclass
以下內容源自小弟的部落格,取出一些重點轉貼自 bbs
http://justbm.blogspot.com/2011/05/lua-oo-library-bmclass.html
如有錯誤煩請指教,謝謝。
====
Library - bmclass.lua 下載
http://ppt.cc/7hgS
====
使用範例
====
範例一(最基本的使用方式)
== code start ==
class = require("bmclass")
a = class("a")
function a:init()
print("for init")
end
function a:hello()
print(tostring(self) .. " : Hello!!!")
end
b = a("b") -- output "for init"
b:hello() -- output "Object b : Hello!!!"
== code end ==
範例二(多重繼承)
== code start ==
class = require("bmclass")
a = class("a")
b = class("b")
c = class("c", a, b) -- superclass a and b
function a:init() print("a init") end
function b:init() print("b init") end
function c:init()
c:next(self, "init") -- next to the superclass
print("c init")
end
function a:hello1() print("Hello1") end
function b:hello2() print("Hello2") end
function c:hello3() print("Hello3") end
d = c("d")
-- output
-- a init
-- b init
-- c init
d:hello1() -- output "Hello1"
d:hello2() -- output "Hello2"
d:hello3() -- output "Hello3"
== code end ==
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 114.24.40.248
推
05/25 16:05, , 1F
05/25 16:05, 1F
目前來說是興趣~但怎麼有此一問XD?
多多接觸學習不會的新技術也跟自己工作相關就是囉~
※ 編輯: bmzz 來自: 220.128.103.223 (05/25 16:58)
Programming 近期熱門文章
PTT數位生活區 即時熱門文章
7
20