{"id":19260582,"url":"https://github.com/evant/crequire","last_synced_at":"2025-10-04T10:55:22.198Z","repository":{"id":59152554,"uuid":"2508125","full_name":"evant/crequire","owner":"evant","description":"A simple way to require c code in ruby using SWIG","archived":false,"fork":false,"pushed_at":"2020-06-14T22:46:31.000Z","size":672,"stargazers_count":2,"open_issues_count":1,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-10-07T21:50:59.253Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/evant.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2011-10-03T21:53:12.000Z","updated_at":"2018-05-09T13:35:34.000Z","dependencies_parsed_at":"2022-09-13T11:00:55.086Z","dependency_job_id":null,"html_url":"https://github.com/evant/crequire","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/evant%2Fcrequire","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/evant%2Fcrequire/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/evant%2Fcrequire/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/evant%2Fcrequire/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/evant","download_url":"https://codeload.github.com/evant/crequire/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223817682,"owners_count":17207947,"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":[],"created_at":"2024-11-09T19:21:48.838Z","updated_at":"2025-10-04T10:55:17.145Z","avatar_url":"https://github.com/evant.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# crequire\n\nA simply DSL to require c code in ruby using SWIG.\n\n## Install\n`gem install crequire`\n\n## Dependencies\n\n* ruby 1.9\n* make\n* SWIG\n\n## A simple example\n\nIf you have a header file then the functions are detected automatically. You\ncan either define the functions in the header file or define a header and\nimplementation file separately.\n\n### example1.h\n\n```c\nint fact(int n) {\n  if (n \u003c= 1) return 1;\n  else return n * fact(n-1);\n}\n\nvoid swap(int *a, int *b) {\n  int tmp;\n  tmp = *b;\n  *b = *a;\n  *a = tmp;\n}\n```\n\n### test_example1.rb\n\n```ruby\nrequire \"crequire\"\ncrequire \"example1\"\ninclude Example1\n\nfact(4) =\u003e 24\n\na = Intp.new\na.assign 1\nb = Intp.new\nb.assign 2\n\nswap(a, b)\n\na.value =\u003e 2\nb.value =\u003e 1\n```\n\n## A complex example\n\nIf you don't define a header file, you must pass in a block to define the\nmethod signatures.\n\n### example2.c\n\n```c\nint sum(int a, int b) {\n  return a + b;\n}\n\nvoid add(int *x, int *y, int *r) {\n  *r = *x + *y;\n}\n\nchar* echo(char* word) {\n  return word;\n}\n```\n\n### test_example2.rb\n\n```ruby\nrequire \"crequire\"\n\ncrequire \"example2\" do\n  # To define a function signature, declare the type followed by the function\n  # name, passing in the types as symbols or strings.\n\n  int sum(:int, :int)\n\n  # To make working with pointers easer, you can define them as *INPUT or\n  # *OUTPUT.\n\n  void add(\"int *INPUT\", \"int *INPUT\", \"int *OUTPUT\")\n\n  # char* is automatically converted to and from string\n  char* echo(\"char*\")\nend\n\ninclude Example2\n\nsum(1, 2) =\u003e 3\nadd(3, 4) =\u003e 7\necho(\"hi\") =\u003e \"hi\"\n```\n\n## Advanced Options\n\n```:force =\u003e true``` Forces a compile on every run. Otherwise compile only\nhappens if compiled no file is found.\n\n```:src =\u003e \"string\"``` Defines the contents of the interface file directly.\n\n```:interface =\u003e \"dir\"``` Outputs the generated interface file to the given directory.\n\n```:dump =\u003e \"dir\"``` Outputs all generated files to the given directory. \n\n```:cflags =\u003e \"flags\"``` Pass cflags to make.\n\n### example2.c\n\n```c\nint sum(int a, int b, int times) {\n  int result = a;\n  for (int i = 0; i \u003c times; i++) {\n    result += b;\n  }\n  return result;\n}\n```\n\n### test_example3.rb\n\n```ruby\nrequire 'crequire'\n\ninterface = \"%module example3 \n%{ \nextern int sum(int a, int b, int times);\n%}\nextern int sum(int a, int b, int times);\" \n\ncrequire \"example3\", :force =\u003e true, :cflags =\u003e \"-std=c99\", :interface =\u003e \"example3\", :src =\u003e interface\n\ninclude Example3\n\nsum(1, 2, 2) =\u003e 5\n```\n\n### example3/example3.i\n\n```c\n%module example3\n%{\nextern int sum(int a, int b);\n%}\nextern int sum(int a, int b);\n```\n\n## Contributing to crequire\n \n* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet\n* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it\n* Fork the project\n* Start a feature/bugfix branch\n* Commit and push until you are happy with your contribution\n* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.\n* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.\n\n## Copyright\n\nCopyright (c) 2011 Evan Tatarka. See LICENSE.txt for\nfurther details.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fevant%2Fcrequire","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fevant%2Fcrequire","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fevant%2Fcrequire/lists"}