diff options
author | chai <chaifix@163.com> | 2018-06-06 07:58:47 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2018-06-06 07:58:47 +0800 |
commit | 726fa81bf2597aa4b3d14a89915993eaa9d62908 (patch) | |
tree | 16d68b2387394cc2a7b24cc6f009bcb394bf077f | |
parent | 24cce4c24a155b726dc3b2c120defef6a94638fa (diff) |
更新数据类型
-rw-r--r-- | lls/lls.c | 11 | ||||
-rw-r--r-- | test/hello.lls | 118 |
2 files changed, 90 insertions, 39 deletions
@@ -5,10 +5,11 @@ enum { VT_UNKNOWN = 0, VT_NULL, // null | | - VT_NUMBER, // number | float | + VT_REAL, // real | float | VT_STRING, // string | char* | VT_BOOLEAN, // boolean | char | - VT_SET, // set | struct | + VT_SET, // set | void* | + VT_ARRAY, // array | void* | VT_FUNCTION, // function | void* | ڴͬĺ }; @@ -17,10 +18,12 @@ typedef struct int type; union { - float _number; + float _real; char* _string; char _bool; - void* _struct; + void* _set; + void* _array; + int _func; } value; } lls_Value; diff --git a/test/hello.lls b/test/hello.lls index 8ca0886..c29ff3c 100644 --- a/test/hello.lls +++ b/test/hello.lls @@ -7,12 +7,26 @@ lls本身并不提供除了 的函数,全部需要用户手动绑定。官方提供std包,包含一些常用的功能 数据类型: - real 实数 - string 字符串 - boolean 布尔值 - function 函数 - set 集合 - array 数组 + real 实数 值 + boolean 布尔值 值 + --------------------------- + string 字符串 地址 + set 集合 地址 + array 数组 地址 + --------------------------- + function 函数 地址(仅) + +new关键字会拷贝内存,如果没有new则会使用地址赋值 + +local s = "hello"; +local a = s; +a[0] = '1'; +io.print(s); +// 1ello +local b = new s; +b[0] = '1'; +io.print(s); +// hello 包含其他文件,使用include函数: 加载文件时会判断文件是否加载过,加载过则不加载. @@ -20,43 +34,43 @@ lls本身并不提供除了 运算符: 关系 - == - != - > - < - >= - <= - 逻辑 - ! + == + != + > + < + >= + <= + 逻辑 + ! && - || - 赋值 + || + 赋值 = - 算数 + 算数 + - * - / - ^ - % + / + % += -= *= - /= - ^= + /= %= - 位 - & 按位与 + 位 + & 按位与 | 按位或 - ~ 按位非 - &= + ~ 按位取反 + ^ 按位异或 + &= |= - ~= + ~= + ^= >> << >>= <<= - 取set\array大小 + 取set\array\string长度 # 关键字 @@ -133,8 +147,8 @@ Bat = new Monster + { wings = true, } + new Foo; -Bat = new Monster + - new Foo + +Bat = Monster + + Foo + { fly = 20, wings = true, @@ -202,20 +216,54 @@ main() func instanceof(Class, obj) { return obj._class == Class._class -} +} Object = { - _class = "Object", - + _class = {"Object"}, + instanceof = func(self, Class) + { + return array.contain(self._class, Class._class); + //return string.contain(self._class, Class._class); + //return self._class == Class._class; + } }; -Box = new Object + +Box = Object + { - _class += "|Box", + _class = {"Box"}, }; +box = new Box; +if(box:instanceof(Object)) +{ + +} + +// 为了解决重复拷贝函数的问题,采用一个set封装这些函数 +// set\array变量赋值的时候不会拷贝,而是引用同一个地址 +Bird = { + _method = { + fly = func(self) + { + // .... + } + } +} + +bird = new Bird; + +bird._method.fly(bird); +// 考虑引入unique关键字,声明变量的时候,不会拷贝副本,而是拷贝地址 +Bird = { + unique fly = func(self){ + // .... + } +} +bird = new Bird; +bird:fly(); +// 或者限制函数只能拷贝地址 |