Extended maintenance of Ruby versions 1.8.7 and 1.9.2 ended on July 31, 2014. Read more

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 21
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 58
def size
  return @ptr.size
end
            
to_ptr() click to toggle source
 
               # File dl/lib/dl/struct.rb, line 54
def to_ptr
  return @ptr
end
            

Commenting is here to help enhance the documentation. For example, code samples, or clarification of the documentation.

If you have questions about Ruby or the documentation, please post to one of the Ruby mailing lists. You will get better, faster, help that way.

If you wish to post a correction of the docs, please do so, but also file bug report so that it can be corrected for the next release. Thank you.

If you want to help improve the Ruby documentation, please visit Documenting-ruby.org.

blog comments powered by Disqus