In Files

  • dl/lib/dl/struct.rb

Parent

Methods

DL::Importable::Internal::Memory

Public Class Methods

new(ptr, names, ty, len, enc, dec) click to toggle source
 
               # File dl/lib/dl/struct.rb, line 22
def initialize(ptr, names, ty, len, enc, dec)
  @ptr = ptr
  @names = names
  @ty    = ty
  @len   = len
  @enc   = enc
  @dec   = dec

  # define methods
  @names.each{|name|
    instance_eval [
      "def #{name}",
      "  v = @ptr[\"#{name}\"]",
      "  if( @len[\"#{name}\"] )",
      "    v = v.collect{|x| @dec[\"#{name}\"] ? @dec[\"#{name}\"].call(x) : x }",
      "  else",
      "    v = @dec[\"#{name}\"].call(v) if @dec[\"#{name}\"]",
      "  end",
      "  return v",
      "end",
      "def #{name}=(v)",
      "  if( @len[\"#{name}\"] )",
      "    v = v.collect{|x| @enc[\"#{name}\"] ? @enc[\"#{name}\"].call(x) : x }",
      "  else",
      "    v = @enc[\"#{name}\"].call(v) if @enc[\"#{name}\"]",
      "  end",
      "  @ptr[\"#{name}\"] = v",
      "  return v",
      "end",
    ].join("\n")
  }
end
            

Public Instance Methods

size() click to toggle source
 
               # File dl/lib/dl/struct.rb, line 59
def size
  return @ptr.size
end
            
to_ptr() click to toggle source
 
               # File dl/lib/dl/struct.rb, line 55
def to_ptr
  return @ptr
end