Skip to content
This repository was archived by the owner on Nov 12, 2025. It is now read-only.

Commit dd1dbcf

Browse files
committed
Add LUA_SHAREDR
Lets you get the result of trying to load a container from dlopen at the path so you don't crash your app. Haven't tested.
1 parent a63e2b0 commit dd1dbcf

1 file changed

Lines changed: 16 additions & 4 deletions

File tree

src/lib.rs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,14 +181,26 @@ pub static LUA_SHARED_PATH: Lazy<Option<PathBuf>> = Lazy::new(|| {
181181
}
182182
});
183183

184-
pub static LUA_SHARED: Lazy< Container<LuaSharedInterface> > = Lazy::new(|| {
184+
type LuaSharedLibrary = Container<LuaSharedInterface>;
185+
186+
// Returns the underlying result of trying to create a luasharedinterface.
187+
// Useful if you don't want your program to panic at all.
188+
pub static LUA_SHAREDR: Lazy< Result< LuaSharedLibrary, dlopen::Error> > = Lazy::new(|| {
189+
let dll_path = match &*LUA_SHARED_PATH {
190+
Some(path) => path,
191+
None => panic!("Couldn't get lua_shared location. Make sure it's at GarrysMod/bin/ or GarrysMod/garrysmod/bin/")
192+
};
193+
unsafe {Container::load(dll_path)}
194+
});
195+
196+
pub static LUA_SHARED: Lazy< &LuaSharedLibrary > = Lazy::new(|| {
185197
let dll_path = match &*LUA_SHARED_PATH {
186198
Some(path) => path,
187199
None => panic!("Couldn't get lua_shared location. Make sure it's at GarrysMod/bin/ or GarrysMod/garrysmod/bin/")
188200
};
189201

190-
return match unsafe {Container::load(dll_path)} {
191-
Ok(lib) => lib,
202+
match &*LUA_SHAREDR {
203+
Ok(lib) => lib, // We shouldn't need a mutable LuaSharedLibrary.
192204
Err(why) => panic!("Path DLL tried to load: {}, Error Reason: {}. Report this on github.", dll_path.display(), why)
193205
}
194-
});
206+
});

0 commit comments

Comments
 (0)