git.s-ol.nu alive / fbfa95b
add builtin get s-ol 2 years ago
1 changed file(s) with 33 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
399399 tick: =>
400400 @out\set @inputs.sig!
401401
402 get = Constant.meta
403 meta:
404 name: 'get'
405 summary: "Index into Arrays and Structs."
406 examples: { '(get val key [key2…])' }
407
408 value: class extends Op
409 pattern = (val! / evt!) + (const.str / const.sym / const.num)*0
410 setup: (inputs) =>
411 { val, keys } = pattern\match inputs
412 super val: Input.hot val
413
414 @state = [key.result! for key in *keys]
415
416 type = val\type!
417 for key in *@state
418 type = type\get key
419
420 if val\metatype == '!'
421 @out = type\mk_evt!
422 else
423 @out = type\mk_sig!
424
425 tick: =>
426 val = @inputs.val!
427 for key in *@state
428 if type(key) == 'number'
429 key = key + 1
430 val = val[key]
431 @out\set val
432
402433 Scope.from_table {
403434 :doc
404435 :trace, 'trace=': trace_, print: print_
414445 '~': to_sig
415446 '!': to_evt
416447
448 :get
449
417450 true: Constant.meta
418451 meta:
419452 name: 'true'