use libloading::Library;
use std::path::PathBuf;
use once_cell::sync::Lazy;
mod shared;
pub use shared::*;
mod globals;
pub use globals::*;
pub mod types;
pub use types::*;
#[cfg(all(target_os = "windows", target_arch = "x86_64"))]
pub static LUA_SHARED_PATH: Lazy<Option<PathBuf>> =
Lazy::new(|| Some(PathBuf::from("bin/win64/lua_shared.dll")));
#[cfg(all(target_os = "windows", target_arch = "x86"))]
pub static LUA_SHARED_PATH: Lazy<Option<PathBuf>> = Lazy::new(|| {
let gmod = std::env::current_dir().expect("Failed to get current dir");
for path in ["garrysmod/bin/lua_shared.dll", "bin/lua_shared.dll"] {
let full = gmod.join(path);
if full.exists() {
return Some(full);
}
}
None
});
#[cfg(all(target_os = "macos"))]
pub static LUA_SHARED_PATH: Lazy<Option<PathBuf>> =
Lazy::new(|| Some(PathBuf::from("garrysmod/bin/lua_shared.dylib")));
#[cfg(all(target_os = "linux", target_arch = "x86"))]
pub static LUA_SHARED_PATH: Lazy<Option<PathBuf>> = Lazy::new(|| {
let gmod = std::env::current_dir().expect("Failed to get current dir");
for path in [
"garrysmod/bin/lua_shared_srv.so",
"garrysmod/bin/lua_shared.so",
"bin/linux32/lua_shared.so",
"bin/linux32/lua_shared_client.so"
] {
let full = gmod.join(path);
if full.exists() {
return Some(full);
}
}
None
});
#[cfg(all(target_os = "linux", target_arch = "x86_64"))]
pub static LUA_SHARED_PATH: Lazy<Option<PathBuf>> = Lazy::new(|| {
let gmod = std::env::current_dir().expect("Failed to get current dir");
for path in [
"bin/linux64/lua_shared.so",
"bin/linux64/lua_shared_client.so"
] {
let full = gmod.join(path);
if full.exists() {
return Some(full);
}
}
None
});
pub static LUA_SHARED_RAW: Lazy<Library> = Lazy::new(|| {
let path = LUA_SHARED_PATH
.as_ref()
.expect("Couldn't find lua_shared dylib!");
unsafe { Library::new(path).expect("Could not open library") }
});