Class: Gloo::Verbs::Invoke
- Inherits:
-
Core::Verb
- Object
- Core::Baseo
- Core::Verb
- Gloo::Verbs::Invoke
- Defined in:
- lib/gloo/verbs/invoke.rb
Constant Summary collapse
- KEYWORD =
'invoke'.freeze
- KEYWORD_SHORT =
'~>'.freeze
Constants inherited from Core::Baseo
Core::Baseo::NOT_IMPLEMENTED_ERR
Instance Attribute Summary
Attributes inherited from Core::Verb
Attributes inherited from Core::Baseo
Class Method Summary collapse
-
.doc_data ⇒ Object
Get the verb's documentation data.
-
.keyword ⇒ Object
Get the Verb's keyword.
-
.keyword_shortcut ⇒ Object
Get the Verb's keyword shortcut.
Instance Method Summary collapse
-
#run ⇒ Object
Run the verb.
Methods inherited from Core::Verb
#display_value, help, inherited, #initialize, #type_display
Methods inherited from Core::Baseo
Constructor Details
This class inherits a constructor from Gloo::Core::Verb
Class Method Details
.doc_data ⇒ Object
Get the verb's documentation data.
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/gloo/verbs/invoke.rb', line 85 def self.doc_data { :name => KEYWORD, :shortcut => KEYWORD_SHORT, :description => 'Invoke a function. Set it to the result of the function.', :syntax => [ 'invoke {path.to.function} {params}' ], :parameters => [ '{path.to.function} — The function we want to invoke.', '{params} — The list of parameters to the function.' ], :result => 'The result of the function is put into it.', :examples => <<~EXAMPLES.strip # # Function examples # functions [can] : name [string] : Jasper on_load [script] : show 'running function examples' (white) invoke functions.greet ^.name show it invoke functions.add 3 4 show it show 'done' (white) # # Say hi to person (name) # greet [ƒ] : on_invoke [script] : put 'Hi, ' + ^.params.name into ^.result params [container] : name [string] : none result [string] : # # Add 2 numbers # add [ƒ] : on_invoke [script] : put ^.params.x and ^.params.y into ^.result params [container] : x [int] : y [int] : result [string] : EXAMPLES } end |
.keyword ⇒ Object
Get the Verb's keyword.
41 42 43 |
# File 'lib/gloo/verbs/invoke.rb', line 41 def self.keyword return KEYWORD end |
.keyword_shortcut ⇒ Object
Get the Verb's keyword shortcut.
48 49 50 |
# File 'lib/gloo/verbs/invoke.rb', line 48 def self.keyword_shortcut return KEYWORD_SHORT end |
Instance Method Details
#run ⇒ Object
Run the verb.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/gloo/verbs/invoke.rb', line 17 def run if @tokens.token_count > 1 ob = @tokens.first # Get the function object pn = Gloo::Core::Pn.new( @engine, @tokens.second ) func = pn.resolve # Is the object a function? if func&.is_function? params = get_params_arr @engine.log.debug "invoking function: #{func.pn}" result = func.invoke( params ) @engine.log.debug "function returned: #{result}" @engine.heap.it.set_to result return result end end end |