In Files

  • dl/lib/dl/types.rb

DL::Types

Constants

TYPES

Public Class Methods

new() click to toggle source
 
               # File dl/lib/dl/types.rb, line 163
def initialize
  init_types()
end
            

Public Instance Methods

encode_argument_type(alias_type) click to toggle source
 
               # File dl/lib/dl/types.rb, line 175
def encode_argument_type(alias_type)
  proc_encode = nil
  proc_decode = nil
  @TYDEFS.each{|aty,ty,enc,dec,_,_,_|
    if( (aty.is_a?(Regexp) && (aty =~ alias_type)) || (aty == alias_type) )
      alias_type = alias_type.gsub(aty,ty) if ty
      alias_type.strip! if alias_type
      if( proc_encode )
        if( enc )
          conv1 = proc_encode
          proc_encode = proc{|v| enc.call(conv1.call(v))}
        end
      else
        if( enc )
          proc_encode = enc
        end
      end
      if( proc_decode )
        if( dec )
          conv2 = proc_decode
          proc_decode = proc{|v| dec.call(conv2.call(v))}
        end
      else
        if( dec )
          proc_decode = dec
        end
      end
    end
  }
  return [alias_type, proc_encode, proc_decode]
end
            
encode_return_type(ty) click to toggle source
 
               # File dl/lib/dl/types.rb, line 207
def encode_return_type(ty)
  ty, enc, dec = encode_argument_type(ty)
  return [ty, enc, dec]
end
            
encode_struct_type(alias_type) click to toggle source
 
               # File dl/lib/dl/types.rb, line 212
def encode_struct_type(alias_type)
  proc_encode = nil
  proc_decode = nil
  @TYDEFS.each{|aty,_,_,_,ty,enc,dec|
    if( (aty.is_a?(Regexp) && (aty =~ alias_type)) || (aty == alias_type) )
      alias_type = alias_type.gsub(aty,ty) if ty
      alias_type.strip! if alias_type
      if( proc_encode )
        if( enc )
          conv1 = proc_encode
          proc_encode = proc{|v| enc.call(conv1.call(v))}
        end
      else
        if( enc )
          proc_encode = enc
        end
      end
      if( proc_decode )
        if( dec )
          conv2 = proc_decode
          proc_decode = proc{|v| dec.call(conv2.call(v))}
        end
      else
        if( dec )
          proc_decode = dec
        end
      end
    end
  }
  return [alias_type, proc_encode, proc_decode]
end
            
init_types() click to toggle source
 
               # File dl/lib/dl/types.rb, line 171
def init_types
  @TYDEFS = TYPES.dup
end
            
typealias(ty1, ty2, enc=nil, dec=nil, ty3=nil, senc=nil, sdec=nil) click to toggle source
 
               # File dl/lib/dl/types.rb, line 167
def typealias(ty1, ty2, enc=nil, dec=nil, ty3=nil, senc=nil, sdec=nil)
  @TYDEFS.unshift([ty1, ty2, enc, dec, ty3, senc, sdec])
end