rhaiscript / rhai Goto Github PK
View Code? Open in Web Editor NEWRhai - An embedded scripting language for Rust.
Home Page: https://crates.io/crates/rhai
License: Apache License 2.0
Rhai - An embedded scripting language for Rust.
Home Page: https://crates.io/crates/rhai
License: Apache License 2.0
Having read how Rhai functions are dispatched, I don't quite get why there is a fixed number of arguments limit. Arguments are basically passed as a six-elements-long homogeneous tuple of Option<&mut Box<Any>>
only to assume last N of them are None
. Not only does it introduce a argument number limit but implies quite a lot of code repetition. Wouldn't it be better to use slices instead of tuples?
Of course fn_register
needs heterogeneousity for native Rust functions, at least until variadic generics come into play. But as for now, why not introduce some macro to automate N-arguments-precisely problem? Then it would be trivial to write another macro to abstract it away just to the limit of N. And even then, any limit doesn't seem really rational for Rhai-defined functions as it doesn't depend on variadic generics (it's dynamic anyway).
Implement basic threads:
// syntax is a to-do, too, a bit
//spawns a new thread with the identifier 'myname'. Thread names are optional
thread myname {
stuff1();
stuff2();
etc();
}
join myname; //joins a thread, no-op if thread has already finished
let x = 5;
let y = 6;
// captures variables for a thread. Currently unsure if it should actually move them or just copy
// Not really sure about syntax here
thread |x, y| {
print(x);
print(y);
}
// all threads are joined when the main script thread is about to finish to prevent threads being stopped unexpectedly
Accessing an element out of bounds shouldn't panic, but error.
I'll fix this after my current PR.
Add futures to Rhai (exact design TODO)
Suggest from twitter - document how to call Rhai functions from Rust. May want to add some helper functions for this as well.
Add boolean AND and OR:
let x = true && false; //false
let y = true || false; //true
Would be nice to add vectors so that you can do more than single data values.
var x = [1, 2, 3];
print(x[1]);
x[0] = 4;
Similar to #5, this would need some way of handling assigning into an indexed position through possibly a setter.
let x = -5;
let f = !true;
It would be great to have anonymous functions in Rhai, and be able to programmatically call them from Rust.
Something like:
let add = engine.eval::<Fn(i64, i64) -> i64>("fn (x,y) { x + y }").unwrap();
println!("{}", add(2,3));
Implement binary, hex and octal literals. Maybe allow _ for readability like in Rust:
let x = 0xaf; // 175
let x = 0b0101; // 5
let x = 0o77; //63
let x = 0b0011_1100_1010_0101; // 15525
Let's meet and discuss Rhai. We need to pick a time. @luciusmagn - is there one that works best?
In this line:
https://github.com/jonathandturner/rhai/blob/master/src/engine.rs#L735
Rhai sets val
to target
, which however is just val
cloned. So I don't quite understand what that is doing. @luciusmagn Would you be so kind and explain to me what I'm missing and why the code is structured like this?
Implement the missing binary operators:
let rem = 10 % 4; // 2
let lsh = 10 << 4; // 160
let rsh = 10 >> 4; // 0
let and = 10 & 4; // 0
let or = 10 | 4; // 14
let xor = 10 ^ 4; // 14
Is there a way to disable the debug_msgs feature when using the crate?
I tried this
[dependencies.rhai]
version= "0.8.1"
default-features = false
features=[]
but I still get the messages
Great job!
By simply looking the readme file, I found that your job seems very promissing, and I'll, just like many other people, ask you more documentation. I've looked into the project dates, and as I can see, you are changing it constantly: that's good. I really wanted to use your Script System, but I found a little bit hard with the current state of your examples(docs). It would be nice, if you create a document showing to the people the differences between Rhai to Rust. So if we study Rust, and later on, we can study your language! Presenting a table with the diffrences between the both (Rust and Rhai) may be enough.
Thanks and keep doing it!
Implement compound assignment operators:
let x = 5;
x += 2; // 7
x -= 1; // 6
x *= 3; // 18
x /= 2; // 9
x >>= 1; // 4
x <<= 2; // 16
x &= 31; // 16
x |= 74; // 90
x ^= 12; // 28
Currently, Rhai doesn't track source positions so errors have no location information. Additionally, it doesn't track the names of where errors occurred (eg: Variable not found vs Variable 'a' not found).
Currently, you can only create i32 literals. Shouldn't be hard to add support for other integer and float literals.
Would be really nice to be able to write comments in a script :)
I guess something like:
// some comment
or...
# another comment
Let me know if you need more info.
It'd be nice to have a 'raise to the power of' operator:
let b = 2 ~ 2; // -> 4
let c = 4 ~ 3; // -> 64
As far as operator precendence goes, I reckon it should be at the same level as multiplication/division & modulo.
It'd be nice to support the dot operator:
For example:
var x = get_object();
x.y = 3;
print(x.z);
For this to work, we may have to add support for getters and setters. This needs a spec that fits with the "no unsafe code" part of the design.
First, I must say - excellent project!. But I'm puzzled by this comment in parser.rs
} else if curr_prec >= 100 {
// Always bind right to left for precedence over 100
rhs = try!(parse_binop(input, curr_prec, rhs));
}
The only such operator is Dot, and Dot associativity must be left to right (a.b).c
, not a.(b.c)
If this is resolved, then I suspect that the engine can be simplified, since there are several special-cases for the dot operator.
The parser is currently pretty loosey-goosey about strictness to any particular language design. For example, you can elide semicolons between adjacent statements. This makes for some confusing issues when a script refuses to run and it's because you missed something that's hard to see.
Before 1.0, it'd be nice to have a pretty straightforward set of grammar rules that are enforced by the parser.
I want infix operators for string to compare("==") and concat.
Rust have no concat op. for &str or String, but they are useful in other languages.
Fortran: s = x // y
Perl: $s = $x . $y
Java: s = x + y
Lua: s = x .. y
VisualBasic: s = x & y
Would you consider to implement it in Rhai?
Implement a tiny standard library. Design is to be added
Calling Rust functions from Rhai is simple and easy, the other way around, not so much. The way I see it, we need a macro or two. Therefore, we need to:
call_fn()
public (Already done)However, this open to discussion, as there might be better ways to handle function calling from Rhai
Add some documentation
Implement ranges and a for
loop like the one in Rust:
for i in 0..10 {
print(i);
}
let x = 1..5;
Turn threads into possible expressions, an extremely handy feature. Possibly introduce actors from actress
for communication with other threads during their execution:
// thread syntax TBD
let mynum = spawn || {
stuff1();
stuff2();
etc();
4
}
// Do other stuff
let x = 4 + mynum; // mynum is joined now and it's return value is taken
// after this point mynum is a regular integer variable
// mynum.join() for manual joining, noop if already joined
Let's have some nice solution for tracing information from rhai when we need to debug. Current debug messeges are only a temporary solution
++ and -- are tricky. Rust doesn't have them. Should Rhai?
Hi,
I have a problem: I'm trying to use rhai to implement a filter type for my imag library, but I fail to bring an object into scope which I have as reference. Here's the codebase: https://github.com/matthiasbeyer/imag/pull/371/files
Note that the Filter
trait provides a function filter
which gets a &Entry
. I need to bring this reference into scope of rhai, but I fail to do so. As you can see I added a wrapper type, but it doesn't help.
Maybe you have an idea?
Implement a basic infinite loop like loop
in Rust:
loop {
// do stuff
break;
}
Implement comments, possibly through very basic preprocessor, rather than by editing the parser. Through thorough discussion, we have settled on Rust/C/C++ style comments:
// I am a single-line comment
/* I am a multiline
comment with multiple lines
and a /* nested comment */
*/
Following usecase:
I have users input rhai script. I want some environment to be set up for every invocation of the script (Lets think of a global variable that should be available when the script is run).
How do I do that?
let x = 10 % 4; // == 2
Will close #24, too
Ketos is a related embedded Lisp dialect for Rust. I thought you might want to include this in your readme.
Add a very simple REPL. Probably needs the consume function family from Nary.
A while ago, Rust introduced yet another amazing feature:
let x = loop {
// complicated computations
break 7;
};
assert_eq!(x, 7);
Would be cool if Rhai had it too. Maybe even for while & for (when it comes around)
Would be nice to have a for loop and/or a for..in.. loop. Right now the control structure story in Rhai is a bit thin, and before 1.0 it'd be nice to fill it out.
Parser cannot seem to handle negative sign.
Two evals below print "Can't parse: Minus" in stdout, and ErrorFunctionArgMismatch is returned.
engine.eval::<i64>("var n = -1; n");
engine.eval::<i64>("-1+5");
I'm trying out rust on a cheap microcontroller following this tutorial https://polyfractal.com/post/rustl8710/
The tutorial works great and the sample echo program runs over serial.
I'd love to add in a rust scripting language and I really like the design of Rhai. But when I add the library, the compile fails because of std is missing.
info: using existing install for 'nightly-x86_64-unknown-linux-gnu'
info: override toolchain for '/home/tim/rustl8710/src/rust' set to 'nightly-x86_64-unknown-linux-gnu'
nightly-x86_64-unknown-linux-gnu unchanged - rustc 1.16.0-nightly (4ce7accaa 2017-01-17)
cd src/rust && xargo build --target thumbv7m-none-eabi
Compiling rhai v0.4.0
error[E0463]: can't find crate for `std`
|
= note: the `thumbv7m-none-eabi` target may not be installed
I'm fairly new to rust still and am not quite clear on what this all means. Is Rhai meant to be used in such embedded use cases? It sure would be neat if it or something like it did work.
I'm getting the above error on the following source code. I ran cargo doc
and the function seems to exist so probably a silly mistake on my part and not a bug, but I can't figure out what's going wrong.
extern crate rhai;
use rhai::Engine;
fn add(x: i64, y: i64) -> i64 {
x + y
}
fn main() {
let mut engine = Engine::new();
engine.register_fn("add", add); // "no method named `register_fn` found for type `rhai::Engine` in the current scope"
}
The last commit was nearly a year ago. I really like the Rhai syntax and the way to use it from Rust, but I don't want to use a dead project...
Basic array support is in, but it's not complete. Need to be able to do more complex expressions like:
x[0].update();
x[1].g;
x[2].f = 4;
It might be worth adding an enum called Value
and replace the current Box<Any>
with that. That would allow us to have primitives and user data, while the former one is cheaper.
One related question is whether we want to encode basic types into the language. Currently, e.g. arrays are special cased while integers and floats are partially special cased (they don't define basic operators except through register_default_lib
).
One motivation I see for that is that currently the integer type is i64
which isn't very obvious at first. If you're trying to index an array by u64
, that would fail. Looking at issues like #52 or #32 , having special types that we handle in another way would make these things easier.
A disadvantage of encoding basic types and operations into the language would be that it would make the language and / or the library more complex.
I am myself unsure which way to go here.
Parse floating point numbers. Rhai already supports them, but has no way of actually creating them:
let x = 5.00001;
We should add @luciusmagn to the authors in the Cargo.toml, I think?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.