Skip to content
This repository was archived by the owner on Nov 12, 2025. It is now read-only.

Commit 5a4e9ce

Browse files
committed
Add printgm macro
Now it uses the ``format!`` macro style so you'd call it as so: ``rglua::printgm!(state, "Hello world {}", 24)``
1 parent 74de644 commit 5a4e9ce

2 files changed

Lines changed: 20 additions & 1 deletion

File tree

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ license = "MIT"
1111

1212
[dependencies]
1313
dlopen = { git = "https://github.com/Vurv78/rust-dlopen", branch = "future", features = ["derive"] }
14-
once_cell = "1.7.2"
14+
once_cell = "1.7.2"

src/helpers.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,23 @@ macro_rules! rstring {
2121
cstr.to_str().expect("Couldn't unwrap CString")
2222
}
2323
}
24+
}
25+
26+
#[allow(unused_macros)]
27+
#[macro_export]
28+
/// Like println!, however it prints to the gmod server's console.
29+
macro_rules! printgm {
30+
// First arg is the lua state.
31+
// Rest are varargs.
32+
// Can be either a variable storing a str literal, or a referenced String / str variable
33+
($state:expr, $($x:expr),*) => {
34+
{
35+
let stmt = format!( $($x,)* ); // Everything past the state will be as if it were inside a format! call.
36+
let lib = *rglua::LUA_SHARED;
37+
lib.lua_getglobal($state, rglua::cstring!("print") );
38+
lib.lua_pushstring($state, rglua::cstring!(stmt) );
39+
// 1 arg, 0 results
40+
lib.lua_call($state, 1, 0);
41+
}
42+
};
2443
}

0 commit comments

Comments
 (0)