summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/hello.lls110
1 files changed, 110 insertions, 0 deletions
diff --git a/test/hello.lls b/test/hello.lls
new file mode 100644
index 0000000..86e6a6b
--- /dev/null
+++ b/test/hello.lls
@@ -0,0 +1,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() \ No newline at end of file