Macro as_table

Source
macro_rules! as_table {
    ($( $key:expr => $value:expr ),* $(,)?) => { ... };
    ($( $item:expr ),* $(,)?) => { ... };
}
Expand description

A helper macro for creating AsTable wrappers. Use this to pass ad-hoc lua tables into lua.

ยงExample

use tlua::as_table;
let lua = tlua::Lua::new();

lua.exec_with(
    "set_configuration(...)",
    as_table! {
        "log" => "my-log-file.txt",
        "fruit" => as_table! { "apple", "banana", "orange" },
        extra_key() => extra_value(),
        420 => "secret-number-field",
    }
)
.unwrap();

lua.exec_with(
    "set_http_request_handler",
    tlua::Function::new(|| -> _ {
        as_table! {
            "status" => 200,
            "headers" => as_table! {
                "content-type" => "application/json",
            },
            "body" => r#"{"error":"request-failed"}"#
        }
    })
)
.unwrap();