diff --git a/Cargo.lock b/Cargo.lock index 18f4b10..d5c3bb9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -135,7 +135,7 @@ dependencies = [ [[package]] name = "gmod" -version = "10.0.0" +version = "10.1.0" dependencies = [ "cfg_table 1.0.0", "cstr", diff --git a/gmod/Cargo.toml b/gmod/Cargo.toml index ce9e256..6f51298 100644 --- a/gmod/Cargo.toml +++ b/gmod/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "gmod" -version = "10.0.0" +version = "10.1.0" authors = ["William Venner "] edition = "2018" license = "MIT" diff --git a/gmod/src/lib.rs b/gmod/src/lib.rs index ad2c6bd..7cf53e9 100644 --- a/gmod/src/lib.rs +++ b/gmod/src/lib.rs @@ -39,15 +39,36 @@ pub mod userdata; pub mod net; /// Returns whether this client is running the x86-64 branch -/// -/// Current implementation checks the contents of the bin/ directory, so this is a blocking operation and requires syscalls, use sparingly pub fn is_x86_64() -> bool { - use std::path::PathBuf; - #[cfg(target_os = "linux")] { - PathBuf::from("bin/linux64").is_dir() + #[cfg(target_pointer_width = "64")] { + // 64-bit can only be x86-64 + true } - #[cfg(target_os = "windows")] { - PathBuf::from("bin/win64").is_dir() + #[cfg(target_pointer_width = "32")] { + lazy_static::lazy_static! { + static ref IS_X86_64: bool = { + use std::path::PathBuf; + + // Check LuaJIT version + unsafe { + let (lib, _) = lua::LuaShared::find_lua_shared(); + if lib.get::<()>(b"luaJIT_version_2_0_4\0").is_ok() { + false + } else if lib.get::<()>(b"luaJIT_version_2_1_0_beta3\0").is_ok() { + true + } else { + // Check bin folder + #[cfg(target_os = "linux")] { + PathBuf::from("bin/linux64").is_dir() + } + #[cfg(target_os = "windows")] { + PathBuf::from("bin/win64").is_dir() + } + } + } + }; + } + *IS_X86_64 } } diff --git a/gmod/src/lua/import.rs b/gmod/src/lua/import.rs index c7f3197..40b09c3 100644 --- a/gmod/src/lua/import.rs +++ b/gmod/src/lua/import.rs @@ -249,27 +249,27 @@ impl LuaShared { } #[cfg(all(target_os = "windows", target_pointer_width = "64"))] - unsafe fn find_lua_shared() -> (Library, &'static str) { + pub unsafe fn find_lua_shared() -> (Library, &'static str) { find_library!("bin/win64/lua_shared.dll") .expect("Failed to load lua_shared.dll") } #[cfg(all(target_os = "windows", target_pointer_width = "32"))] - unsafe fn find_lua_shared() -> (Library, &'static str) { + pub unsafe fn find_lua_shared() -> (Library, &'static str) { find_library!("garrysmod/bin/lua_shared.dll") .or_else(|_| find_library!("bin/lua_shared.dll")) .expect("Failed to load lua_shared.dll") } #[cfg(all(target_os = "linux", target_pointer_width = "32"))] - unsafe fn find_lua_shared() -> (Library, &'static str) { + pub unsafe fn find_lua_shared() -> (Library, &'static str) { find_library!("garrysmod/bin/lua_shared_srv.so") .or_else(|_| find_library!("bin/linux32/lua_shared.so")) .expect("Failed to find lua_shared.so or lua_shared_srv.so") } #[cfg(all(target_os = "linux", target_pointer_width = "64"))] - unsafe fn find_lua_shared() -> (Library, &'static str) { + pub unsafe fn find_lua_shared() -> (Library, &'static str) { find_library!("bin/linux64/lua_shared.so") .expect("Failed to find lua_shared.so") }