ruby / fiddle

A libffi wrapper for Ruby.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Fiddle::CParser should expose module methods

catlee opened this issue · comments

The methods in Fiddle::CParser such as parse_struct_signature are useful on their own, outside of a class instance.

Would it make sense to be able to call these as module methods, in addition to the existing instance method interface?

i.e.

require 'fiddle/cparser'
Fiddle::CParser.parse_struct_signature(...)

Could you share your use case?
We may introduce a new more convenient API instead of exporting parse_struct_signature with the current specification.

I was trying to create a representation of a C structure without having to include Fiddle::CParser or some other module into my namespace.

OK. Then, does the following code satisfy your use case with the current API?

require "fiddle/import"

cparser_class = Class.new do
  include Fiddle::CParser
end
cparser = cparser_class.new
pp cparser.parse_struct_signature(["int i", "char c"]) # => [[4, 2], ["i", "c"]]