summaryrefslogtreecommitdiff
path: root/spec/outputs/teal-lang.tl
diff options
context:
space:
mode:
authorLi Jin <dragon-fly@qq.com>2021-10-12 10:04:44 +0800
committerLi Jin <dragon-fly@qq.com>2021-10-12 10:04:44 +0800
commit60a979e224f26117f5be82bfca757a2483cef0fd (patch)
tree7c6af44f6dcada1f23979b820ba830251997b161 /spec/outputs/teal-lang.tl
parenta19b242cbaf53721b20a3163dd06f43e9ef2b487 (diff)
downloadyuescript-60a979e224f26117f5be82bfca757a2483cef0fd.tar.gz
yuescript-60a979e224f26117f5be82bfca757a2483cef0fd.tar.bz2
yuescript-60a979e224f26117f5be82bfca757a2483cef0fd.zip
fix test.
Diffstat (limited to 'spec/outputs/teal-lang.tl')
-rw-r--r--spec/outputs/teal-lang.tl60
1 files changed, 60 insertions, 0 deletions
diff --git a/spec/outputs/teal-lang.tl b/spec/outputs/teal-lang.tl
new file mode 100644
index 0000000..8f0bf36
--- /dev/null
+++ b/spec/outputs/teal-lang.tl
@@ -0,0 +1,60 @@
1local a:{string:number} = {
2 value = 123
3};
4local b:number = a.value;
5local function add(a:number, b:number):number
6
7 return a + b
8
9end
10local s = add(a.value, b)
11print(s);
12local record Point
13 x: number
14 y: number
15end
16function Point.new(x:number, y:number):Point
17local point:Point = setmetatable({ }, {
18 __index = Point
19})
20 point.x = x or 0
21 point.y = y or 0
22 return point
23
24end
25function Point:move(dx:number, dy:number)
26 self.x = self.x + dx
27 self.y = self.y + dy
28
29end
30local p:Point = Point.new(100, 100)
31p:move(50, 50);
32local function filter(tab:{string}, handler:function(item:string):boolean):{string}
33
34 local _accum_0 = { }
35 local _len_0 = 1
36 for _index_0 = 1, #tab do
37 local item = tab[_index_0]
38 if handler(item) then
39 _accum_0[_len_0] = item
40 _len_0 = _len_0 + 1
41 end
42 end
43 return _accum_0
44
45end
46local function cond(item:string):boolean
47
48 return item ~= "a"
49
50end
51local res = filter({
52 "a",
53 "b",
54 "c",
55 "a"
56}, cond)
57for _index_0 = 1, #res do
58 local s = res[_index_0]
59 print(s)
60end