diff options
| author | Li Jin <dragon-fly@qq.com> | 2021-10-12 10:04:44 +0800 |
|---|---|---|
| committer | Li Jin <dragon-fly@qq.com> | 2021-10-12 10:04:44 +0800 |
| commit | 60a979e224f26117f5be82bfca757a2483cef0fd (patch) | |
| tree | 7c6af44f6dcada1f23979b820ba830251997b161 /spec/outputs/teal-lang.lua | |
| parent | a19b242cbaf53721b20a3163dd06f43e9ef2b487 (diff) | |
| download | yuescript-60a979e224f26117f5be82bfca757a2483cef0fd.tar.gz yuescript-60a979e224f26117f5be82bfca757a2483cef0fd.tar.bz2 yuescript-60a979e224f26117f5be82bfca757a2483cef0fd.zip | |
fix test.
Diffstat (limited to 'spec/outputs/teal-lang.lua')
| -rw-r--r-- | spec/outputs/teal-lang.lua | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/spec/outputs/teal-lang.lua b/spec/outputs/teal-lang.lua new file mode 100644 index 0000000..0e627f4 --- /dev/null +++ b/spec/outputs/teal-lang.lua | |||
| @@ -0,0 +1,49 @@ | |||
| 1 | local a = { | ||
| 2 | value = 123 | ||
| 3 | }; | ||
| 4 | local b = a.value; | ||
| 5 | local add = function(a, b) | ||
| 6 | return a + b | ||
| 7 | end | ||
| 8 | local s = add(a.value, b) | ||
| 9 | print(s); | ||
| 10 | local Point = {}; | ||
| 11 | Point.new = function(x, y) | ||
| 12 | local point = setmetatable({ }, { | ||
| 13 | __index = Point | ||
| 14 | }) | ||
| 15 | point.x = x or 0 | ||
| 16 | point.y = y or 0 | ||
| 17 | return point | ||
| 18 | end | ||
| 19 | Point.move = function(self, dx, dy) | ||
| 20 | self.x = self.x + dx | ||
| 21 | self.y = self.y + dy | ||
| 22 | end | ||
| 23 | local p = Point.new(100, 100) | ||
| 24 | p:move(50, 50); | ||
| 25 | local filter = function(tab, handler) | ||
| 26 | local _accum_0 = { } | ||
| 27 | local _len_0 = 1 | ||
| 28 | for _index_0 = 1, #tab do | ||
| 29 | local item = tab[_index_0] | ||
| 30 | if handler(item) then | ||
| 31 | _accum_0[_len_0] = item | ||
| 32 | _len_0 = _len_0 + 1 | ||
| 33 | end | ||
| 34 | end | ||
| 35 | return _accum_0 | ||
| 36 | end | ||
| 37 | local cond = function(item) | ||
| 38 | return item ~= "a" | ||
| 39 | end | ||
| 40 | local res = filter({ | ||
| 41 | "a", | ||
| 42 | "b", | ||
| 43 | "c", | ||
| 44 | "a" | ||
| 45 | }, cond) | ||
| 46 | for _index_0 = 1, #res do | ||
| 47 | local s = res[_index_0] | ||
| 48 | print(s) | ||
| 49 | end | ||
