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
|
// global
//
//
//
/*
关键字
null
true false
*/
/*
可以成为语句:
赋值、
不可成为语句:
<variable>;
*/
// 声明一个变量时必须赋值,如
foo = null;
a = 10;
global b = 12;
/* 类(首字母大写的set)*/
Monster = {
health = 100,
strength = 0.4,
speed = 20,
attack = func(self, other)
{
other.health -= self.strength;
},
['escape'] = func(self)
{
speed -= 10;
},
["init"] = func(self, _health, _speed, _strength)
{
self.speed = _speed;
self.health = _health;
},
};
/* 继承 */
Bat = new Monster;
Bat += {
fly = 20,
wings = true,
};
/*
或者下面这样,可以实现多重继承
Bat = new Monster + {
fly = 20,
wings = true,
} + new Foo;
Bat = new Monster +
new Foo +
{
fly = 20,
wings = true,
init = func()
{
}
};
*/
bat = new Bat;
// 语法糖,把调用者作为第一个参数压入栈
bat:init(1, 2, 3);
func test()
{
a = 13;
c = {
c_1 = 12,
c_2 = 13,
c_3 = func() {
},
['c_4'] = func(obj){
obj.c_1 = 12
},
["c_5"] = func(msg){
print(msg)
}
};
d = new c;
e = c;
d["c_4"] = "d_c_4";
d["c_5"]("function test");
d.c_5("function test");
/* 数组,默认无key的set */
/* 如果第一个数据没有key,则set成为array */
/* array从0开始索引 */
arr = {1, 2, 2, 3, 5, 2};
/* 字符串拼接 */
str = "hello " + "world";
}
func main()
{
}
main()
|