Module: Raudi::Source::Function
- Included in:
- Base
- Defined in:
- lib/raudi/source/function.rb
Instance Method Summary collapse
- #function_arguments(params) ⇒ Object
- #function_block(name, params = {}, &block_source) ⇒ Object
- #generate_function_header(name, params = {}) ⇒ Object
- #generate_result(name, result = nil) ⇒ Object
Instance Method Details
#function_arguments(params) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/raudi/source/function.rb', line 28 def function_arguments(params) arguments_line = "(" arguments_line << if params params = [params] unless params.is_a? Array params.map do |param| argument = result_to_c(param) if param[:array] param[:array] = 1 unless param[:array].is_a?(Integer) argument << ('*' * param[:array]) end argument << param[:name].to_s end.join(", ") else 'void' end arguments_line << ")" end |
#function_block(name, params = {}, &block_source) ⇒ Object
7 8 9 10 |
# File 'lib/raudi/source/function.rb', line 7 def function_block(name, params = {}, &block_source) function_header = generate_function_header(name, params) code_block(function_header, &block_source) end |
#generate_function_header(name, params = {}) ⇒ Object
12 13 14 15 |
# File 'lib/raudi/source/function.rb', line 12 def generate_function_header(name, params = {}) source = '' source << generate_result(name, params[:result]) end |
#generate_result(name, result = nil) ⇒ Object
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/raudi/source/function.rb', line 17 def generate_result(name, result = nil) if result.is_a?(Hash) result[:type] ||= :void result[:name] = name generate_variable result else result ||= :void generate_variable name: name, type: result end end |