Merge pull request #275 from schungx/master

Fix Discord link.
This commit is contained in:
Stephen Chung 2020-10-31 11:57:05 +08:00 committed by GitHub
commit c38ea9a358
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 70 additions and 8 deletions

View File

@ -7,7 +7,7 @@ Rhai - Embedded Scripting for Rust
[![crates.io](https://img.shields.io/crates/v/rhai?logo=rust)](https://crates.io/crates/rhai/) [![crates.io](https://img.shields.io/crates/v/rhai?logo=rust)](https://crates.io/crates/rhai/)
[![crates.io](https://img.shields.io/crates/d/rhai?logo=rust)](https://crates.io/crates/rhai/) [![crates.io](https://img.shields.io/crates/d/rhai?logo=rust)](https://crates.io/crates/rhai/)
[![API Docs](https://docs.rs/rhai/badge.svg?logo=docs.rs)](https://docs.rs/rhai/) [![API Docs](https://docs.rs/rhai/badge.svg?logo=docs.rs)](https://docs.rs/rhai/)
[![chat](https://img.shields.io/discord/767611025456889857.svg?logo=discord)](https://discord.gg/yZMKAQ) [![chat](https://img.shields.io/discord/767611025456889857.svg?logo=discord)](https://discord.gg/HquqbYFcZ9)
[![Reddit](https://img.shields.io/reddit/subreddit-subscribers/Rhai?logo=reddit)](https://www.reddit.com/r/Rhai) [![Reddit](https://img.shields.io/reddit/subreddit-subscribers/Rhai?logo=reddit)](https://www.reddit.com/r/Rhai)
Rhai is an embedded scripting language and evaluation engine for Rust that gives a safe and easy way Rhai is an embedded scripting language and evaluation engine for Rust that gives a safe and easy way

View File

@ -15,7 +15,7 @@ Other Online Resources for Rhai
* [Online Playground][playground] - Run scripts directly from editor * [Online Playground][playground] - Run scripts directly from editor
* [Discord Chat](https://discord.gg/yZMKAQ) - Rhai channel * [Discord Chat](https://discord.gg/HquqbYFcZ9) - Rhai channel
* [Reddit](https://www.reddit.com/r/Rhai) - Rhai community * [Reddit](https://www.reddit.com/r/Rhai) - Rhai community

View File

@ -15,7 +15,65 @@ Nightly Required
Currently, [`no_std`] requires the nightly compiler due to the crates that it uses. Currently, [`no_std`] requires the nightly compiler due to the crates that it uses.
Implementation
--------------
Rhai allocates, so the first thing that must be included in any `no-std` project is
an allocator crate, such as [`wee_alloc`](https://crates.io/crates/wee_alloc).
Then there is the need to set up proper error/panic handlers.
The following example uses `panic = "abort"` and `wee_alloc` as the allocator.
```rust
// Set up for no-std.
#![no_std]
// The following no-std features are usually needed.
#![feature(alloc_error_handler, start, core_intrinsics, lang_items, link_cfg)]
// Set up the global allocator.
extern crate alloc;
extern crate wee_alloc;
#[global_allocator]
static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;
// Rust needs a CRT runtime on Windows when compiled with MSVC.
#[cfg(all(windows, target_env = "msvc"))]
#[link(name = "msvcrt")]
#[link(name = "libcmt")]
extern {}
// Set up panic and error handlers
#[alloc_error_handler]
fn err_handler(_: core::alloc::Layout) -> ! {
core::intrinsics::abort();
}
#[panic_handler]
#[lang = "panic_impl"]
extern "C" fn rust_begin_panic(_: &core::panic::PanicInfo) -> ! {
core::intrinsics::abort();
}
#[lang = "eh_personality"]
extern "C" fn eh_personality() {}
#[no_mangle]
extern "C" fn rust_eh_register_frames() {}
#[no_mangle]
extern "C" fn rust_eh_unregister_frames() {}
#[start]
fn main(_argc: isize, _argv: *const *const u8) -> isize {
// ... main program ...
}
```
Samples Samples
------- -------
Check out the [`no-std` sample applications](../examples/rust.md#no-std-samples) for different operating environments. Check out the [`no-std` sample applications](../examples/rust.md#no-std-samples)
for different operating environments.

View File

@ -3,16 +3,16 @@ Building to WebAssembly (WASM)
{{#include ../../links.md}} {{#include ../../links.md}}
It is possible to use Rhai when compiling to WebAssembly (WASM). This yields a scripting engine (and language) It is possible to use Rhai when compiling to WebAssembly (WASM).
that can be run in a standard web browser. This yields a scripting engine (and language) that can be run in a standard web browser.
Why you would want to is another matter... as there is already a nice, fast, complete scripting language Why you would _want_ to is another matter... as there is already a nice, fast, complete scripting language
for the the common WASM environment (i.e. a browser) - and it is called JavaScript. for the the common WASM environment (i.e. a browser) - and it is called JavaScript.
But anyhow, do it because you _can_! But anyhow, do it because you _can_!
When building for WASM, certain features will not be available, such as the script file API's and loading modules When building for WASM, certain features will not be available,
from external script files. such as the script file API's and loading modules from external script files.
Size Size

View File

@ -215,6 +215,10 @@ mod float_functions {
Ok((x.trunc() as INT).into()) Ok((x.trunc() as INT).into())
} }
} }
#[rhai_fn(name = "to_float")]
pub fn f32_to_float(x: f32) -> FLOAT {
x as FLOAT
}
#[rhai_fn(name = "to_int", return_raw)] #[rhai_fn(name = "to_int", return_raw)]
pub fn f64_to_int(x: f64) -> Result<Dynamic, Box<EvalAltResult>> { pub fn f64_to_int(x: f64) -> Result<Dynamic, Box<EvalAltResult>> {
if cfg!(not(feature = "unchecked")) && x > (MAX_INT as f64) { if cfg!(not(feature = "unchecked")) && x > (MAX_INT as f64) {