aboutsummaryrefslogtreecommitdiff
path: root/spec/inputs/teal_lang.yue
diff options
context:
space:
mode:
authorLi Jin <dragon-fly@qq.com>2023-07-28 11:53:04 +0800
committerLi Jin <dragon-fly@qq.com>2023-07-28 11:53:04 +0800
commit5497775534d20ba06ab9c13bc4db1c5bee877513 (patch)
treebe68d03cf0928efca4a579125e4ba15ef3ab9325 /spec/inputs/teal_lang.yue
parentf415df9617d251abd802257d9750618ccc71ca93 (diff)
downloadyuescript-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.yue36
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 @@
1import "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
8s = add(a.value, b)
9print(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
27p\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
34res = filter {"a", "b", "c", "a"}, cond
35for s in *res
36 print s