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

Commit 300064f

Browse files
committed
Use libloading instead of dlopen
Fixes #4. Api has not changed at all.
1 parent 0e39b9e commit 300064f

3 files changed

Lines changed: 8 additions & 7 deletions

File tree

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@ edition = "2018"
1111
# Remember to make your output module a cdylib.
1212

1313
[dependencies]
14-
dlopen = "0.1.8"
14+
libloading = "0.7.0"
1515
once_cell = "1.7.2"

README.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,3 @@ pub extern fn gmod13_close(_state: LuaState) -> i32 {
6262
## Acknowledgements
6363
### [garrysmod_common](https://github.com/danielga/garrysmod_common)
6464
This is heavily based off of garrysmod_common, in how we export the lua_shared functions and trying to replicate everything from the Lua C Api.
65-
66-
### [rust-dlopen](https://github.com/szymonwieloch/rust-dlopen)
67-
Thanks to this library we're able to make rglua cross platform.

src/lua_shared.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#![allow(unused)]
22
#![macro_export]
33

4-
use dlopen::raw::Library;
4+
use libloading::Library;
55

66
// Keep separate in case needed by crates.
77
pub static GMOD_DIR: Lazy<PathBuf> = Lazy::new(|| {
@@ -43,15 +43,19 @@ pub static LUA_SHARED_PATH: Lazy<Option<PathBuf>> = Lazy::new(|| {
4343
macro_rules! expose_symbol {
4444
($name:ident, $ret:ty, $($args:tt)*) => {
4545
pub const $name: Lazy<extern fn$($args)* -> $ret> = Lazy::new(|| {
46-
unsafe { LUA_SHARED_RAW.symbol( stringify!($name) ) }.unwrap()
46+
unsafe {
47+
let lib = &*LUA_SHARED_RAW;
48+
let v: libloading::Symbol<extern fn$($args)* -> $ret> = lib.get( stringify!($name).as_bytes() ).unwrap();
49+
std::mem::transmute(v)
50+
}
4751
});
4852
};
4953
}
5054

5155
// dlopen raw lua_shared.dll library. Don't use this unless you know what you're doing.
5256
pub const LUA_SHARED_RAW: Lazy<Library> = Lazy::new(|| {
5357
let path = LUA_SHARED_PATH.as_ref().expect("Couldn't find lua_shared.dll!");
54-
Library::open(path).expect("Could not open library")
58+
unsafe { Library::new(path).expect("Could not open library") }
5559
});
5660

5761
use std::path::PathBuf;

0 commit comments

Comments
 (0)