macro_rules! lua {
() => { ... };
(nil) => { ... };
($item:expr) => { ... };
(cstr $item:literal) => { ... };
($($key:ident = $val:expr),* $(,)?) => { ... };
($([$key:expr] = $val:expr),* $(,)?) => { ... };
}Expand description
Provides a simple syntax for constructing lua objects.
This was inspired by the very similar json! macro from serde_json.
ยงExamples
use faf_replay_parser::{lua, lua::LuaObject};
// Basic types
let obj1: LuaObject = lua!(10.0);
let obj2: LuaObject = lua!(nil);
let obj3: LuaObject = lua!(true);
// By default, strings are converted to `LuaObject::Unicode`
let obj4: LuaObject = lua!("foo");
// `LuaObject::String`s need to be explicitly prefixed
let obj5: LuaObject = lua!(cstr "foo");
// Tables use lua syntax
let table1: LuaObject = lua! {
foo = "bar",
// Expression evaluation is supported
bar = 2.0 + 3.0,
};
let table2: LuaObject = lua! {
["foo"] = "bar",
[10.] = true,
// Trailing comma optional
[false] = 100.
};