-
-
Notifications
You must be signed in to change notification settings - Fork 36
Description
This is just for collecting my thoughts and getting feedback on a DSL for MachOStructure
(and, by inheritance, just about every Mach-O data-oriented class in ruby-macho
.
The current "DSL" for a Mach-O structure looks something like this:
class SomeImportantStruct < MachOStructure
attr_reader :something
attr_reader :something_else
FORMAT = "L=2" # something and something_else are "L", meaning int32s
SIZEOF = 8 # 2 x sizeof(int32)
def initialize(something, something_else)
# ...
end
end
This is incredibly repetitive, bug-prone, and difficult to read (there's no immediate way to determine the size of each field).
Something like this would be substantially better:
class SomeImportantStruct < MachOStructure
field :int32, :something
field :int32, :something_else
# FORMAT, SIZEOF, and instantiation are automatically generated from the field definitions
end
Extremely early versions of ruby-macho
actually had something like this, using CStruct
from this repo, but I dropped it for reasons that I don't remember (probably having to do with me being unfamiliar with ruby DSL writing at the time).
This will probably require a large amount of refactoring and breakage, so I don't think it'll make it into 1.1 (or even 1.x, it might be destined for a major bump).