// global // // // /* 关键字 null true false */ /* 可以成为语句: 赋值、 不可成为语句: ; */ // 声明一个变量时必须赋值,如 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"; f = {}; } func main() { } main()