{"id":13806897,"url":"https://github.com/Anyolite/anyolite","last_synced_at":"2025-05-13T23:33:31.242Z","repository":{"id":50885906,"uuid":"282045399","full_name":"Anyolite/anyolite","owner":"Anyolite","description":"Embedded mruby/Ruby for Crystal","archived":false,"fork":false,"pushed_at":"2024-10-05T16:39:22.000Z","size":1637,"stargazers_count":168,"open_issues_count":2,"forks_count":9,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-05-12T15:04:40.987Z","etag":null,"topics":["crystal","mruby","ruby","scripting"],"latest_commit_sha":null,"homepage":"https://anyolite.github.io/anyolite","language":"Crystal","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/Anyolite.png","metadata":{"files":{"readme":"README.md","changelog":"Changelog.md","contributing":null,"funding":null,"license":"LICENSE","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}},"created_at":"2020-07-23T20:07:51.000Z","updated_at":"2025-04-15T06:25:39.000Z","dependencies_parsed_at":"2023-02-01T03:15:29.650Z","dependency_job_id":"9b4029ec-2b3c-470b-b399-4cdcfb82db81","html_url":"https://github.com/Anyolite/anyolite","commit_stats":null,"previous_names":[],"tags_count":32,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Anyolite%2Fanyolite","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Anyolite%2Fanyolite/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Anyolite%2Fanyolite/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Anyolite%2Fanyolite/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Anyolite","download_url":"https://codeload.github.com/Anyolite/anyolite/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254043218,"owners_count":22004912,"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":["crystal","mruby","ruby","scripting"],"created_at":"2024-08-04T01:01:17.698Z","updated_at":"2025-05-13T23:33:31.096Z","avatar_url":"https://github.com/Anyolite.png","language":"Crystal","readme":"# Anyolite\r\n\r\nAnyolite is a Crystal shard which adds a fully functional mruby (or even regular Ruby) interpreter to Crystal.\r\n\r\n![Test](https://github.com/Anyolite/anyolite/workflows/Test/badge.svg)\r\n\r\n![Release](https://img.shields.io/github/v/release/Anyolite/anyolite)\r\n![ReleaseDate](https://img.shields.io/github/release-date/Anyolite/anyolite)\r\n\r\n![License](https://img.shields.io/github/license/Anyolite/anyolite)\r\n\r\n# Description\r\n\r\nAnyolite allows for wrapping Crystal classes and functions into Ruby with little effort.\r\nThis way, Ruby can be used as a scripting language to Crystal projects, with the major advantage of a similar syntax.\r\n\r\nUseful links for an overview:\r\n* Demo project: https://github.com/Anyolite/ScapoLite\r\n* Wiki: https://github.com/Anyolite/anyolite/wiki\r\n* Documentation: https://anyolite.github.io/anyolite\r\n\r\n# Features\r\n\r\n* Bindings to an mruby interpreter\r\n* Near complete support to regular Ruby as alternative implementation (also known as MRI or CRuby)\r\n* Wrapping of nearly arbitrary Crystal classes and methods to Ruby\r\n* Easy syntax without unnecessary boilerplate code\r\n* Simple system to prevent garbage collector conflicts\r\n* Support for keyword arguments and default values\r\n* Objects, arrays, hashes, structs, enums and unions as function arguments and return values are completely valid\r\n* Ruby methods can be called at runtime as long as all their possible return value types are known\r\n* Ruby closures can be handled as regular variables\r\n* Methods and constants can be excluded, modified or renamed with annotations\r\n* Options to compile scripts directly into the executable\r\n\r\n# Prerequisites\r\n\r\nYou need to have the following programs installed (and in your PATH variable, if you are on Windows):\r\n* Ruby (for building mruby)\r\n* Rake (for building the whole project)\r\n* Git (for downloading mruby)\r\n* GCC or Microsoft Visual Studio 19 (for building the object files required for Anyolite, depending on your OS)\r\n\r\n## Using regular Ruby instead of mruby\r\n\r\nIt is possible to use Anyolite with regular Ruby (MRI) instead of mruby. An instruction to install MRI can be found at [Using Ruby instead of mruby](https://github.com/Anyolite/anyolite/wiki/Using-Ruby-instead-of-mruby) in the wiki.\r\n\r\n# Installing\r\n\r\nPut this shard as a requirement into your shard.yml project file and then call\r\n```bash\r\nshards install\r\n```\r\nfrom a terminal.\r\n\r\nAlternatively, you can clone this repository into the lib folder of your project and run\r\n```bash\r\nrake build_shard\r\n```\r\nmanually from a terminal or the MSVC Developer Console (on Windows) to install the shard without using the crystal shards program.\r\n\r\nIf you want to use other options for Anyolite, visit [Changing build configurations](https://github.com/Anyolite/anyolite/wiki/Changing-build-configurations) in the wiki.\r\n\r\n# How to use\r\n\r\nImagine a Crystal class for a really bad RPG:\r\n\r\n```crystal\r\nmodule RPGTest\r\n  class Entity\r\n    property hp : Int32\r\n\r\n    def initialize(@hp : Int32)\r\n    end\r\n\r\n    def damage(diff : Int32)\r\n      @hp -= diff\r\n    end\r\n\r\n    def yell(sound : String, loud : Bool = false)\r\n      if loud\r\n        puts \"Entity yelled: #{sound.upcase}\"\r\n      else\r\n        puts \"Entity yelled: #{sound}\"\r\n      end\r\n    end\r\n\r\n    def absorb_hp_from(other : Entity)\r\n      @hp += other.hp\r\n      other.hp = 0\r\n    end\r\n  end\r\nend\r\n```\r\n\r\nNow, you want to wrap this class in Ruby. All you need to do is to execute the following code in Crystal (current commit; see documentation page for the version of the latest release):\r\n\r\n```crystal\r\nrequire \"anyolite\"\r\n\r\nAnyolite::RbInterpreter.create do |rb|\r\n  Anyolite.wrap(rb, RPGTest)\r\n\r\n  rb.load_script_from_file(\"examples/hp_example.rb\")\r\nend\r\n```\r\n\r\nWell, that's it already. \r\nThe last line in the block calls the following example script:\r\n\r\n```ruby\r\na = RPGTest::Entity.new(hp: 20)\r\na.damage(diff: 13)\r\nputs a.hp\r\n\r\nb = RPGTest::Entity.new(hp: 10)\r\na.absorb_hp_from(other: b)\r\nputs a.hp\r\nputs b.hp\r\nb.yell(sound: 'Ouch, you stole my HP!', loud: true)\r\na.yell(sound: 'Well, take better care of your public attributes!')\r\n```\r\n\r\nThe example above gives a good overview over the things you can already do with Anyolite.\r\nMore features will be added in the future.\r\n\r\n# Limitations\r\n\r\nSee [Limitations and solutions](https://github.com/Anyolite/anyolite/wiki/Limitations-and-solutions) in the Wiki section for a detailed list.\r\n\r\n# Why this name?\r\n\r\nhttps://en.wikipedia.org/wiki/Anyolite\r\n\r\nIn short, it is a rare variant of the crystalline mineral called zoisite, with ruby and other crystal shards (of pargasite) embedded.\r\n\r\nThe term 'anyoli' means 'green' in the Maasai language, thus naming 'anyolite'.\r\n\r\n# Roadmap\r\n\r\n## Upcoming releases\r\n\r\n### Version 1.1.2\r\n\r\n#### Bugfixes\r\n\r\n* [X] Fixed broken documentation\r\n* [X] Fixed pointers not working as regular arguments\r\n\r\n### Version 2.0.0\r\n\r\nIMPORTANT: Version 2.0.0 will introduce breaking changes to improve the general user experience.\r\n\r\nThis means that the build process and some parts of the API will change. There will be a dedicated\r\nsection in the Wiki for migrating from Anyolite 1 to Anyolite 2, so compatibility can easily be\r\nrestored.\r\n\r\nThe list of features for Anyolite 2 will expand over time, while development on Anyolite 1 continues\r\nuntil Anyolite 2 is released.\r\n\r\n#### Breaking changes\r\n\r\n* [ ] Discard postinstall option in favor of more sophisticated build script\r\n* [ ] Simplify building with custom options\r\n* [ ] Set optional arguments being keywords for method as default\r\n* [ ] Add option for using either dynamic or static linking\r\n\r\n#### Usability\r\n\r\n* [ ] Add Wiki section about migrating from Anyolite 1\r\n* [ ] Add error messages when using wrong annotation syntax\r\n\r\n### Later releases\r\n\r\n* [ ] Automated generation of Ruby documentations for wrapped functions\r\n* [ ] MRI support on Windows (does currently not work for some reason)\r\n* [ ] MRI support for version 3.1.0 and up\r\n* [ ] Support and continuous integration for Mac\r\n* [ ] Support for bindings using `Data` and `Struct` from Ruby\r\n* [ ] Multiple interpreters for mruby\r\n* [ ] Add option to make script calls thread-safe\r\n\r\n### Wishlist, entries might not be possible to implement\r\n\r\n* [ ] Splat argument and/or arbitrary keyword passing\r\n* [ ] Support for slices and bytes\r\n* [ ] Classes as argument type\r\n* [ ] Resolve context even in generic type union arguments\r\n* [ ] General improvement of type resolution\r\n* [ ] Bignum support\r\n* [ ] Range support\r\n","funding_links":[],"categories":["Misc"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FAnyolite%2Fanyolite","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FAnyolite%2Fanyolite","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FAnyolite%2Fanyolite/lists"}