method
wrap_arg
v2_1_10 -
Show latest stable
-
0 notes -
Class: ValueUtil
- 1_8_6_287
- 1_8_7_72
- 1_8_7_330
- 1_9_1_378
- 1_9_2_180
- 1_9_3_125
- 1_9_3_392
- 2_1_10 (0)
- 2_2_9 (0)
- 2_4_6 (0)
- 2_5_5 (0)
- 2_6_3 (0)
- What's this?
wrap_arg(arg, ty, funcs = [], &block)
public
Hide source
# File ext/fiddle/lib/fiddle/value.rb, line 48 def wrap_arg(arg, ty, funcs = [], &block) funcs ||= [] case arg when nil return 0 when Pointer return arg.to_i when IO case ty when TYPE_VOIDP return Pointer[arg].to_i else return arg.to_i end when Function if( block ) arg.bind_at_call(&block) funcs.push(arg) elsif !arg.bound? raise(RuntimeError, "block must be given.") end return arg.to_i when String if( ty.is_a?(Array) ) return arg.unpack('C*') else case SIZEOF_VOIDP when SIZEOF_LONG return [arg].pack("p").unpack("l!")[0] when SIZEOF_LONG_LONG return [arg].pack("p").unpack("q")[0] else raise(RuntimeError, "sizeof(void*)?") end end when Float, Integer return arg when Array if( ty.is_a?(Array) ) # used only by struct case ty[0] when TYPE_VOIDP return arg.collect{|v| Integer(v)} when TYPE_CHAR if( arg.is_a?(String) ) return val.unpack('C*') end end return arg else return arg end else if( arg.respond_to?(:to_ptr) ) return arg.to_ptr.to_i else begin return Integer(arg) rescue raise(ArgumentError, "unknown argument type: #{arg.class}") end end end end