...
This commit is contained in:
		
							
								
								
									
										6378
									
								
								rhai_engine/rhaiexamples/definitions/.rhai/all_in_one.d.rhai
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										6378
									
								
								rhai_engine/rhaiexamples/definitions/.rhai/all_in_one.d.rhai
									
									
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							@@ -0,0 +1,14 @@
 | 
			
		||||
module static;
 | 
			
		||||
 | 
			
		||||
op minus(int, int) -> int;
 | 
			
		||||
 | 
			
		||||
module general_kenobi {
 | 
			
		||||
const CONSTANT: int;
 | 
			
		||||
 | 
			
		||||
/// Returns a string where "hello there" is repeated `n` times.
 | 
			
		||||
fn hello_there(n: int) -> String;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
let hello_there: string;
 | 
			
		||||
 | 
			
		||||
const HELLO: string;
 | 
			
		||||
@@ -0,0 +1,259 @@
 | 
			
		||||
module static;
 | 
			
		||||
 | 
			
		||||
op ==(int, int) -> bool;
 | 
			
		||||
op !=(int, int) -> bool;
 | 
			
		||||
op >(int, int) -> bool;
 | 
			
		||||
op >=(int, int) -> bool;
 | 
			
		||||
op <(int, int) -> bool;
 | 
			
		||||
op <=(int, int) -> bool;
 | 
			
		||||
op &(int, int) -> int;
 | 
			
		||||
op |(int, int) -> int;
 | 
			
		||||
op ^(int, int) -> int;
 | 
			
		||||
op ..(int, int) -> Range<int>;
 | 
			
		||||
op ..=(int, int) -> RangeInclusive<int>;
 | 
			
		||||
 | 
			
		||||
op ==(bool, bool) -> bool;
 | 
			
		||||
op !=(bool, bool) -> bool;
 | 
			
		||||
op >(bool, bool) -> bool;
 | 
			
		||||
op >=(bool, bool) -> bool;
 | 
			
		||||
op <(bool, bool) -> bool;
 | 
			
		||||
op <=(bool, bool) -> bool;
 | 
			
		||||
op &(bool, bool) -> bool;
 | 
			
		||||
op |(bool, bool) -> bool;
 | 
			
		||||
op ^(bool, bool) -> bool;
 | 
			
		||||
 | 
			
		||||
op ==((), ()) -> bool;
 | 
			
		||||
op !=((), ()) -> bool;
 | 
			
		||||
op >((), ()) -> bool;
 | 
			
		||||
op >=((), ()) -> bool;
 | 
			
		||||
op <((), ()) -> bool;
 | 
			
		||||
op <=((), ()) -> bool;
 | 
			
		||||
 | 
			
		||||
op +(int, int) -> int;
 | 
			
		||||
op -(int, int) -> int;
 | 
			
		||||
op *(int, int) -> int;
 | 
			
		||||
op /(int, int) -> int;
 | 
			
		||||
op %(int, int) -> int;
 | 
			
		||||
op **(int, int) -> int;
 | 
			
		||||
op >>(int, int) -> int;
 | 
			
		||||
op <<(int, int) -> int;
 | 
			
		||||
 | 
			
		||||
op +(float, float) -> float;
 | 
			
		||||
op -(float, float) -> float;
 | 
			
		||||
op *(float, float) -> float;
 | 
			
		||||
op /(float, float) -> float;
 | 
			
		||||
op %(float, float) -> float;
 | 
			
		||||
op **(float, float) -> float;
 | 
			
		||||
op ==(float, float) -> bool;
 | 
			
		||||
op !=(float, float) -> bool;
 | 
			
		||||
op >(float, float) -> bool;
 | 
			
		||||
op >=(float, float) -> bool;
 | 
			
		||||
op <(float, float) -> bool;
 | 
			
		||||
op <=(float, float) -> bool;
 | 
			
		||||
 | 
			
		||||
op +(float, int) -> float;
 | 
			
		||||
op -(float, int) -> float;
 | 
			
		||||
op *(float, int) -> float;
 | 
			
		||||
op /(float, int) -> float;
 | 
			
		||||
op %(float, int) -> float;
 | 
			
		||||
op **(float, int) -> float;
 | 
			
		||||
op ==(float, int) -> bool;
 | 
			
		||||
op !=(float, int) -> bool;
 | 
			
		||||
op >(float, int) -> bool;
 | 
			
		||||
op >=(float, int) -> bool;
 | 
			
		||||
op <(float, int) -> bool;
 | 
			
		||||
op <=(float, int) -> bool;
 | 
			
		||||
 | 
			
		||||
op +(int, float) -> float;
 | 
			
		||||
op -(int, float) -> float;
 | 
			
		||||
op *(int, float) -> float;
 | 
			
		||||
op /(int, float) -> float;
 | 
			
		||||
op %(int, float) -> float;
 | 
			
		||||
op **(int, float) -> float;
 | 
			
		||||
op ==(int, float) -> bool;
 | 
			
		||||
op !=(int, float) -> bool;
 | 
			
		||||
op >(int, float) -> bool;
 | 
			
		||||
op >=(int, float) -> bool;
 | 
			
		||||
op <(int, float) -> bool;
 | 
			
		||||
op <=(int, float) -> bool;
 | 
			
		||||
 | 
			
		||||
op +(Decimal, Decimal) -> Decimal;
 | 
			
		||||
op -(Decimal, Decimal) -> Decimal;
 | 
			
		||||
op *(Decimal, Decimal) -> Decimal;
 | 
			
		||||
op /(Decimal, Decimal) -> Decimal;
 | 
			
		||||
op %(Decimal, Decimal) -> Decimal;
 | 
			
		||||
op **(Decimal, Decimal) -> Decimal;
 | 
			
		||||
op ==(Decimal, Decimal) -> bool;
 | 
			
		||||
op !=(Decimal, Decimal) -> bool;
 | 
			
		||||
op >(Decimal, Decimal) -> bool;
 | 
			
		||||
op >=(Decimal, Decimal) -> bool;
 | 
			
		||||
op <(Decimal, Decimal) -> bool;
 | 
			
		||||
op <=(Decimal, Decimal) -> bool;
 | 
			
		||||
 | 
			
		||||
op +(Decimal, int) -> Decimal;
 | 
			
		||||
op -(Decimal, int) -> Decimal;
 | 
			
		||||
op *(Decimal, int) -> Decimal;
 | 
			
		||||
op /(Decimal, int) -> Decimal;
 | 
			
		||||
op %(Decimal, int) -> Decimal;
 | 
			
		||||
op **(Decimal, int) -> Decimal;
 | 
			
		||||
op ==(Decimal, int) -> bool;
 | 
			
		||||
op !=(Decimal, int) -> bool;
 | 
			
		||||
op >(Decimal, int) -> bool;
 | 
			
		||||
op >=(Decimal, int) -> bool;
 | 
			
		||||
op <(Decimal, int) -> bool;
 | 
			
		||||
op <=(Decimal, int) -> bool;
 | 
			
		||||
 | 
			
		||||
op +(int, Decimal) -> Decimal;
 | 
			
		||||
op -(int, Decimal) -> Decimal;
 | 
			
		||||
op *(int, Decimal) -> Decimal;
 | 
			
		||||
op /(int, Decimal) -> Decimal;
 | 
			
		||||
op %(int, Decimal) -> Decimal;
 | 
			
		||||
op **(int, Decimal) -> Decimal;
 | 
			
		||||
op ==(int, Decimal) -> bool;
 | 
			
		||||
op !=(int, Decimal) -> bool;
 | 
			
		||||
op >(int, Decimal) -> bool;
 | 
			
		||||
op >=(int, Decimal) -> bool;
 | 
			
		||||
op <(int, Decimal) -> bool;
 | 
			
		||||
op <=(int, Decimal) -> bool;
 | 
			
		||||
 | 
			
		||||
op +(String, String) -> String;
 | 
			
		||||
op -(String, String) -> String;
 | 
			
		||||
op ==(String, String) -> bool;
 | 
			
		||||
op !=(String, String) -> bool;
 | 
			
		||||
op >(String, String) -> bool;
 | 
			
		||||
op >=(String, String) -> bool;
 | 
			
		||||
op <(String, String) -> bool;
 | 
			
		||||
op <=(String, String) -> bool;
 | 
			
		||||
 | 
			
		||||
op +(char, char) -> String;
 | 
			
		||||
op ==(char, char) -> bool;
 | 
			
		||||
op !=(char, char) -> bool;
 | 
			
		||||
op >(char, char) -> bool;
 | 
			
		||||
op >=(char, char) -> bool;
 | 
			
		||||
op <(char, char) -> bool;
 | 
			
		||||
op <=(char, char) -> bool;
 | 
			
		||||
 | 
			
		||||
op +(char, String) -> String;
 | 
			
		||||
op ==(char, String) -> bool;
 | 
			
		||||
op !=(char, String) -> bool;
 | 
			
		||||
op >(char, String) -> bool;
 | 
			
		||||
op >=(char, String) -> bool;
 | 
			
		||||
op <(char, String) -> bool;
 | 
			
		||||
op <=(char, String) -> bool;
 | 
			
		||||
 | 
			
		||||
op +(String, char) -> String;
 | 
			
		||||
op -(String, char) -> String;
 | 
			
		||||
op ==(String, char) -> bool;
 | 
			
		||||
op !=(String, char) -> bool;
 | 
			
		||||
op >(String, char) -> bool;
 | 
			
		||||
op >=(String, char) -> bool;
 | 
			
		||||
op <(String, char) -> bool;
 | 
			
		||||
op <=(String, char) -> bool;
 | 
			
		||||
 | 
			
		||||
op +((), String) -> String;
 | 
			
		||||
op ==((), String) -> bool;
 | 
			
		||||
op !=((), String) -> bool;
 | 
			
		||||
op >((), String) -> bool;
 | 
			
		||||
op >=((), String) -> bool;
 | 
			
		||||
op <((), String) -> bool;
 | 
			
		||||
op <=((), String) -> bool;
 | 
			
		||||
 | 
			
		||||
op +(String, ()) -> String;
 | 
			
		||||
op ==(String, ()) -> bool;
 | 
			
		||||
op !=(String, ()) -> bool;
 | 
			
		||||
op >(String, ()) -> bool;
 | 
			
		||||
op >=(String, ()) -> bool;
 | 
			
		||||
op <(String, ()) -> bool;
 | 
			
		||||
op <=(String, ()) -> bool;
 | 
			
		||||
 | 
			
		||||
op +(Blob, Blob) -> Blob;
 | 
			
		||||
op +(Blob, char) -> Blob;
 | 
			
		||||
op ==(Blob, Blob) -> bool;
 | 
			
		||||
op !=(Blob, Blob) -> bool;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
op ==(Range<int>, RangeInclusive<int>) -> bool;
 | 
			
		||||
op !=(Range<int>, RangeInclusive<int>) -> bool;
 | 
			
		||||
 | 
			
		||||
op ==(RangeInclusive<int>, Range<int>) -> bool;
 | 
			
		||||
op !=(RangeInclusive<int>, Range<int>) -> bool;
 | 
			
		||||
 | 
			
		||||
op ==(Range<int>, Range<int>) -> bool;
 | 
			
		||||
op !=(Range<int>, Range<int>) -> bool;
 | 
			
		||||
 | 
			
		||||
op ==(RangeInclusive<int>, RangeInclusive<int>) -> bool;
 | 
			
		||||
op !=(RangeInclusive<int>, RangeInclusive<int>) -> bool;
 | 
			
		||||
 | 
			
		||||
op ==(?, ?) -> bool;
 | 
			
		||||
op !=(?, ?) -> bool;
 | 
			
		||||
op >(?, ?) -> bool;
 | 
			
		||||
op >=(?, ?) -> bool;
 | 
			
		||||
op <(?, ?) -> bool;
 | 
			
		||||
op <=(?, ?) -> bool;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
op &=(bool, bool);
 | 
			
		||||
op |=(bool, bool);
 | 
			
		||||
 | 
			
		||||
op +=(int, int);
 | 
			
		||||
op -=(int, int);
 | 
			
		||||
op *=(int, int);
 | 
			
		||||
op /=(int, int);
 | 
			
		||||
op %=(int, int);
 | 
			
		||||
op **=(int, int);
 | 
			
		||||
op >>=(int, int);
 | 
			
		||||
op <<=(int, int);
 | 
			
		||||
op &=(int, int);
 | 
			
		||||
op |=(int, int);
 | 
			
		||||
op ^=(int, int);
 | 
			
		||||
 | 
			
		||||
op +=(float, float);
 | 
			
		||||
op -=(float, float);
 | 
			
		||||
op *=(float, float);
 | 
			
		||||
op /=(float, float);
 | 
			
		||||
op %=(float, float);
 | 
			
		||||
op **=(float, float);
 | 
			
		||||
 | 
			
		||||
op +=(float, int);
 | 
			
		||||
op -=(float, int);
 | 
			
		||||
op *=(float, int);
 | 
			
		||||
op /=(float, int);
 | 
			
		||||
op %=(float, int);
 | 
			
		||||
op **=(float, int);
 | 
			
		||||
 | 
			
		||||
op +=(Decimal, Decimal);
 | 
			
		||||
op -=(Decimal, Decimal);
 | 
			
		||||
op *=(Decimal, Decimal);
 | 
			
		||||
op /=(Decimal, Decimal);
 | 
			
		||||
op %=(Decimal, Decimal);
 | 
			
		||||
op **=(Decimal, Decimal);
 | 
			
		||||
 | 
			
		||||
op +=(Decimal, int);
 | 
			
		||||
op -=(Decimal, int);
 | 
			
		||||
op *=(Decimal, int);
 | 
			
		||||
op /=(Decimal, int);
 | 
			
		||||
op %=(Decimal, int);
 | 
			
		||||
op **=(Decimal, int);
 | 
			
		||||
 | 
			
		||||
op +=(String, String);
 | 
			
		||||
op -=(String, String);
 | 
			
		||||
op +=(String, char);
 | 
			
		||||
op -=(String, char);
 | 
			
		||||
op +=(char, String);
 | 
			
		||||
op +=(char, char);
 | 
			
		||||
 | 
			
		||||
op +=(Array, Array);
 | 
			
		||||
op +=(Array, ?);
 | 
			
		||||
 | 
			
		||||
op +=(Blob, Blob);
 | 
			
		||||
op +=(Blob, int);
 | 
			
		||||
op +=(Blob, char);
 | 
			
		||||
op +=(Blob, String);
 | 
			
		||||
 | 
			
		||||
op in(?, Array) -> bool;
 | 
			
		||||
op in(String, String) -> bool;
 | 
			
		||||
op in(char, String) -> bool;
 | 
			
		||||
op in(int, Range<int>) -> bool;
 | 
			
		||||
op in(int, RangeInclusive<int>) -> bool;
 | 
			
		||||
op in(String, Map) -> bool;
 | 
			
		||||
op in(int, Blob) -> bool;
 | 
			
		||||
@@ -0,0 +1,261 @@
 | 
			
		||||
module static;
 | 
			
		||||
 | 
			
		||||
/// Display any data to the standard output.
 | 
			
		||||
///
 | 
			
		||||
/// # Example
 | 
			
		||||
/// 
 | 
			
		||||
/// ```rhai
 | 
			
		||||
/// let answer = 42;
 | 
			
		||||
/// 
 | 
			
		||||
/// print(`The Answer is ${answer}`);
 | 
			
		||||
/// ```
 | 
			
		||||
fn print(data: ?);
 | 
			
		||||
 | 
			
		||||
/// Display any data to the standard output in debug format.
 | 
			
		||||
///
 | 
			
		||||
/// # Example
 | 
			
		||||
/// 
 | 
			
		||||
/// ```rhai
 | 
			
		||||
/// let answer = 42;
 | 
			
		||||
/// 
 | 
			
		||||
/// debug(answer);
 | 
			
		||||
/// ```
 | 
			
		||||
fn debug(data: ?);
 | 
			
		||||
 | 
			
		||||
/// Get the type of a value.
 | 
			
		||||
///
 | 
			
		||||
/// # Example
 | 
			
		||||
/// 
 | 
			
		||||
/// ```rhai
 | 
			
		||||
/// let x = "hello, world!";
 | 
			
		||||
/// 
 | 
			
		||||
/// print(x.type_of());     // prints "string"
 | 
			
		||||
/// ```
 | 
			
		||||
fn type_of(data: ?) -> String;
 | 
			
		||||
 | 
			
		||||
/// Create a function pointer to a named function.
 | 
			
		||||
///
 | 
			
		||||
/// If the specified name is not a valid function name, an error is raised.
 | 
			
		||||
/// 
 | 
			
		||||
/// # Example
 | 
			
		||||
/// 
 | 
			
		||||
/// ```rhai
 | 
			
		||||
/// let f = Fn("foo");      // function pointer to 'foo'
 | 
			
		||||
/// 
 | 
			
		||||
/// f.call(42);             // call: foo(42)
 | 
			
		||||
/// ```
 | 
			
		||||
fn Fn(fn_name: String) -> FnPtr;
 | 
			
		||||
 | 
			
		||||
/// Call a function pointed to by a function pointer,
 | 
			
		||||
/// passing following arguments to the function call.
 | 
			
		||||
///
 | 
			
		||||
/// If an appropriate function is not found, an error is raised.
 | 
			
		||||
/// 
 | 
			
		||||
/// # Example
 | 
			
		||||
/// 
 | 
			
		||||
/// ```rhai
 | 
			
		||||
/// let f = Fn("foo");      // function pointer to 'foo'
 | 
			
		||||
/// 
 | 
			
		||||
/// f.call(1, 2, 3);        // call: foo(1, 2, 3)
 | 
			
		||||
/// ```
 | 
			
		||||
fn call(fn_ptr: FnPtr, ...args: ?) -> ?;
 | 
			
		||||
 | 
			
		||||
/// Call a function pointed to by a function pointer, binding the `this` pointer
 | 
			
		||||
/// to the object of the method call, and passing on following arguments to the function call.
 | 
			
		||||
///
 | 
			
		||||
/// If an appropriate function is not found, an error is raised.
 | 
			
		||||
/// 
 | 
			
		||||
/// # Example
 | 
			
		||||
/// 
 | 
			
		||||
/// ```rhai
 | 
			
		||||
/// fn add(x) {
 | 
			
		||||
///     this + x
 | 
			
		||||
/// }
 | 
			
		||||
/// 
 | 
			
		||||
/// let f = Fn("add");      // function pointer to 'add'
 | 
			
		||||
/// 
 | 
			
		||||
/// let x = 41;
 | 
			
		||||
/// 
 | 
			
		||||
/// let r = x.call(f, 1);   // call: add(1) with 'this' = 'x'
 | 
			
		||||
/// 
 | 
			
		||||
/// print(r);               // prints 42
 | 
			
		||||
/// ```
 | 
			
		||||
fn call(obj: ?, fn_ptr: FnPtr, ...args: ?) -> ?;
 | 
			
		||||
 | 
			
		||||
/// Curry a number of arguments into a function pointer and return it as a new function pointer.
 | 
			
		||||
/// 
 | 
			
		||||
/// # Example
 | 
			
		||||
/// 
 | 
			
		||||
/// ```rhai
 | 
			
		||||
/// fn foo(x, y, z) {
 | 
			
		||||
///     x + y + z
 | 
			
		||||
/// }
 | 
			
		||||
/// 
 | 
			
		||||
/// let f = Fn("foo");
 | 
			
		||||
/// 
 | 
			
		||||
/// let g = f.curry(1, 2);  // curried arguments: 1, 2
 | 
			
		||||
/// 
 | 
			
		||||
/// g.call(3);              // call: foo(1, 2, 3)
 | 
			
		||||
/// ```
 | 
			
		||||
fn curry(fn_ptr: FnPtr, ...args: ?) -> FnPtr;
 | 
			
		||||
 | 
			
		||||
/// Return `true` if a script-defined function exists with a specified name and
 | 
			
		||||
/// number of parameters.
 | 
			
		||||
/// 
 | 
			
		||||
/// # Example
 | 
			
		||||
/// 
 | 
			
		||||
/// ```rhai
 | 
			
		||||
/// fn foo(x) { }
 | 
			
		||||
/// 
 | 
			
		||||
/// print(is_def_fn("foo", 1));     // prints true
 | 
			
		||||
/// print(is_def_fn("foo", 2));     // prints false
 | 
			
		||||
/// print(is_def_fn("foo", 0));     // prints false
 | 
			
		||||
/// print(is_def_fn("bar", 1));     // prints false
 | 
			
		||||
/// ```
 | 
			
		||||
fn is_def_fn(fn_name: String, num_params: int) -> bool;
 | 
			
		||||
 | 
			
		||||
/// Return `true` if a variable matching a specified name is defined.
 | 
			
		||||
/// 
 | 
			
		||||
/// # Example
 | 
			
		||||
/// 
 | 
			
		||||
/// ```rhai
 | 
			
		||||
/// let x = 42;
 | 
			
		||||
/// 
 | 
			
		||||
/// print(is_def_var("x"));         // prints true
 | 
			
		||||
/// print(is_def_var("foo"));       // prints false
 | 
			
		||||
/// 
 | 
			
		||||
/// {
 | 
			
		||||
///     let y = 1;
 | 
			
		||||
///     print(is_def_var("y"));     // prints true
 | 
			
		||||
/// }
 | 
			
		||||
/// 
 | 
			
		||||
/// print(is_def_var("y"));         // prints false
 | 
			
		||||
/// ```
 | 
			
		||||
fn is_def_var(var_name: String) -> bool;
 | 
			
		||||
 | 
			
		||||
/// Return `true` if the variable is shared.
 | 
			
		||||
/// 
 | 
			
		||||
/// # Example
 | 
			
		||||
/// 
 | 
			
		||||
/// ```rhai
 | 
			
		||||
/// let x = 42;
 | 
			
		||||
/// 
 | 
			
		||||
/// print(is_shared(x));        // prints false
 | 
			
		||||
/// 
 | 
			
		||||
/// let f = || x;               // capture 'x', making it shared
 | 
			
		||||
/// 
 | 
			
		||||
/// print(is_shared(x));        // prints true
 | 
			
		||||
/// ```
 | 
			
		||||
fn is_shared(variable: ?) -> bool;
 | 
			
		||||
 | 
			
		||||
/// Evaluate a text script within the current scope.
 | 
			
		||||
/// 
 | 
			
		||||
/// # Example
 | 
			
		||||
/// 
 | 
			
		||||
/// ```rhai
 | 
			
		||||
/// let x = 42;
 | 
			
		||||
/// 
 | 
			
		||||
/// eval("let y = x; x = 123;");
 | 
			
		||||
/// 
 | 
			
		||||
/// print(x);           // prints 123
 | 
			
		||||
/// print(y);           // prints 42
 | 
			
		||||
/// ```
 | 
			
		||||
fn eval(script: String) -> ?;
 | 
			
		||||
 | 
			
		||||
/// Return `true` if the string contains another string.
 | 
			
		||||
///
 | 
			
		||||
/// This function also drives the `in` operator.
 | 
			
		||||
///
 | 
			
		||||
/// # Example
 | 
			
		||||
///
 | 
			
		||||
/// ```rhai
 | 
			
		||||
/// let x = "hello world!";
 | 
			
		||||
///
 | 
			
		||||
/// // The 'in' operator calls 'contains' in the background
 | 
			
		||||
/// if "world" in x {
 | 
			
		||||
///     print("found!");
 | 
			
		||||
/// }
 | 
			
		||||
/// ```
 | 
			
		||||
fn contains(string: String, find: String) -> bool;
 | 
			
		||||
 | 
			
		||||
/// Return `true` if the string contains a character.
 | 
			
		||||
///
 | 
			
		||||
/// This function also drives the `in` operator.
 | 
			
		||||
///
 | 
			
		||||
/// # Example
 | 
			
		||||
///
 | 
			
		||||
/// ```rhai
 | 
			
		||||
/// let x = "hello world!";
 | 
			
		||||
///
 | 
			
		||||
/// // The 'in' operator calls 'contains' in the background
 | 
			
		||||
/// if 'w' in x {
 | 
			
		||||
///     print("found!");
 | 
			
		||||
/// }
 | 
			
		||||
/// ```
 | 
			
		||||
fn contains(string: String, ch: char) -> bool;
 | 
			
		||||
 | 
			
		||||
/// Return `true` if a value falls within the exclusive range.
 | 
			
		||||
///
 | 
			
		||||
/// This function also drives the `in` operator.
 | 
			
		||||
///
 | 
			
		||||
/// # Example
 | 
			
		||||
///
 | 
			
		||||
/// ```rhai
 | 
			
		||||
/// let r = 1..100;
 | 
			
		||||
///
 | 
			
		||||
/// // The 'in' operator calls 'contains' in the background
 | 
			
		||||
/// if 42 in r {
 | 
			
		||||
///     print("found!");
 | 
			
		||||
/// }
 | 
			
		||||
/// ```
 | 
			
		||||
fn contains(range: Range<int>, value: int) -> bool;
 | 
			
		||||
 | 
			
		||||
/// Return `true` if a value falls within the inclusive range.
 | 
			
		||||
///
 | 
			
		||||
/// This function also drives the `in` operator.
 | 
			
		||||
///
 | 
			
		||||
/// # Example
 | 
			
		||||
///
 | 
			
		||||
/// ```rhai
 | 
			
		||||
/// let r = 1..=100;
 | 
			
		||||
///
 | 
			
		||||
/// // The 'in' operator calls 'contains' in the background
 | 
			
		||||
/// if 42 in r {
 | 
			
		||||
///     print("found!");
 | 
			
		||||
/// }
 | 
			
		||||
/// ```
 | 
			
		||||
fn contains(range: RangeInclusive<int>, value: int) -> bool;
 | 
			
		||||
 | 
			
		||||
/// Return `true` if a key exists within the object map.
 | 
			
		||||
///
 | 
			
		||||
/// This function also drives the `in` operator.
 | 
			
		||||
///
 | 
			
		||||
/// # Example
 | 
			
		||||
///
 | 
			
		||||
/// ```rhai
 | 
			
		||||
/// let m = #{a:1, b:2, c:3};
 | 
			
		||||
///
 | 
			
		||||
/// // The 'in' operator calls 'contains' in the background
 | 
			
		||||
/// if "c" in m {
 | 
			
		||||
///     print("found!");
 | 
			
		||||
/// }
 | 
			
		||||
/// ```
 | 
			
		||||
fn contains(map: Map, string: String) -> bool;
 | 
			
		||||
 | 
			
		||||
/// Return `true` if a value is found within the BLOB.
 | 
			
		||||
///
 | 
			
		||||
/// This function also drives the `in` operator.
 | 
			
		||||
///
 | 
			
		||||
/// # Example
 | 
			
		||||
///
 | 
			
		||||
/// ```rhai
 | 
			
		||||
/// let b = blob();
 | 
			
		||||
///
 | 
			
		||||
/// b += 1; b += 2; b += 3; b += 4; b += 5;
 | 
			
		||||
///
 | 
			
		||||
/// // The 'in' operator calls 'contains' in the background
 | 
			
		||||
/// if 3 in b {
 | 
			
		||||
///     print("found!");
 | 
			
		||||
/// }
 | 
			
		||||
/// ```
 | 
			
		||||
fn contains(blob: Blob, value: int) -> bool;
 | 
			
		||||
@@ -0,0 +1,5 @@
 | 
			
		||||
module static;
 | 
			
		||||
 | 
			
		||||
let hello_there: string;
 | 
			
		||||
 | 
			
		||||
const HELLO: string;
 | 
			
		||||
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							@@ -0,0 +1,6 @@
 | 
			
		||||
module general_kenobi;
 | 
			
		||||
 | 
			
		||||
const CONSTANT: int;
 | 
			
		||||
 | 
			
		||||
/// Returns a string where "hello there" is repeated `n` times.
 | 
			
		||||
fn hello_there(n: int) -> String;
 | 
			
		||||
							
								
								
									
										49
									
								
								rhai_engine/rhaiexamples/definitions/.rhai/defs.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										49
									
								
								rhai_engine/rhaiexamples/definitions/.rhai/defs.json
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,49 @@
 | 
			
		||||
{
 | 
			
		||||
  "modules": {
 | 
			
		||||
    "general_kenobi": {
 | 
			
		||||
      "functions": [
 | 
			
		||||
        {
 | 
			
		||||
          "baseHash": 3873007749982070651,
 | 
			
		||||
          "fullHash": 5865213555928423624,
 | 
			
		||||
          "namespace": "internal",
 | 
			
		||||
          "access": "public",
 | 
			
		||||
          "name": "hello_there",
 | 
			
		||||
          "type": "native",
 | 
			
		||||
          "numParams": 1,
 | 
			
		||||
          "params": [
 | 
			
		||||
            {
 | 
			
		||||
              "name": "n",
 | 
			
		||||
              "type": "i64"
 | 
			
		||||
            }
 | 
			
		||||
          ],
 | 
			
		||||
          "returnType": "String",
 | 
			
		||||
          "signature": "hello_there(n: i64) -> String",
 | 
			
		||||
          "docComments": [
 | 
			
		||||
            "/// Returns a string where \"hello there\" is repeated `n` times."
 | 
			
		||||
          ]
 | 
			
		||||
        }
 | 
			
		||||
      ]
 | 
			
		||||
    }
 | 
			
		||||
  },
 | 
			
		||||
  "functions": [
 | 
			
		||||
    {
 | 
			
		||||
      "baseHash": 12461724250411739075,
 | 
			
		||||
      "fullHash": 14530626537296006176,
 | 
			
		||||
      "namespace": "global",
 | 
			
		||||
      "access": "public",
 | 
			
		||||
      "name": "minus",
 | 
			
		||||
      "type": "native",
 | 
			
		||||
      "numParams": 2,
 | 
			
		||||
      "params": [
 | 
			
		||||
        {
 | 
			
		||||
          "type": "i64"
 | 
			
		||||
        },
 | 
			
		||||
        {
 | 
			
		||||
          "type": "i64"
 | 
			
		||||
        }
 | 
			
		||||
      ],
 | 
			
		||||
      "returnType": "i64",
 | 
			
		||||
      "signature": "minus(_: i64, _: i64) -> i64"
 | 
			
		||||
    }
 | 
			
		||||
  ]
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										70
									
								
								rhai_engine/rhaiexamples/definitions/main.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										70
									
								
								rhai_engine/rhaiexamples/definitions/main.rs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,70 @@
 | 
			
		||||
use rhai::plugin::*;
 | 
			
		||||
use rhai::{Engine, EvalAltResult, Scope};
 | 
			
		||||
 | 
			
		||||
#[export_module]
 | 
			
		||||
pub mod general_kenobi {
 | 
			
		||||
    /// General Kenobi's Constant.
 | 
			
		||||
    pub const CONSTANT: i64 = 42;
 | 
			
		||||
 | 
			
		||||
    /// Returns a string where "hello there" is repeated `n` times.
 | 
			
		||||
    pub fn hello_there(n: i64) -> String {
 | 
			
		||||
        use std::convert::TryInto;
 | 
			
		||||
        "hello there ".repeat(n.try_into().unwrap())
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
fn main() -> Result<(), Box<EvalAltResult>> {
 | 
			
		||||
    let mut engine = Engine::new();
 | 
			
		||||
    let mut scope = Scope::new();
 | 
			
		||||
 | 
			
		||||
    // This variable will also show up in the definitions, since it will be part of the scope.
 | 
			
		||||
    scope.push("hello_there", "hello there");
 | 
			
		||||
 | 
			
		||||
    // This constant will also show up in the definitions, since it will be part of the scope.
 | 
			
		||||
    scope.push_constant("HELLO", "hello there");
 | 
			
		||||
 | 
			
		||||
    #[cfg(not(feature = "no_module"))]
 | 
			
		||||
    engine.register_static_module("general_kenobi", exported_module!(general_kenobi).into());
 | 
			
		||||
 | 
			
		||||
    // Custom operators also show up in definitions.
 | 
			
		||||
    #[cfg(not(feature = "no_custom_syntax"))]
 | 
			
		||||
    {
 | 
			
		||||
        engine.register_custom_operator("minus", 100).unwrap();
 | 
			
		||||
        engine.register_fn("minus", |a: i64, b: i64| a - b);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    engine.run_with_scope(
 | 
			
		||||
        &mut scope,
 | 
			
		||||
        "hello_there = general_kenobi::hello_there(4 minus 2);",
 | 
			
		||||
    )?;
 | 
			
		||||
 | 
			
		||||
    // Generate definitions for the contents of the engine and the scope.
 | 
			
		||||
    engine
 | 
			
		||||
        .definitions_with_scope(&scope)
 | 
			
		||||
        .write_to_dir("examples/definitions/.rhai/definitions")
 | 
			
		||||
        .unwrap();
 | 
			
		||||
 | 
			
		||||
    // Alternatively we can write all of the above to a single file.
 | 
			
		||||
    engine
 | 
			
		||||
        .definitions_with_scope(&scope)
 | 
			
		||||
        .write_to_file("examples/definitions/.rhai/all_in_one.d.rhai")
 | 
			
		||||
        .unwrap();
 | 
			
		||||
 | 
			
		||||
    // Skip standard packages if not needed (e.g. they are provided elsewhere).
 | 
			
		||||
    engine
 | 
			
		||||
        .definitions_with_scope(&scope)
 | 
			
		||||
        .include_standard_packages(false)
 | 
			
		||||
        .write_to_file("examples/definitions/.rhai/all_in_one_without_standard.d.rhai")
 | 
			
		||||
        .unwrap();
 | 
			
		||||
 | 
			
		||||
    // Write function definitions as JSON.
 | 
			
		||||
    let json = engine
 | 
			
		||||
        .definitions()
 | 
			
		||||
        .include_standard_packages(false)
 | 
			
		||||
        .json()
 | 
			
		||||
        .unwrap();
 | 
			
		||||
 | 
			
		||||
    std::fs::write("examples/definitions/.rhai/defs.json", json).unwrap();
 | 
			
		||||
 | 
			
		||||
    Ok(())
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										3
									
								
								rhai_engine/rhaiexamples/definitions/script.rhai
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								rhai_engine/rhaiexamples/definitions/script.rhai
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,3 @@
 | 
			
		||||
// The following will be valid based on the definitions.
 | 
			
		||||
hello_there = general_kenobi::hello_there(123);
 | 
			
		||||
print(hello_there);
 | 
			
		||||
		Reference in New Issue
	
	Block a user