Class: RubimCode::UserClass

Inherits:
UserVariable show all
Defined in:
lib/rubimc.rb

Overview

Наследник всех пользовательских классов

Constant Summary collapse

@@var_array =

список всех пользовательских “свойств” класса

{}

Instance Attribute Summary

Attributes inherited from UserVariable

#name, #type

Class Method Summary collapse

Methods inherited from UserVariable

#!=, #!@, #%, #&, #*, #**, #+, #+@, #-, #-@, #/, #<, #<<, #<=, #==, #>, #>=, #>>, #^, #c_assign=, #common_operator, #initialize, #times, #to_bool, #to_i, #to_rubim, #to_s, #|, #~@

Constructor Details

This class inherits a constructor from RubimCode::UserVariable

Class Method Details

.add_var_array(user_class_name, value) ⇒ Object



179
180
181
182
# File 'lib/rubimc.rb', line 179

def self.add_var_array(user_class_name, value)
	@@var_array[user_class_name.to_sym] ||= []
	@@var_array[user_class_name.to_sym] << value
end

.generate_structObject

генерация класса (typedef struct + методы)



185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
# File 'lib/rubimc.rb', line 185

def self.generate_struct
	RubimCode.pout "typedef struct {"
	RubimCode.level +=1
	@@var_array[self.to_s.to_sym].each do |var| 
		RubimCode.pout "#{var.type} #{var.name};"
	end
	RubimCode.pout "} #{self.to_s};"
	RubimCode.level -=1

	public_instance_methods(false).each do |method_name| 
		tmp_str = ""
		pout_destination = tmp_str
		return_var = self.new("(*params)").send(method_name).to_rubim
		pout_destination = :default
		return_var.type = "void" if return_var.type.nil? # if type is not set

		RubimCode.pout "#{return_var.type} #{method_name.to_s} (#{self.to_s} *params) {"
		RubimCode.level += 1
			self.new("(*params)").send(method_name)
			RubimCode.pout "return #{return_var};"
			RubimCode.pout "}"
		RubimCode.level -= 1
	end
end

.redefine_users_methodsObject



210
211
212
213
214
215
216
# File 'lib/rubimc.rb', line 210

def self.redefine_users_methods
	public_instance_methods(false).each do |method_name|
		define_method(method_name) do
			"#{__method__}(&#{self.name})" 
		end
	end
end