diff options
Diffstat (limited to 'spec')
| -rw-r--r-- | spec/inputs/funcs.yue | 31 | ||||
| -rw-r--r-- | spec/outputs/funcs.lua | 153 |
2 files changed, 184 insertions, 0 deletions
diff --git a/spec/inputs/funcs.yue b/spec/inputs/funcs.yue index e647edc..6b1669b 100644 --- a/spec/inputs/funcs.yue +++ b/spec/inputs/funcs.yue | |||
| @@ -193,4 +193,35 @@ do | |||
| 193 | func = (): -> check 123 | 193 | func = (): -> check 123 |
| 194 | print func! -- get nil | 194 | print func! -- get nil |
| 195 | 195 | ||
| 196 | do | ||
| 197 | f = ({:a, :b, :c}) -> print a, b, c | ||
| 198 | f = (:a, :b, :c) -> print a, b, c | ||
| 199 | g = (x, :y) -> print x, y | ||
| 200 | i = ({a: ax = 0, b: by = 0}) -> print ax, by | ||
| 201 | j = (name, {id: uid = "n/a", :role = "guest"}) -> print name, uid, role | ||
| 202 | m = ({user: {:name, :age}, meta: {:ver = 1}}) -> print name, age, ver | ||
| 203 | m1 = ({user: {:name, :age}, :meta = {}}) -> print name, age, meta and meta.ver or "nil" | ||
| 204 | new = ({:name = "anon", :age = 0}) => | ||
| 205 | @name = name | ||
| 206 | @age = age | ||
| 207 | set = ({:name = @name, :age = @age}) => | ||
| 208 | @name = name | ||
| 209 | @age = age | ||
| 210 | logKV = ({:k, :v}, ...) -> | ||
| 211 | print "kv:", k, v | ||
| 212 | print "rest count:", select "#", ... | ||
| 213 | macro gen = (fname) -> | | ||
| 214 | #{fname} = ({:a, :b = 0}) -> print a, b | ||
| 215 | $gen foo | ||
| 216 | t1 = (:a, x) -> print a, x | ||
| 217 | t2 = (:a) -> print a | ||
| 218 | w = ( | ||
| 219 | id | ||
| 220 | {:x = 0, :y = 0} | ||
| 221 | :flag | ||
| 222 | ) -> | ||
| 223 | print id, x, y, flag | ||
| 224 | g1 = ({:a, a: ax}) -> print a, ax | ||
| 225 | g4 = ({:a, :b, ...rest}) -> print a, b | ||
| 226 | |||
| 196 | nil | 227 | nil |
diff --git a/spec/outputs/funcs.lua b/spec/outputs/funcs.lua index c1735c4..db7ed67 100644 --- a/spec/outputs/funcs.lua +++ b/spec/outputs/funcs.lua | |||
| @@ -283,4 +283,157 @@ do | |||
| 283 | end | 283 | end |
| 284 | print(func()) | 284 | print(func()) |
| 285 | end | 285 | end |
| 286 | local _anon_func_0 = function(_arg_0) | ||
| 287 | local _accum_0 = { } | ||
| 288 | local _len_0 = 1 | ||
| 289 | local _max_0 = #_arg_0 | ||
| 290 | for _index_0 = 1, _max_0 do | ||
| 291 | local _item_0 = _arg_0[_index_0] | ||
| 292 | _accum_0[_len_0] = _item_0 | ||
| 293 | _len_0 = _len_0 + 1 | ||
| 294 | end | ||
| 295 | return _accum_0 | ||
| 296 | end | ||
| 297 | do | ||
| 298 | local f | ||
| 299 | f = function(_arg_0) | ||
| 300 | local a, b, c | ||
| 301 | a, b, c = _arg_0.a, _arg_0.b, _arg_0.c | ||
| 302 | return print(a, b, c) | ||
| 303 | end | ||
| 304 | f = function(_arg_0) | ||
| 305 | local a, b, c | ||
| 306 | a, b, c = _arg_0.a, _arg_0.b, _arg_0.c | ||
| 307 | return print(a, b, c) | ||
| 308 | end | ||
| 309 | local g | ||
| 310 | g = function(x, _arg_0) | ||
| 311 | local y | ||
| 312 | y = _arg_0.y | ||
| 313 | return print(x, y) | ||
| 314 | end | ||
| 315 | local i | ||
| 316 | i = function(_arg_0) | ||
| 317 | local ax, by | ||
| 318 | ax, by = _arg_0.a, _arg_0.b | ||
| 319 | if ax == nil then | ||
| 320 | ax = 0 | ||
| 321 | end | ||
| 322 | if by == nil then | ||
| 323 | by = 0 | ||
| 324 | end | ||
| 325 | return print(ax, by) | ||
| 326 | end | ||
| 327 | j = function(name, _arg_0) | ||
| 328 | local uid, role | ||
| 329 | uid, role = _arg_0.id, _arg_0.role | ||
| 330 | if uid == nil then | ||
| 331 | uid = "n/a" | ||
| 332 | end | ||
| 333 | if role == nil then | ||
| 334 | role = "guest" | ||
| 335 | end | ||
| 336 | return print(name, uid, role) | ||
| 337 | end | ||
| 338 | local m | ||
| 339 | m = function(_arg_0) | ||
| 340 | local name, age, ver | ||
| 341 | name, age, ver = _arg_0.user.name, _arg_0.user.age, _arg_0.meta.ver | ||
| 342 | if ver == nil then | ||
| 343 | ver = 1 | ||
| 344 | end | ||
| 345 | return print(name, age, ver) | ||
| 346 | end | ||
| 347 | local m1 | ||
| 348 | m1 = function(_arg_0) | ||
| 349 | local name, age, meta | ||
| 350 | name, age, meta = _arg_0.user.name, _arg_0.user.age, _arg_0.meta | ||
| 351 | if meta == nil then | ||
| 352 | meta = { } | ||
| 353 | end | ||
| 354 | return print(name, age, meta and meta.ver or "nil") | ||
| 355 | end | ||
| 356 | local new | ||
| 357 | new = function(self, _arg_0) | ||
| 358 | local name, age | ||
| 359 | name, age = _arg_0.name, _arg_0.age | ||
| 360 | if name == nil then | ||
| 361 | name = "anon" | ||
| 362 | end | ||
| 363 | if age == nil then | ||
| 364 | age = 0 | ||
| 365 | end | ||
| 366 | self.name = name | ||
| 367 | self.age = age | ||
| 368 | end | ||
| 369 | local set | ||
| 370 | set = function(self, _arg_0) | ||
| 371 | local name, age | ||
| 372 | name, age = _arg_0.name, _arg_0.age | ||
| 373 | if name == nil then | ||
| 374 | name = self.name | ||
| 375 | end | ||
| 376 | if age == nil then | ||
| 377 | age = self.age | ||
| 378 | end | ||
| 379 | self.name = name | ||
| 380 | self.age = age | ||
| 381 | end | ||
| 382 | local logKV | ||
| 383 | logKV = function(_arg_0, ...) | ||
| 384 | local k, v | ||
| 385 | k, v = _arg_0.k, _arg_0.v | ||
| 386 | print("kv:", k, v) | ||
| 387 | return print("rest count:", select("#", ...)) | ||
| 388 | end | ||
| 389 | do | ||
| 390 | local foo | ||
| 391 | foo = function(_arg_0) | ||
| 392 | local a, b | ||
| 393 | a, b = _arg_0.a, _arg_0.b | ||
| 394 | if b == nil then | ||
| 395 | b = 0 | ||
| 396 | end | ||
| 397 | return print(a, b) | ||
| 398 | end | ||
| 399 | end | ||
| 400 | local t1 | ||
| 401 | t1 = function(_arg_0, x) | ||
| 402 | local a | ||
| 403 | a = _arg_0.a | ||
| 404 | return print(a, x) | ||
| 405 | end | ||
| 406 | local t2 | ||
| 407 | t2 = function(_arg_0) | ||
| 408 | local a | ||
| 409 | a = _arg_0.a | ||
| 410 | return print(a) | ||
| 411 | end | ||
| 412 | local w | ||
| 413 | w = function(id, _arg_0, _arg_1) | ||
| 414 | local x, y | ||
| 415 | x, y = _arg_0.x, _arg_0.y | ||
| 416 | if x == nil then | ||
| 417 | x = 0 | ||
| 418 | end | ||
| 419 | if y == nil then | ||
| 420 | y = 0 | ||
| 421 | end | ||
| 422 | local flag | ||
| 423 | flag = _arg_1.flag | ||
| 424 | return print(id, x, y, flag) | ||
| 425 | end | ||
| 426 | local g1 | ||
| 427 | g1 = function(_arg_0) | ||
| 428 | local a, ax | ||
| 429 | a, ax = _arg_0.a, _arg_0.a | ||
| 430 | return print(a, ax) | ||
| 431 | end | ||
| 432 | local g4 | ||
| 433 | g4 = function(_arg_0) | ||
| 434 | local a, b, rest | ||
| 435 | a, b, rest = _arg_0.a, _arg_0.b, _anon_func_0(_arg_0) | ||
| 436 | return print(a, b) | ||
| 437 | end | ||
| 438 | end | ||
| 286 | return nil | 439 | return nil |
