{"id":15032805,"url":"https://github.com/ruby/fiddle","last_synced_at":"2025-05-14T07:08:21.078Z","repository":{"id":19571302,"uuid":"87246714","full_name":"ruby/fiddle","owner":"ruby","description":"A libffi wrapper for Ruby.","archived":false,"fork":false,"pushed_at":"2025-04-19T21:57:37.000Z","size":652,"stargazers_count":173,"open_issues_count":18,"forks_count":41,"subscribers_count":40,"default_branch":"master","last_synced_at":"2025-04-19T22:55:36.751Z","etag":null,"topics":["fiddle","libffi","ruby"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ruby.png","metadata":{"files":{"readme":"README.md","changelog":"NEWS.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2017-04-05T00:03:38.000Z","updated_at":"2025-04-19T21:57:42.000Z","dependencies_parsed_at":"2025-04-11T04:08:43.333Z","dependency_job_id":"f9a12687-3435-449f-b705-ad55d177aa58","html_url":"https://github.com/ruby/fiddle","commit_stats":{"total_commits":454,"total_committers":56,"mean_commits":8.107142857142858,"dds":0.7202643171806167,"last_synced_commit":"c3dbf7ba9a618f00366b077391eb21fd88df88bf"},"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ruby%2Ffiddle","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ruby%2Ffiddle/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ruby%2Ffiddle/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ruby%2Ffiddle/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ruby","download_url":"https://codeload.github.com/ruby/fiddle/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254092659,"owners_count":22013290,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["fiddle","libffi","ruby"],"created_at":"2024-09-24T20:19:29.259Z","updated_at":"2025-05-14T07:08:21.044Z","avatar_url":"https://github.com/ruby.png","language":"Ruby","readme":"# Fiddle\n\n[![CI](https://github.com/ruby/fiddle/actions/workflows/ci.yml/badge.svg)](https://github.com/ruby/fiddle/actions/workflows/ci.yml)\n\nA libffi wrapper for Ruby.\n\nFiddle is an extension to translate a foreign function interface (FFI) with ruby.\n\nIt wraps [libffi](http://sourceware.org/libffi/), a popular C library which provides a portable interface that allows code written in one language to call code written in another language.\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'fiddle'\n```\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install fiddle\n\n## Usage\n\n Here we will use Fiddle::Function to wrap [floor(3) from libm](http://linux.die.net/man/3/floor)\n\n```ruby\nrequire 'fiddle'\n\nlibm = Fiddle.dlopen('/lib/libm.so.6')\n\nfloor = Fiddle::Function.new(\n          libm['floor'],\n          [Fiddle::TYPE_DOUBLE],\n          Fiddle::TYPE_DOUBLE\n        )\n\nputs floor.call(3.14159) #=\u003e 3.0\n```\n\n### Nested Structs\n\nYou can use hashes to create nested structs, where the hash keys are member names and the values are the nested structs:\n\n```ruby\nStudentCollegeDetail = struct [\n  'int college_id',\n  'char college_name[50]'\n]\n\nStudentDetail = struct [\n  'int id',\n  'char name[20]',\n  { clg_data: StudentCollegeDetail }\n]\n```\n\nYou can also specify an anonymous nested struct, like so:\n\n```ruby\nStudentDetail = struct [\n  'int id',\n  'char name[20]',\n  {\n    clg_data: struct([\n                      'int college_id',\n                      'char college_name[50]'\n                    ])\n  }\n]\n```\n\nThe position of a hash (and the order of the keys in the hash, in the case of a hash with multiple entries), dictate the offsets of the nested struct in memory. The following examples are both syntactically valid but will lay out the structs differently in memory:\n\n```ruby\n# order of members in memory: position, id, dimensions\nRect = struct [ { position: struct(['float x', 'float y']) },\n                'int id',\n                { dimensions: struct(['float w', 'float h']) }\n              ]\n\n# order of members in memory: id, position, dimensions\nRect = struct [ 'int id',\n                {\n                  position: struct(['float x', 'float y']),\n                  dimensions: struct(['float w', 'float h'])\n                }\n              ]\n```\n\n\n## Development\n\nAfter checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.\n\nTo install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/ruby/fiddle.\n\n\n## License\n\nThe gem is available as open source under the terms of the [BSD-2-Clause](https://opensource.org/licenses/BSD-2-Clause).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fruby%2Ffiddle","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fruby%2Ffiddle","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fruby%2Ffiddle/lists"}