-
Notifications
You must be signed in to change notification settings - Fork 12
Built‐in Parser
The built-in parser provides a mini-language that can evaluate expressions, call commands, and modify resources. (Entity modification is coming soon, see issue #3)
The built-in parser is enabled by default and can be disabled by disabling the builtin-parser
feature.
Important
This guide assumes you already have used Rust before and that you know how it works.
For simplicity, the let
keyword is not required for creating variables:
$ x = 5 + 4
> 9
$ x - 2
> 7
$ x = x + 3
> 12
The built-in parser uses the a similar memory model to Rust's.
This means assigning a variable's value to another causes the original variable to get moved.
$ x = "Hello World!"
> "Hello World!"
$ y = x
> "Hello World!"
$ x
ERROR Variable `x` was moved
For simplicity, references are always mutable, and you can have multiple of them.
You can deference references to modify the value they are references.
$ x = "Hi"
> "Hi"
$ y = &x
> "Hi"
$ z = &x
> "Hi"
$ *z = "Bye"
> "Bye"
$ x
> "Bye"
$ y
> "Bye"
You can also use dereferencing to clone a variable's value.
$ x = "Hmmm"
$ y = *x
$ z = x
Every value can have one of these types:
-
None: The same as
()
in Rust. -
Number: Any type of Rust number (You can specify a type like this:
5usize
,2.4f32
,8f64
), along with these 2 additional types:- Integer: A generic integer of an unknown size that can get downcasted to the appropriate size when used with an integer of a known size.
- Float: A generic float of an unknown size that can get downcasted to the appropriate size when used with a float of a known size.
-
Boolean: A value that can either be
true
orfalse
. -
String: An array of characters, the same as the
String
type in Rust. - Reference: A mutable reference to another value.
-
Object: A dynamic object, equivalent to
HashMap<String, Value>
in Rust. - StructObject: A dynamic object, but with a name. Mostly used for enum assignments.
- Tuple: A dynamic tuple.
- StructTuple: A dynamic tuple, but with a name. Mostly used for enum assignments.
- Resource: A reference to a resource that can be modified.
You can call functions by the name, followed by space seperated arguments.
$ print "Hello World!"
INFO "Hello World!"
Custom native functions can be created and added, see the custom_functions.rs
for an example.
You can modify Resource
s that implement the Reflect
trait by their name.
Warning: Error handling for this is not finished, expect panics.
MyStructResource.number1 = 100
MyEnumResource = Option2
MyEnumResource = StructVariant { a: 5.2, b: "Hi!" }
MyEnumResource = TupleVariant(false)
bevy_dev_console
is still in active development, and more features will be added soon.