This commit is contained in:
William Venner 2021-12-30 18:19:58 +00:00
commit e9ef9e0978
4 changed files with 46 additions and 0 deletions

View File

@ -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}

View File

@ -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).

View File

@ -0,0 +1,2 @@
[toolchain]
channel = "nightly"

View File

@ -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
}