{"id":13440043,"url":"https://github.com/rhaiscript/rhai","last_synced_at":"2025-05-12T05:29:42.820Z","repository":{"id":37784763,"uuid":"52825741","full_name":"rhaiscript/rhai","owner":"rhaiscript","description":"Rhai - An embedded scripting language for Rust.","archived":false,"fork":false,"pushed_at":"2025-05-05T04:51:05.000Z","size":14384,"stargazers_count":4564,"open_issues_count":40,"forks_count":194,"subscribers_count":30,"default_branch":"main","last_synced_at":"2025-05-12T04:08:31.779Z","etag":null,"topics":["embedded","embedded-scripting-language","no-std","rhai","scripting-engine","scripting-language","wasm","webassembly"],"latest_commit_sha":null,"homepage":"https://crates.io/crates/rhai","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rhaiscript.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE-APACHE.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":"2016-02-29T21:22:58.000Z","updated_at":"2025-05-11T21:51:25.000Z","dependencies_parsed_at":"2023-09-24T09:57:31.077Z","dependency_job_id":"34d5b744-bb34-4ce0-9c93-06c5c1b2438b","html_url":"https://github.com/rhaiscript/rhai","commit_stats":{"total_commits":3394,"total_committers":47,"mean_commits":72.2127659574468,"dds":"0.45197407189157335","last_synced_commit":"160f72b4cd8f102ef0748f1630c18776aacbe5f1"},"previous_names":["jonathandturner/rhai"],"tags_count":75,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rhaiscript%2Frhai","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rhaiscript%2Frhai/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rhaiscript%2Frhai/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rhaiscript%2Frhai/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rhaiscript","download_url":"https://codeload.github.com/rhaiscript/rhai/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253672707,"owners_count":21945481,"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":["embedded","embedded-scripting-language","no-std","rhai","scripting-engine","scripting-language","wasm","webassembly"],"created_at":"2024-07-31T03:01:19.262Z","updated_at":"2025-05-12T05:29:42.793Z","avatar_url":"https://github.com/rhaiscript.png","language":"Rust","readme":"Rhai - Embedded Scripting for Rust\n==================================\n\n![GitHub last commit](https://img.shields.io/github/last-commit/rhaiscript/rhai?logo=github)\n[![Build Status](https://github.com/rhaiscript/rhai/workflows/Build/badge.svg)](https://github.com/rhaiscript/rhai/actions)\n[![Stars](https://img.shields.io/github/stars/rhaiscript/rhai?style=flat\u0026logo=github)](https://github.com/rhaiscript/rhai)\n[![License](https://img.shields.io/crates/l/rhai)](https://github.com/license/rhaiscript/rhai)\n[![crates.io](https://img.shields.io/crates/v/rhai?logo=rust)](https://crates.io/crates/rhai/)\n[![crates.io](https://img.shields.io/crates/d/rhai?logo=rust)](https://crates.io/crates/rhai/)\n[![API Docs](https://docs.rs/rhai/badge.svg?logo=docs-rs)](https://docs.rs/rhai/)\n[![VS Code plugin installs](https://img.shields.io/visual-studio-marketplace/i/rhaiscript.vscode-rhai?logo=visual-studio-code\u0026label=vs%20code)](https://marketplace.visualstudio.com/items?itemName=rhaiscript.vscode-rhai)\n[![Sublime Text package downloads](https://img.shields.io/packagecontrol/dt/Rhai.svg?logo=sublime-text\u0026label=sublime%20text)](https://packagecontrol.io/packages/Rhai)\n[![Discord Chat](https://img.shields.io/discord/767611025456889857.svg?logo=discord\u0026label=discord)](https://discord.gg/HquqbYFcZ9)\n[![Zulip Chat](https://img.shields.io/badge/zulip-join_chat-brightgreen.svg?logo=zulip)](https://rhaiscript.zulipchat.com)\n[![Reddit Channel](https://img.shields.io/reddit/subreddit-subscribers/Rhai?logo=reddit\u0026label=reddit)](https://www.reddit.com/r/Rhai)\n\n[![Rhai logo](https://rhai.rs/book/images/logo/rhai-banner-transparent-colour.svg)](https://rhai.rs)\n\nRhai is an embedded scripting language and evaluation engine for Rust that gives a safe and easy way\nto add scripting to any application.\n\n\nTargets and builds\n------------------\n\n* All CPU and O/S targets supported by Rust, including:\n  * WebAssembly (WASM)\n  * `no-std`\n* Minimum Rust version 1.66.0\n\n\nStandard features\n-----------------\n\n* Simple language similar to JavaScript+Rust with [dynamic](https://rhai.rs/book/language/dynamic.html) typing.\n* Fairly efficient evaluation - 1 million iterations in 0.14 sec on a single-core 2.6 GHz Linux VM running [this script](https://github.com/rhaiscript/rhai/blob/main/scripts/speed_test.rhai).\n* Tight integration with native Rust [functions](https://rhai.rs/book/rust/functions.html) and [types](https://rhai.rs/book/rust/custom-types.html), including [getters/setters](https://rhai.rs/book/rust/getters-setters.html), [methods](https://rhai.rs/book/rust/methods.html) and [indexers](https://rhai.rs/book/rust/indexers.html).\n* Freely pass Rust values into a script as [variables](https://rhai.rs/book/language/variables.html)/[constants](https://rhai.rs/book/language/constants.html) via an external [`Scope`](https://rhai.rs/book/engine/scope.html) - all clonable Rust types are supported; no need to implement any special trait. Or tap directly into the [variable resolution process](https://rhai.rs/book/engine/var.html).\n* Built-in support for most common [data types](https://rhai.rs/book/language/values-and-types.html) including booleans, [integers](https://rhai.rs/book/language/numbers.html), [floating-point numbers](https://rhai.rs/book/language/numbers.html) (including [`Decimal`](https://crates.io/crates/rust_decimal)), [strings](https://rhai.rs/book/language/strings-chars.html), [Unicode characters](https://rhai.rs/book/language/strings-chars.html), [arrays](https://rhai.rs/book/language/arrays.html) (including packed [byte arrays](https://rhai.rs/book/language/blobs.html)) and [object maps](https://rhai.rs/book/language/object-maps.html).\n* Easily [call a script-defined function](https://rhai.rs/book/engine/call-fn.html) from Rust.\n* Relatively little `unsafe` code (yes there are some for performance reasons).\n* Few dependencies - currently only [`smallvec`](https://crates.io/crates/smallvec), [`thin-vec`](https://crates.io/crates/thin-vec), [`num-traits`](https://crates.io/crates/num-traits), [`once_cell`](https://crates.io/crates/once_cell), [`ahash`](https://crates.io/crates/ahash), [`bitflags`](https://crates.io/crates/bitflags) and [`smartstring`](https://crates.io/crates/smartstring).\n* Re-entrant scripting engine can be made `Send + Sync` (via the `sync` feature).\n* Compile once to [AST](https://rhai.rs/book/engine/compile.html) form for repeated evaluations.\n* Scripts are [optimized](https://rhai.rs/book/engine/optimize) (useful for template-based machine-generated scripts).\n* Easy custom API development via [plugins](https://rhai.rs/book/plugins) system powered by procedural macros.\n* [Function overloading](https://rhai.rs/book/language/overload.html) and [operator overloading](https://rhai.rs/book/rust/operators.html).\n* Dynamic dispatch via [function pointers](https://rhai.rs/book/language/fn-ptr.html) with additional support for [currying](https://rhai.rs/book/language/fn-curry.html).\n* [Closures](https://rhai.rs/book/language/fn-closure.html) (anonymous functions) that can capture shared values.\n* Some syntactic support for [object-oriented programming (OOP)](https://rhai.rs/book/patterns/oop.html).\n* Organize code base with dynamically-loadable [modules](https://rhai.rs/book/language/modules), optionally [overriding the resolution process](https://rhai.rs/book/rust/modules/resolvers.html).\n* Serialization/deserialization support via [serde](https://crates.io/crates/serde) (requires the `serde` feature).\n* Support for [minimal builds](https://rhai.rs/book/start/builds/minimal.html) by excluding unneeded language [features](https://rhai.rs/book/start/features.html).\n* A [debugging](https://rhai.rs/book/engine/debugging) interface.\n\n\nProtected against attacks\n-------------------------\n\n* [_Don't Panic_](https://rhai.rs/book/safety/index.html#dont-panic-guarantee--any-panic-is-a-bug) guarantee - Any panic is a bug. Rhai subscribes to the motto that a library should never panic the host system, and is coded with this in mind.\n* [Sand-boxed](https://rhai.rs/book/safety/sandbox.html) - the scripting engine, if declared immutable, cannot mutate the containing environment unless [explicitly permitted](https://rhai.rs/book/patterns/control.html).\n* Rugged - protected against malicious attacks (such as [stack-overflow](https://rhai.rs/book/safety/max-call-stack.html), [over-sized data](https://rhai.rs/book/safety/max-string-size.html), and [runaway scripts](https://rhai.rs/book/safety/max-operations.html) etc.) that may come from untrusted third-party user-land scripts.\n* Track script evaluation [progress](https://rhai.rs/book/safety/progress.html) and manually terminate a script run.\n* Passes Miri.\n\n\nFor those who actually want their own language\n----------------------------------------------\n\n* Use as a [DSL](https://rhai.rs/book/engine/dsl.html).\n* Disable certain [language features](https://rhai.rs/book/engine/options.html#language-features) such as [looping](https://rhai.rs/book/engine/disable-looping.html).\n* Further restrict the language by surgically [disabling keywords and operators](https://rhai.rs/book/engine/disable-keywords.html).\n* Define [custom operators](https://rhai.rs/book/engine/custom-op.html).\n* Extend the language with [custom syntax](https://rhai.rs/book/engine/custom-syntax.html).\n\n\nExample\n-------\n\nThe [`scripts`](https://github.com/rhaiscript/rhai/tree/master/scripts) subdirectory contains sample Rhai scripts.\n\nBelow is the standard _Fibonacci_ example for scripting languages:\n\n```ts\n// This Rhai script calculates the n-th Fibonacci number using a\n// really dumb algorithm to test the speed of the scripting engine.\n\nconst TARGET = 28;\nconst REPEAT = 5;\nconst ANSWER = 317_811;\n\nfn fib(n) {\n    if n \u003c 2 {\n        n\n    } else {\n        fib(n-1) + fib(n-2)\n    }\n}\n\nprint(`Running Fibonacci(${TARGET}) x ${REPEAT} times...`);\nprint(\"Ready... Go!\");\n\nlet result;\nlet now = timestamp();\n\nfor n in 0..REPEAT {\n    result = fib(TARGET);\n}\n\nprint(`Finished. Run time = ${now.elapsed} seconds.`);\n\nprint(`Fibonacci number #${TARGET} = ${result}`);\n\nif result != ANSWER {\n    print(`The answer is WRONG! Should be ${ANSWER}!`);\n}\n```\n\nProject Site\n------------\n\n[`rhai.rs`](https://rhai.rs)\n\n\nDocumentation\n-------------\n\nSee [_The Rhai Book_](https://rhai.rs/book) for details on the Rhai scripting engine and language.\n\n\nPlayground\n----------\n\nAn [_Online Playground_](https://rhai.rs/playground) is available with syntax-highlighting editor,\npowered by WebAssembly.\n\nScripts can be evaluated directly from the editor.\n\n\nLicense\n-------\n\nLicensed under either of the following, at your choice:\n\n* [Apache License, Version 2.0](https://github.com/rhaiscript/rhai/blob/master/LICENSE-APACHE.txt), or\n* [MIT license](https://github.com/rhaiscript/rhai/blob/master/LICENSE-MIT.txt)\n\nUnless explicitly stated otherwise, any contribution intentionally submitted\nfor inclusion in this crate, as defined in the Apache-2.0 license, shall\nbe dual-licensed as above, without any additional terms or conditions.\n","funding_links":[],"categories":["Libraries","Rust","库 Libraries","others","Uncategorized","webassembly"],"sub_categories":["Scripting","脚本 Scripting","Uncategorized"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frhaiscript%2Frhai","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frhaiscript%2Frhai","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frhaiscript%2Frhai/lists"}