/* 基于栈的虚拟机 lls本身并不提供除了 * include() * typeof() 的函数,全部需要用户手动绑定。官方提供std包,包含一些常用的功能 数据类型: real 实数 string 字符串 boolean 布尔值 function 函数 set 集合 array 数组 包含其他文件,使用include函数: 加载文件时会判断文件是否加载过,加载过则不加载. local something = include("another.lls") 运算符: 关系 == != > < >= <= 逻辑 ! && || 赋值 = 算数 + - * / ^ % += -= *= /= ^= %= 位 & 按位与 | 按位或 ~ 按位非 &= |= ~= >> << >>= <<= 取set\array大小 # 关键字 null true false local global new 数字表示方式 可以加任意个_方便阅读 十进制 [1~9][0~9]...[0~9] 12306 二进制 0 0_00_00_00_00 十六进制 0x 0xFA 原生字符串 local rawString = "" this is a raw string test ""; */ /* 可以成为语句: 赋值、 不可成为语句: ; */ local too; local foo = null; local a = 10; global b = 12; /* 类(首字母大写的set)*/ global Monster = { health = 100, strength = 0.4, speed = 20, name = null, 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, create = func(_name, _speed, _wings) { local a = new Bat; a:init(_name, _speed, _wings); return a; } }; /* 或者下面这样,可以实现多重继承 Bat = new Monster + { fly = 20, wings = true, } + new Foo; Bat = new Monster + new Foo + { fly = 20, wings = true, init = func(self, _name, _speed, _wings) { //... } }; */ bat = new Bat; // 语法糖,把调用者作为第一个参数压入栈 bat:init(1, 2, 3); func newBat(_name, _speed, _wings) { local a = new Bat; a:init(_name, _speed, _wings); return a; } local bat1 = newBat(1, 2, 3); local bat2 = Bat.create(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}; /* set 和 array 不可以用+拼接 */ /* 字符串拼接 */ str = "hello " + "world"; f = {}; } func main() { local image = gl.createTexture(); global canvas = gl.createCanvas(); } main() func instanceof(Class, obj) { return obj._class == Class._class } Object = { _class = "Object", }; Box = new Object + { _class += "|Box", };