Add `is_client` and `is_server`

This commit is contained in:
William Venner 2021-12-09 19:50:46 +00:00
parent 1f358a0b0f
commit d87cf56251
3 changed files with 18 additions and 2 deletions

2
Cargo.lock generated
View File

@ -135,7 +135,7 @@ dependencies = [
[[package]]
name = "gmod"
version = "10.2.0"
version = "10.2.1"
dependencies = [
"cfg_table 1.0.0",
"cstr",

View File

@ -1,6 +1,6 @@
[package]
name = "gmod"
version = "10.2.0"
version = "10.2.1"
authors = ["William Venner <william@venner.io>"]
edition = "2018"
license = "MIT"

View File

@ -19,6 +19,22 @@ impl LuaState {
}
}
/// Returns whether this is the clientside Lua state or not.
pub unsafe fn is_client(&self) -> bool {
self.get_global(crate::lua_string!("CLIENT"));
let client = self.get_boolean(-1);
self.pop();
client
}
/// Returns whether this is the serverside Lua state or not.
pub unsafe fn is_server(&self) -> bool {
self.get_global(crate::lua_string!("SERVER"));
let server = self.get_boolean(-1);
self.pop();
server
}
/// Returns the Lua string as a slice of bytes.
///
/// **WARNING:** This will CHANGE the type of the value at the given index to a string.