-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.lua
90 lines (79 loc) · 1.63 KB
/
main.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
require("init")()
-- 定义基类
local Person = class "Person" {
open = true,
init = function(self, name, age)
self.name = name
self.age = age
end,
final = {
Species = "human"
},
fields = {
name = null,
age = null,
},
methods = {
say = function(self, arg)
print(arg)
print(self.name .. self.age .. " years old. ")
end
}
}
-- 定义派生类
local Employee = class "Employee" {
extend = Person,
init = function(self, super, name, age, position)
super(name, age)
self.position = position
end,
overrides = {
say = function(self, super, words)
super("call super")
print(self.name .. ":我是 " .. self.position .. " 而且 " .. words .. ".")
end,
},
methods = {
todo = function(self, thing)
print(self.name .. " is going to " .. thing)
end,
}
}
-- 通过 cls(args) 直接生成实例
local yjp = Employee("一键爬", 25, "Not Boss")
local emp = Employee("时光星球", 30, "Boss")
local empx = Employee("北斗星", 35, "Big Boss")
emp:say("加入时光帝国")
emp:todo("开发时光客App")
empx:say("lua 得了相思病")
-- 访问final属性
print(emp:getSpecies())
-- 打印对象
print(tostring(emp))
print(type(empx))
local KFC = object "KFC" {
static = true,
fields = {
Crazy = "Thursday",
},
methods = {
V50 = function()
print("Vme50")
end
}
}
print(KFC)
print(KFC.Crazy)
KFC.V50()
-- print(dump(KFC))
local Ticker = require("utils.Ticker")
local count = 0
local ti = Ticker()
ti:setOnTickListener(function()
print("onTick")
count = count + 1
if count == 1 then
ti:stop()
end
end)
ti:start()