Class: Gloo::Objs::Function

Inherits:
Core::Obj show all
Defined in:
lib/gloo/objs/basic/function.rb

Constant Summary collapse

KEYWORD =
'function'.freeze
KEYWORD_SHORT =
'ƒ'.freeze
ON_INVOKE =

Events

'on_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

#children, #parent, #value

Attributes inherited from Core::Baseo

#name

Class Method Summary collapse

Instance Method Summary collapse

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?, #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

#initialize, #type_display

Constructor Details

This class inherits a constructor from Gloo::Core::Obj

Class Method Details

.messagesObject

Get a list of message names that this object receives.



108
109
110
# File 'lib/gloo/objs/basic/function.rb', line 108

def self.messages
  return super + [ 'invoke' ]
end

.short_typenameObject

The short name of the object type.



35
36
37
# File 'lib/gloo/objs/basic/function.rb', line 35

def self.short_typename
  return KEYWORD_SHORT
end

.typenameObject

The name of the object type.



28
29
30
# File 'lib/gloo/objs/basic/function.rb', line 28

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.

Returns:



83
84
85
# File 'lib/gloo/objs/basic/function.rb', line 83

def add_children_on_create?
  return true
end

#add_default_childrenObject

Add children to this object. This is used by containers to add children needed for default configurations.



92
93
94
95
96
97
98
# File 'lib/gloo/objs/basic/function.rb', line 92

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.



143
144
145
146
147
148
149
150
151
152
# File 'lib/gloo/objs/basic/function.rb', line 143

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
  
  return return_value
end

#msg_invokeObject

Send the object the invoke message. Invoke the functdion and return the result.



116
117
118
# File 'lib/gloo/objs/basic/function.rb', line 116

def msg_invoke
  return invoke( nil )
end

#multiline_value?Boolean

Does this object support multi-line values? Initially only true for scripts.

Returns:



57
58
59
# File 'lib/gloo/objs/basic/function.rb', line 57

def multiline_value?
  return false
end

#resultObject

Get the result, the return value or container of objects.



64
65
66
67
68
69
70
71
# File 'lib/gloo/objs/basic/function.rb', line 64

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_on_invokeObject

Run the on invoke script if there is one.



128
129
130
131
132
133
# File 'lib/gloo/objs/basic/function.rb', line 128

def run_on_invoke
  o = find_child ON_INVOKE
  return unless o

  Gloo::Exec::Dispatch.message( @engine, 'run', o )
end

#set_array_value(arr) ⇒ Object

Set the value as an array.



49
50
51
# File 'lib/gloo/objs/basic/function.rb', line 49

def set_array_value( arr )
  self.value = arr
end

#set_params(args) ⇒ Object

Set parameters from the arguments given.



157
158
159
160
161
162
163
164
165
# File 'lib/gloo/objs/basic/function.rb', line 157

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.



42
43
44
# File 'lib/gloo/objs/basic/function.rb', line 42

def set_value( new_value )
  self.value = new_value.to_s
end