Class: Gloo::Objs::Function
- Inherits:
-
Core::Obj
- Object
- Core::Baseo
- Core::Obj
- Gloo::Objs::Function
- Defined in:
- lib/gloo/objs/ctrl/function.rb
Constant Summary collapse
- KEYWORD =
'function'.freeze
- KEYWORD_SHORT =
'ƒ'.freeze
- ON_INVOKE =
Events
'on_invoke'.freeze
- AFTER_INVOKE =
'after_invoke'.freeze
- PARAMS =
Parameters to the function invocation.
'params'.freeze
- RESULT =
Return Value or container of objects
'result'.freeze
Constants inherited from Core::Baseo
Core::Baseo::NOT_IMPLEMENTED_ERR
Instance Attribute Summary
Attributes inherited from Core::Obj
Attributes inherited from Core::Baseo
Class Method Summary collapse
-
.messages ⇒ Object
Get a list of message names that this object receives.
-
.short_typename ⇒ Object
The short name of the object type.
-
.typename ⇒ Object
The name of the object type.
Instance Method Summary collapse
-
#add_children_on_create? ⇒ Boolean
Does this object have children to add when an object is created in interactive mode? This does not apply during obj load, etc.
-
#add_default_children ⇒ Object
Add children to this object.
-
#invoke(args) ⇒ Object
Invoke the function, run the script and return the result.
-
#msg_invoke ⇒ Object
Send the object the invoke message.
-
#multiline_value? ⇒ Boolean
Does this object support multi-line values? Initially only true for scripts.
-
#result ⇒ Object
Get the result, the return value or container of objects.
-
#run_after_invoke ⇒ Object
Run the after invoke script if there is one.
-
#run_on_invoke ⇒ Object
Run the on invoke script if there is one.
-
#set_array_value(arr) ⇒ Object
Set the value as an array.
-
#set_params(args) ⇒ Object
Set parameters from the arguments given.
-
#set_value(new_value) ⇒ Object
Set the value with any necessary type conversions.
Methods inherited from Core::Obj
#add_child, can_create?, #can_receive_message?, #child_count, #child_index, #contains_child?, #delete_children, #dispatch, #display_value, #find_add_child, #find_child, help, inherited, #initialize, #is_alias?, #is_function?, #msg_reload, #msg_unload, #pn, #remove_child, #render, #root?, #send_message, #set_parent, #type_display, #value_display, #value_is_array?, #value_is_blank?, #value_string?
Methods inherited from Core::Baseo
Constructor Details
This class inherits a constructor from Gloo::Core::Obj
Class Method Details
.messages ⇒ Object
Get a list of message names that this object receives.
109 110 111 |
# File 'lib/gloo/objs/ctrl/function.rb', line 109 def self. return super + [ 'invoke' ] end |
.short_typename ⇒ Object
The short name of the object type.
36 37 38 |
# File 'lib/gloo/objs/ctrl/function.rb', line 36 def self.short_typename return KEYWORD_SHORT end |
.typename ⇒ Object
The name of the object type.
29 30 31 |
# File 'lib/gloo/objs/ctrl/function.rb', line 29 def self.typename return KEYWORD end |
Instance Method Details
#add_children_on_create? ⇒ Boolean
Does this object have children to add when an object is created in interactive mode? This does not apply during obj load, etc.
84 85 86 |
# File 'lib/gloo/objs/ctrl/function.rb', line 84 def add_children_on_create? return true end |
#add_default_children ⇒ Object
Add children to this object. This is used by containers to add children needed for default configurations.
93 94 95 96 97 98 99 |
# File 'lib/gloo/objs/ctrl/function.rb', line 93 def add_default_children fac = @engine.factory fac.create_can PARAMS, self fac.create_script ON_INVOKE, '', self fac.create_untyped RESULT, '', self end |
#invoke(args) ⇒ Object
Invoke the function, run the script and return the result.
154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/gloo/objs/ctrl/function.rb', line 154 def invoke args @engine.log.debug "Invoking function: #{name}" set_params args if args run_on_invoke return_value = result @engine.heap.it.set_to return_value run_after_invoke return return_value end |
#msg_invoke ⇒ Object
Send the object the invoke message. Invoke the functdion and return the result.
117 118 119 |
# File 'lib/gloo/objs/ctrl/function.rb', line 117 def msg_invoke return invoke( nil ) end |
#multiline_value? ⇒ Boolean
Does this object support multi-line values? Initially only true for scripts.
58 59 60 |
# File 'lib/gloo/objs/ctrl/function.rb', line 58 def multiline_value? return false end |
#result ⇒ Object
Get the result, the return value or container of objects.
65 66 67 68 69 70 71 72 |
# File 'lib/gloo/objs/ctrl/function.rb', line 65 def result return_any = find_child RESULT # TODO: what does it look like to return objects? # if return_any is a container with children, return the container return return_any ? return_any.value : nil end |
#run_after_invoke ⇒ Object
Run the after invoke script if there is one.
139 140 141 142 143 144 |
# File 'lib/gloo/objs/ctrl/function.rb', line 139 def run_after_invoke o = find_child AFTER_INVOKE return unless o Gloo::Exec::Dispatch.( @engine, 'run', o ) end |
#run_on_invoke ⇒ Object
Run the on invoke script if there is one.
129 130 131 132 133 134 |
# File 'lib/gloo/objs/ctrl/function.rb', line 129 def run_on_invoke o = find_child ON_INVOKE return unless o Gloo::Exec::Dispatch.( @engine, 'run', o ) end |
#set_array_value(arr) ⇒ Object
Set the value as an array.
50 51 52 |
# File 'lib/gloo/objs/ctrl/function.rb', line 50 def set_array_value( arr ) self.value = arr end |
#set_params(args) ⇒ Object
Set parameters from the arguments given.
169 170 171 172 173 174 175 176 177 |
# File 'lib/gloo/objs/ctrl/function.rb', line 169 def set_params args params = find_child PARAMS return unless params args.each_with_index do |arg, i| param = params.children[i] param.value = arg if param end end |
#set_value(new_value) ⇒ Object
Set the value with any necessary type conversions.
43 44 45 |
# File 'lib/gloo/objs/ctrl/function.rb', line 43 def set_value( new_value ) self.value = new_value.to_s end |