Macro vslice
macro_rules! vslice {
($($elements:expr),* $(,)?) => { ... };
}Expand description
Constructs a slice of Variant literals, useful for passing to vararg functions.
Many APIs in Godot have variable-length arguments. GDScript can call such functions by simply passing more arguments, but in Rust,
the parameter type &[Variant] is used.
This macro creates a slice of Variant values.
§Examples
Variable number of arguments:
let slice: &[Variant] = vslice![42, "hello", true];
let concat: GString = godot::global::str(slice);(In practice, you might want to use godot_str! instead of str().)
Dynamic function call via reflection. NIL can still be passed inside vslice!, just use Variant::nil().
let mut obj: Gd<Object> = some_object();
obj.call("some_method", vslice![Vector2i::new(1, 2), Variant::nil()]);§See also
To create typed and untyped Arrays, use the array! and varray! macros respectively.
For dictionaries, a similar macro vdict! exists.