From d87cf56251dae132a46c46d3c5744c6743e5682d Mon Sep 17 00:00:00 2001 From: William Venner Date: Thu, 9 Dec 2021 19:50:46 +0000 Subject: [PATCH] Add `is_client` and `is_server` --- Cargo.lock | 2 +- gmod/Cargo.toml | 2 +- gmod/src/lua/lua_state.rs | 16 ++++++++++++++++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5b4adbd..14a5a09 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -135,7 +135,7 @@ dependencies = [ [[package]] name = "gmod" -version = "10.2.0" +version = "10.2.1" dependencies = [ "cfg_table 1.0.0", "cstr", diff --git a/gmod/Cargo.toml b/gmod/Cargo.toml index 0481807..6fc0f90 100644 --- a/gmod/Cargo.toml +++ b/gmod/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "gmod" -version = "10.2.0" +version = "10.2.1" authors = ["William Venner "] edition = "2018" license = "MIT" diff --git a/gmod/src/lua/lua_state.rs b/gmod/src/lua/lua_state.rs index 37d93fb..9a43b9c 100644 --- a/gmod/src/lua/lua_state.rs +++ b/gmod/src/lua/lua_state.rs @@ -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.