Module: DL::CStructBuilder

Module | DL::CStructBuilder
In: | dl/lib/dl/struct.rb

### Methods

create

### Public Instance methods

create(klass, types, members)

[Source]

    # File dl/lib/dl/struct.rb, line 18
        def create(klass, types, members)
          new_class = Class.new(klass){
            define_method(:initialize){|addr|
              @entity = klass.entity_class.new(addr, types)
              @entity.assign_names(members)
            }
            define_method(:to_ptr){ @entity }
            define_method(:to_i){ @entity.to_i }
            members.each{|name|
              define_method(name){ @entity[name] }
              define_method(name + "="){|val| @entity[name] = val }
            }
          }
          size = klass.entity_class.size(types)
          new_class.module_eval("def new_class.size()\n\#{size}\nend\ndef new_class.malloc()\naddr = DL.malloc(\#{size})\nnew(addr)\nend\n")
          return new_class
        end

[Validate]