Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fiddle::CParser should expose module methods #125

Open
catlee opened this issue Apr 12, 2023 · 3 comments
Open

Fiddle::CParser should expose module methods #125

catlee opened this issue Apr 12, 2023 · 3 comments

Comments

@catlee
Copy link

catlee commented Apr 12, 2023

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(...)
@kou
Copy link
Member

kou commented Apr 13, 2023

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

@catlee
Copy link
Author

catlee commented Apr 19, 2023

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

@kou
Copy link
Member

kou commented Apr 20, 2023

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"]]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants