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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
|
string script = R"scriptcode(
-- start script
function main()
local a = 19
print(Asura.version)
print(Asura.author.name)
print("ok")
print(Asura.author.func())
-- local boy = Asura.SimBoy.New("I am peter!", 19)
-- boy:Say()
-- print(Asura.SimSchool.GetName())
print(Asura.SimBoy.Class)
print(Asura.SimBoy.Gender)
print(Asura.SimBoy.GetClassName())
print(Asura.School.GetName())
print(Asura.School.Region)
--[[
local Kid = Asura.SimBoy.Extend()
Asura.Kid = Kid
Kid.New = function(self, height, age)
self.base(age)
self.height = height
end
Kid.GetHeight = function(self)
print(self.height)
end
local kid = Kid.New(110, 12)
kid:GetHeight()
]]
local kid = Asura.SimBoy.New(23, "Chai")
print(kid:GetAge())
print(kid:GetName())
kid.fruit = function()
return "apple"
end
print(kid.fruit())
print(Asura.SimBoy.GetGender())
Asura.SimBoy.Havefun = function()
return "Boys have some fun!"
end
print(Asura.SimBoy.Havefun())
--
Asura.SimBoy.Foo = function()
return "SimBoy.Foo"
end
print(Asura.SimBoy.Foo())
print(Asura.EGender.BOY)
--Asura.EGender.BOY = 2
print(Asura.EGender.BOY)
print(Asura.SimBoy.EHabits.Girls)
print(Asura.EHabits.Girls)
print(kid)
kid:Write(function()
return "kid:Write()"
end )
print(kid:Speak())
kid:Write(function()
return "kid:Write() 2"
end )
print(kid:Speak())
------------------- plain class test
local Foo = Asura.Class("Foo")
Foo.Ctor = function(self, age, name, boy)
self.age = age
self.name = boy:GetName()
self.boy = boy
end
Foo.GetAge = function(self)
return self.age
end
Foo.GetName = function(self)
return self.name
end
local foo = Foo.New(10, "lee", kid)
print(foo:GetName())
print(Foo.GetClassName())
print(foo.GetClassName())
print(foo.boy:GetAge())
--------------------inherits test
local Coo = Foo.Extend("Coo")
print(Coo.GetClassName())
local coo = Coo.New(20, "Wang", kid)
print(coo:GetAge())
Coo.Ctor = function(self, age, name, boy)
self.age = age - 1
self.name = boy:GetName()
self.boy = boy
self.__base.Ctor(self, age, name, boy)
end
Coo.GetName = function(self)
local name = self.__base.GetName(self)
return "his name is " .. name
end
local coo2 = Coo.New(20, "Wang", kid)
print(coo2:GetAge())
print(coo2.GetClassName())
print(coo2:GetName())
---------------------plain enum test
local ERace = Asura.Enum("ERace", {
["White"] = 1,
["Asian"] = 2,
["Black"] = 3,
})
print(ERace.White)
print(ERace.Asian)
end
function err(msg)
print(msg)
end
xpcall(main, err)
-- end script
)scriptcode";
|