docs: Add printing to console example.
This commit is contained in:
parent
d87cf56251
commit
9dbf2d4688
|
@ -0,0 +1,11 @@
|
||||||
|
[package]
|
||||||
|
name = "printing-to-console"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
publish = false
|
||||||
|
|
||||||
|
[lib]
|
||||||
|
crate-type = ["cdylib"]
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
gmod = {version = "10.2.1", features = ["gmcl"], default-features = false}
|
|
@ -0,0 +1,4 @@
|
||||||
|
# Printing to Console Example
|
||||||
|
|
||||||
|
This is an example of using a module to print to console.
|
||||||
|
Compiling should follow the instructions in [my-first-binary-module](../my-first-binary-module/README.md).
|
|
@ -0,0 +1,2 @@
|
||||||
|
[toolchain]
|
||||||
|
channel = "nightly"
|
|
@ -0,0 +1,29 @@
|
||||||
|
#![feature(c_unwind)]
|
||||||
|
|
||||||
|
use gmod::gmcl::override_stdout;
|
||||||
|
use gmod::lua::State;
|
||||||
|
|
||||||
|
#[macro_use] extern crate gmod;
|
||||||
|
|
||||||
|
#[gmod13_open]
|
||||||
|
fn gmod13_open(lua: State) -> i32 {
|
||||||
|
// Here, if this module is running on the client.
|
||||||
|
if lua.is_client() {
|
||||||
|
// We overwrite println! so it prints to the console.
|
||||||
|
override_stdout()
|
||||||
|
}
|
||||||
|
|
||||||
|
if lua.is_server() {
|
||||||
|
println!("Hello Server, this is a binary module!")
|
||||||
|
} else {
|
||||||
|
println!("Hello Client, this is a binary module!")
|
||||||
|
}
|
||||||
|
|
||||||
|
0
|
||||||
|
}
|
||||||
|
|
||||||
|
#[gmod13_close]
|
||||||
|
fn gmod13_close(lua: State) -> i32 {
|
||||||
|
println!("Goodbye from binary module!");
|
||||||
|
0
|
||||||
|
}
|
Loading…
Reference in New Issue