diff options
author | Li Jin <dragon-fly@qq.com> | 2021-02-17 11:22:07 +0800 |
---|---|---|
committer | Li Jin <dragon-fly@qq.com> | 2021-02-17 11:22:07 +0800 |
commit | 7066392d1c974065181d95d93274136dcd625d43 (patch) | |
tree | cf51eafc2c52cbc12246a306bca172d799193d30 /spec/inputs/class.yue | |
parent | 90cd12ad9ef465f3e435e1bd034dcfbe4e19d016 (diff) | |
download | yuescript-7066392d1c974065181d95d93274136dcd625d43.tar.gz yuescript-7066392d1c974065181d95d93274136dcd625d43.tar.bz2 yuescript-7066392d1c974065181d95d93274136dcd625d43.zip |
stop reusing variables, rename project.
Diffstat (limited to 'spec/inputs/class.yue')
-rw-r--r-- | spec/inputs/class.yue | 232 |
1 files changed, 232 insertions, 0 deletions
diff --git a/spec/inputs/class.yue b/spec/inputs/class.yue new file mode 100644 index 0000000..ca8b58c --- /dev/null +++ b/spec/inputs/class.yue | |||
@@ -0,0 +1,232 @@ | |||
1 | |||
2 | class Hello | ||
3 | new: (@test, @world) => | ||
4 | print "creating object.." | ||
5 | hello: => | ||
6 | print @test, @world | ||
7 | __tostring: => "hello world" | ||
8 | |||
9 | x = Hello 1,2 | ||
10 | x\hello() | ||
11 | |||
12 | print x | ||
13 | |||
14 | class Simple | ||
15 | cool: => print "cool" | ||
16 | |||
17 | class Yikes extends Simple | ||
18 | new: => print "created hello" | ||
19 | |||
20 | x = Yikes() | ||
21 | x\cool() | ||
22 | |||
23 | |||
24 | class Hi | ||
25 | new: (arg) => | ||
26 | print "init arg", arg | ||
27 | |||
28 | cool: (num) => | ||
29 | print "num", num | ||
30 | |||
31 | |||
32 | class Simple extends Hi | ||
33 | new: => super "man" | ||
34 | cool: => super 120302 | ||
35 | |||
36 | x = Simple() | ||
37 | x\cool() | ||
38 | |||
39 | print x.__class == Simple | ||
40 | |||
41 | |||
42 | class Okay | ||
43 | -- what is going on | ||
44 | something: 20323 | ||
45 | -- yeaha | ||
46 | |||
47 | |||
48 | class Biggie extends Okay | ||
49 | something: => | ||
50 | super 1,2,3,4 | ||
51 | super.something another_self, 1,2,3,4 | ||
52 | assert super == Okay | ||
53 | |||
54 | |||
55 | class Yeah | ||
56 | okay: => | ||
57 | super\something 1,2,3,4 | ||
58 | |||
59 | |||
60 | class What | ||
61 | something: => print "val:", @val | ||
62 | |||
63 | class Hello extends What | ||
64 | val: 2323 | ||
65 | something: => super\something | ||
66 | |||
67 | with Hello! | ||
68 | x = \something! | ||
69 | print x | ||
70 | x! | ||
71 | |||
72 | class CoolSuper | ||
73 | hi: => | ||
74 | super(1,2,3,4) 1,2,3,4 | ||
75 | super.something 1,2,3,4 | ||
76 | _ = super.something(1,2,3,4).world | ||
77 | super\yeah"world".okay hi, hi, hi | ||
78 | _ = something.super | ||
79 | _ = super.super.super.super | ||
80 | _ = super\hello | ||
81 | nil | ||
82 | |||
83 | |||
84 | -- selfing | ||
85 | x = @hello | ||
86 | x = @@hello | ||
87 | |||
88 | @hello "world" | ||
89 | @@hello "world" | ||
90 | |||
91 | @@one @@two(4,5) @three, @four | ||
92 | |||
93 | xx = (@hello, @@world, cool) -> | ||
94 | |||
95 | |||
96 | -- class properties | ||
97 | class ClassMan | ||
98 | @yeah: 343 | ||
99 | blue: => | ||
100 | @hello: 3434, @world: 23423 | ||
101 | green: => | ||
102 | @red: => | ||
103 | |||
104 | |||
105 | x = @ | ||
106 | y = @@ | ||
107 | |||
108 | @ something | ||
109 | |||
110 | @@ something | ||
111 | |||
112 | @ = @ + @ / @ | ||
113 | |||
114 | @ = 343 | ||
115 | @.hello 2,3,4 | ||
116 | |||
117 | _ = hello[@].world | ||
118 | |||
119 | |||
120 | class Whacko | ||
121 | _ = @hello | ||
122 | if something | ||
123 | print "hello world" | ||
124 | |||
125 | hello = "world" | ||
126 | @another = "day" | ||
127 | |||
128 | print "yeah" if something -- this is briken | ||
129 | |||
130 | |||
131 | print "hello" | ||
132 | |||
133 | yyy = -> | ||
134 | class Cool | ||
135 | _ = nil | ||
136 | |||
137 | |||
138 | -- | ||
139 | |||
140 | class a.b.c.D | ||
141 | _ = nil | ||
142 | |||
143 | |||
144 | class a.b["hello"] | ||
145 | _ = nil | ||
146 | |||
147 | class (-> require "moon")!.Something extends Hello.World | ||
148 | _ = nil | ||
149 | |||
150 | -- | ||
151 | |||
152 | a = class | ||
153 | b = class Something | ||
154 | c = class Something extends Hello | ||
155 | d = class extends World | ||
156 | |||
157 | print (class WhatsUp).__name | ||
158 | |||
159 | -- | ||
160 | |||
161 | global ^ | ||
162 | class Something | ||
163 | _ = nil | ||
164 | |||
165 | |||
166 | -- | ||
167 | |||
168 | -- hoisting | ||
169 | class Something | ||
170 | val = 23 | ||
171 | {:insert} = table | ||
172 | new: => print insert, val -- prints nil 23 | ||
173 | |||
174 | -- | ||
175 | |||
176 | class X | ||
177 | new: hi | ||
178 | |||
179 | |||
180 | -- | ||
181 | |||
182 | class Cool extends Thing | ||
183 | dang: => | ||
184 | { | ||
185 | hello: -> super! | ||
186 | world: -> super.one | ||
187 | } | ||
188 | |||
189 | -- | ||
190 | |||
191 | class Whack extends Thing | ||
192 | dang: do_something => | ||
193 | super! | ||
194 | |||
195 | --- | ||
196 | |||
197 | class Wowha extends Thing | ||
198 | @butt: -> | ||
199 | super! | ||
200 | _ = super.hello | ||
201 | super\hello! | ||
202 | super\hello | ||
203 | |||
204 | |||
205 | @zone: cool { | ||
206 | -> | ||
207 | super! | ||
208 | _ = super.hello | ||
209 | super\hello! | ||
210 | super\hello | ||
211 | } | ||
212 | |||
213 | do | ||
214 | class Test | ||
215 | new: => @@if = true | ||
216 | @do: => 1 | ||
217 | test: => @@if and @@do! | ||
218 | test = Test! | ||
219 | test\test! | ||
220 | |||
221 | do | ||
222 | class Test | ||
223 | new: => @if = true | ||
224 | do: => 1 | ||
225 | test: => @if and @do! | ||
226 | test = Test! | ||
227 | test\test! | ||
228 | |||
229 | class extends lapis.Application | ||
230 | "/": => json: { status: true } | ||
231 | |||
232 | nil | ||