Class: Runtime

Inherits:
Object
  • Object
show all
Defined in:
lib/runtime.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename) ⇒ Runtime

Returns a new instance of Runtime.



198
199
200
201
202
203
204
205
206
207
208
209
# File 'lib/runtime.rb', line 198

def initialize filename
	@filename = filename
	@builtins = {}
	@version = 1
	@enums = {}
	@nodes = {}
	@structs = {}
	@directions = []
	@sequences = {}

	self.init_builtins
end

Instance Attribute Details

#builtinsObject (readonly)

Returns the value of attribute builtins.



190
191
192
# File 'lib/runtime.rb', line 190

def builtins
  @builtins
end

#directionsObject (readonly)

Returns the value of attribute directions.



195
196
197
# File 'lib/runtime.rb', line 195

def directions
  @directions
end

#enumsObject (readonly)

Returns the value of attribute enums.



193
194
195
# File 'lib/runtime.rb', line 193

def enums
  @enums
end

#filenameObject (readonly)

Returns the value of attribute filename.



189
190
191
# File 'lib/runtime.rb', line 189

def filename
  @filename
end

#nodesObject (readonly)

Returns the value of attribute nodes.



192
193
194
# File 'lib/runtime.rb', line 192

def nodes
  @nodes
end

#sequencesObject (readonly)

Returns the value of attribute sequences.



196
197
198
# File 'lib/runtime.rb', line 196

def sequences
  @sequences
end

#structsObject (readonly)

Returns the value of attribute structs.



194
195
196
# File 'lib/runtime.rb', line 194

def structs
  @structs
end

#versionObject

Returns the value of attribute version.



191
192
193
# File 'lib/runtime.rb', line 191

def version
  @version
end

Instance Method Details

#add_direction(direction_def) ⇒ Object



262
263
264
# File 'lib/runtime.rb', line 262

def add_direction direction_def
	@directions.push direction_def
end

#add_enum(enum_def) ⇒ Object



236
237
238
# File 'lib/runtime.rb', line 236

def add_enum enum_def
	@enums[enum_def.name] = enum_def
end

#add_node(node_def) ⇒ Object



240
241
242
243
# File 'lib/runtime.rb', line 240

def add_node node_def
	@nodes[node_def.name] = node_def
	@nodes[node_def.nickname] = node_def if node_def.name != node_def.nickname
end

#add_sequence(sequence_def) ⇒ Object



273
274
275
# File 'lib/runtime.rb', line 273

def add_sequence sequence_def
	@sequences[sequence_def.name] = sequence_def
end

#add_struct(struct_def) ⇒ Object



245
246
247
# File 'lib/runtime.rb', line 245

def add_struct struct_def
	@structs[struct_def.name] = struct_def
end

#get_direction(client, direction, server) ⇒ Object



266
267
268
269
270
271
# File 'lib/runtime.rb', line 266

def get_direction client, direction, server
	dir = @directions.find { |d| d.client == client and d.server == server and d.direction == direction }
	return dir if dir != nil

	return nil
end

#get_node_directions(node, side) ⇒ Object



284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
# File 'lib/runtime.rb', line 284

def get_node_directions node, side
	node_directions = {}
	@directions.each do |direction|
		next if side == :client and direction.client != node
		next if side == :server and direction.server != node

		opposite_node = nil
		case side
		when :client
			opposite_node = direction.server
		when :server
			opposite_node = direction.client
		end

		node_direction = node_directions[opposite_node]
		if node_direction == nil
			node_direction = NodeDirection.new node, opposite_node
			node_directions[opposite_node] = node_direction
		end

		if side == :client and direction.direction == :left
			node_direction.in_direction = direction
		elsif side == :client and direction.direction == :right
			node_direction.out_direction = direction
		elsif side == :server and direction.direction == :left
			node_direction.out_direction = direction
		elsif side == :server and direction.direction == :right
			node_direction.in_direction = direction
		end
	end
	node_directions.values
end

#get_sequence(name) ⇒ Object



277
278
279
280
281
282
# File 'lib/runtime.rb', line 277

def get_sequence name
	sequence = @sequences[name]
	return sequence if sequence != nil

	return nil
end

#get_type(name) ⇒ Object



249
250
251
252
253
254
255
256
257
258
259
260
# File 'lib/runtime.rb', line 249

def get_type name
	type_def = @builtins[name]
	return type_def, self if type_def != nil

	type_def = @enums[name]
	return type_def, self if type_def != nil

	type_def = @structs[name]
	return type_def, self if type_def != nil

	return nil, self
end

#init_builtinsObject



211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
# File 'lib/runtime.rb', line 211

def init_builtins
	type_names = [
		'Bool',
		'Byte',
		'Short',
		'Int',
		'Long',
		'UShort',
		'UInt',
		'ULong',
		'Float',
		'Double',
		'String',
		'DateTime',
		'ByteBuffer',
		'List',
		'Set',
		'Map',
		'Vector2',
		'Vector3',
		'Color',
	]
	type_names.each { |t| @builtins[t] = BuiltinTypeDef.new t }
end