Method: MrubyBridgeSignaturePluginModule#ptrMrb2C

Defined in:
lib/tecsgen/plugin/lib/MrubyBridgeSignaturePluginModule.rb

#ptrMrb2C(file, type, param) ⇒ Object



152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
# File 'lib/tecsgen/plugin/lib/MrubyBridgeSignaturePluginModule.rb', line 152

def ptrMrb2C file, type, param
  ttype = type.get_type.get_original_type
  tment = get_type_map_ent ttype
  tstr = tment[1]
=begin
  case ttype
  when IntType
    bit_size = ttype.get_bit_size
    case bit_size
    when -1, -11
      tstr = "Char"
    when 8, 16, 32, 64
      tstr = "Int#{bit_size}"
    when -2
      tstr = "Short"
    when -3
      tstr = "Int"
    when -4
      tstr = "Long"
    when -5
      tstr = "IntPtr"
    else
      raise "MrubyBridgeSignaturePlugin: not handle type"
    end
  when FloatType
    if ttype.get_bit_size == 32 then
      tstr = "Float32"
    else
      tstr = "Double64"
    end
  when BoolType
    tstr = "Bool"
  when StructType
    raise "MrubyBridgeSignaturePlugin: not handle type 2 #{ttype}"
  else
    raise "MrubyBridgeSignaturePlugin: not handle type 2 #{ttype}"
  end
=end

  if( param.get_size ) then
    sz_str = param.get_size.to_s
  elsif param.get_string then      # mikan とりあえず size_is と string の同時指定 (二重ポインタ) はなし
    sz_str = param.get_string.to_s
  else
    sz_str = "1"
  end
  # unsigned 型の場合には cast が必要
  if ttype.get_original_type.get_type_str != param.get_type.get_type.get_type_str then
    cast_str = "(#{param.get_type.get_type_str})"
  else
    cast_str = ""
  end

  modify = ""
  case param.get_direction
  when :OUT, :INOUT
    case tstr
    when "Char", "SChar", "UChar"
      modify = "Mod"
    end
  end
  if param.is_nullable? then
    nullable = "Nullable"
  else
    nullable = ""
  end

  # file.print "  CHECK_POINTER( #{tstr}, mrb_#{param.get_name}, #{sz_str} );\n"
  # file.print "  #{param.get_name} = #{cast_str}((struct #{tstr}PointerBody*)(DATA_PTR(mrb_#{param.get_name})))->buf;\n"
  file.print "  #{param.get_name} = CheckAndGet#{tstr}Pointer#{modify}#{nullable}( mrb, mrb_#{param.get_name}, #{sz_str} );\n"
end