diff options
author | Li Jin <dragon-fly@qq.com> | 2023-07-28 11:53:04 +0800 |
---|---|---|
committer | Li Jin <dragon-fly@qq.com> | 2023-07-28 11:53:04 +0800 |
commit | 5497775534d20ba06ab9c13bc4db1c5bee877513 (patch) | |
tree | be68d03cf0928efca4a579125e4ba15ef3ab9325 /spec/inputs/teal_lang.yue | |
parent | f415df9617d251abd802257d9750618ccc71ca93 (diff) | |
download | yuescript-5497775534d20ba06ab9c13bc4db1c5bee877513.tar.gz yuescript-5497775534d20ba06ab9c13bc4db1c5bee877513.tar.bz2 yuescript-5497775534d20ba06ab9c13bc4db1c5bee877513.zip |
fix xpcall usages in different Lua version.
Diffstat (limited to 'spec/inputs/teal_lang.yue')
-rw-r--r-- | spec/inputs/teal_lang.yue | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/spec/inputs/teal_lang.yue b/spec/inputs/teal_lang.yue new file mode 100644 index 0000000..e01682f --- /dev/null +++ b/spec/inputs/teal_lang.yue | |||
@@ -0,0 +1,36 @@ | |||
1 | import "macro_teal" as $ | ||
2 | |||
3 | $local "a:{string:number}", {value:123} | ||
4 | $local "b:number", a.value | ||
5 | |||
6 | $function "add(a:number, b:number):number", -> a + b | ||
7 | |||
8 | s = add(a.value, b) | ||
9 | print(s) | ||
10 | |||
11 | $record Point, | ||
12 | x: number | ||
13 | y: number | ||
14 | |||
15 | $method "Point.new(x:number, y:number):Point", -> | ||
16 | $local "point:Point", setmetatable {}, __index: Point | ||
17 | point.x = x or 0 | ||
18 | point.y = y or 0 | ||
19 | point | ||
20 | |||
21 | $method "Point:move(dx:number, dy:number)", -> | ||
22 | @x += dx | ||
23 | @y += dy | ||
24 | |||
25 | $local "p:Point", Point.new 100, 100 | ||
26 | |||
27 | p\move 50, 50 | ||
28 | |||
29 | $function "filter(tab:{string}, handler:function(item:string):boolean):{string}", -> | ||
30 | [item for item in *tab when handler item] | ||
31 | |||
32 | $function "cond(item:string):boolean", -> item ~= "a" | ||
33 | |||
34 | res = filter {"a", "b", "c", "a"}, cond | ||
35 | for s in *res | ||
36 | print s | ||