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

Commit 37e65d9

Browse files
committed
Add proc macros
* Bump to 0.9.0 * Add #[lua_function] #[gmod_open] #[gmod_close] proc macros which allow for you to return Result<i32, E> from a gmod function.
1 parent bc7b3fe commit 37e65d9

File tree

30 files changed

+316
-48
lines changed

30 files changed

+316
-48
lines changed

Cargo.toml

Lines changed: 6 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,6 @@
1-
[package]
2-
name = "rglua"
3-
description = "Toolkit for garrysmod development with the source sdk and luajit api"
4-
version = "0.8.0"
5-
authors = ["Vurv <vurvdevelops@gmail.com>"]
6-
keywords = ["glua", "garrysmod", "lua", "gmod"]
7-
categories = ["api-bindings", "external-ffi-bindings", "development-tools::ffi", "game-development", "accessibility"]
8-
readme = "README.md"
9-
license = "MIT"
10-
edition = "2021"
11-
12-
# Remember to make your output module a cdylib.
13-
14-
[dependencies]
15-
libloading = "0.7.2"
16-
once_cell = "1.8.0"
17-
thiserror = "1.0.30"
18-
19-
derive_more = { version = "0.99.17", optional = true }
20-
21-
vtables = { version = "0.1.0", optional = true }
22-
vtables_derive = { version = "0.1.0", optional = true }
23-
24-
[features]
25-
default = ["interfaces", "userdata"]
26-
27-
interfaces = ["vtables", "vtables_derive"]
28-
29-
userdata = ["derive_more"]
1+
[workspace]
2+
members = [
3+
"rglua",
4+
"rglua-macros"
5+
]
6+
exclude = ["examples"]

README.md

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,24 @@ cargo build --release --target=i686-pc-windows-msvc
1414
### [garrysmod_common](https://github.com/danielga/garrysmod_common)
1515
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.
1616

17-
1817
## Comparison
19-
There are actually a decent amount of libraries out there for gmod development
18+
There are actually a decent amount of libraries out there for gmod development.
19+
Here's a comparison and why you could use this one.
20+
21+
[rglua]: https://crates.io/crates/rglua
22+
[rust-glua-sys]: https://github.com/SpiralP/rust-glua-sys
23+
[gmod-rs]: https://crates.io/crates/gmod
24+
[gmrs]: https://github.com/diogo464/gmrs
25+
26+
| Library | [rglua] | [rust-glua-sys] | [gmod-rs] | [gmrs] |
27+
|-----------------------------------|---------|-----------------|------------|--------|
28+
| Lua C Api Bindings | ✔️ | ✔️ | ✔️ ||
29+
| Crates.io | ✔️ || ✔️ ||
30+
| Proc Macros | ✔️ || ✔️ | ✔️ |
31+
| Interfacing w/ Source SDK | ✔️ ||||
32+
| Returning Result<> from functions | ✔️ ||||
33+
| Can be used on stable | ✔️ | ✔️ || ✔️ |
34+
| Real world examples | ✔️ || ✔️ ||
35+
| Github Stars | 😢 | 👍 | 👑 | 🤷‍♂️ |
2036

37+
__*You can help with that last one 😉*__

examples/engine/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
[package]
22
name = "gmod_engine"
33
description = "Binary module that accesses engine.dll"
4-
version = "0.1.0"
4+
version = "0.2.0"
55
edition = "2021"
66
publish = false
77

88
[lib]
99
crate-type = ["cdylib"]
1010

1111
[dependencies]
12-
rglua = { path = "../.." }
12+
rglua = { path = "../../rglua" }
1313
anyhow = "1.0.51"

examples/engine/src/lib.rs

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ fn get_iface() -> anyhow::Result<&'static EngineClient> {
1212
}
1313
}
1414

15-
extern "C" fn concmd(l: LuaState) -> i32 {
15+
#[lua_function]
16+
fn concmd(l: LuaState) -> i32 {
1617
match get_iface() {
1718
Ok(iface) => {
1819
iface.ExecuteClientCmd( luaL_checklstring(l, 1, 0) );
@@ -22,7 +23,8 @@ extern "C" fn concmd(l: LuaState) -> i32 {
2223
0
2324
}
2425

25-
extern "C" fn get_resolution(l: LuaState) -> i32 {
26+
#[lua_function]
27+
fn get_resolution(l: LuaState) -> i32 {
2628
match get_iface() {
2729
Ok(iface) => unsafe {
2830
let (w, h): (*mut _, *mut _) = (&mut 0, &mut 0);
@@ -38,7 +40,8 @@ extern "C" fn get_resolution(l: LuaState) -> i32 {
3840
0
3941
}
4042

41-
extern "C" fn get_directory(l: LuaState) -> i32 {
43+
#[lua_function]
44+
fn get_directory(l: LuaState) -> i32 {
4245
match get_iface() {
4346
Ok(iface) => {
4447
let dir = iface.GetGameDirectory();
@@ -52,7 +55,8 @@ extern "C" fn get_directory(l: LuaState) -> i32 {
5255
0
5356
}
5457

55-
extern "C" fn get_level(l: LuaState) -> i32 {
58+
#[lua_function]
59+
fn get_level(l: LuaState) -> i32 {
5660
match get_iface() {
5761
Ok(iface) => {
5862
let level = iface.GetLevelName();
@@ -66,7 +70,8 @@ extern "C" fn get_level(l: LuaState) -> i32 {
6670
0
6771
}
6872

69-
extern "C" fn is_recording(l: LuaState) -> i32 {
73+
#[lua_function]
74+
fn is_recording(l: LuaState) -> i32 {
7075
match get_iface() {
7176
Ok(iface) => {
7277
let demo = iface.IsRecordingDemo();
@@ -80,7 +85,8 @@ extern "C" fn is_recording(l: LuaState) -> i32 {
8085
0
8186
}
8287

83-
extern "C" fn is_paused(l: LuaState) -> i32 {
88+
#[lua_function]
89+
fn is_paused(l: LuaState) -> i32 {
8490
match get_iface() {
8591
Ok(iface) => {
8692
let paused = iface.IsPaused();
@@ -94,8 +100,8 @@ extern "C" fn is_paused(l: LuaState) -> i32 {
94100
0
95101
}
96102

97-
#[no_mangle]
98-
extern "C" fn gmod13_open(l: LuaState) -> i32 {
103+
#[gmod_open]
104+
fn open(l: LuaState) -> i32 {
99105
printgm!(l, "Loaded engine module!");
100106

101107
let lib = reg! [
@@ -111,7 +117,7 @@ extern "C" fn gmod13_open(l: LuaState) -> i32 {
111117
0
112118
}
113119

114-
#[no_mangle]
115-
extern "C" fn gmod13_close(_: LuaState) -> i32 {
120+
#[gmod_close]
121+
fn close(_l: LuaState) -> i32 {
116122
0
117123
}

examples/is_even/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "gmod_is_even"
33
description = "Binary module that exposes a function called 'is_even' that does what it says."
4-
version = "0.1.0"
4+
version = "0.2.0"
55
edition = "2021"
66
publish = false
77

examples/is_even/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ extern "C" fn is_odd(l: LuaState) -> i32 {
1919
1
2020
}
2121

22-
#[no_mangle]
23-
extern "C" fn gmod13_open(l: LuaState) -> i32 {
22+
#[gmod_open]
23+
fn open(l: LuaState) -> i32 {
2424
// Print to the gmod console
2525
printgm!(l, "Loaded is_even module!");
2626

@@ -36,8 +36,8 @@ extern "C" fn gmod13_open(l: LuaState) -> i32 {
3636
1
3737
}
3838

39-
#[no_mangle]
40-
extern "C" fn gmod13_close(l: LuaState) -> i32 {
39+
#[gmod_close]
40+
fn close(l: LuaState) -> i32 {
4141
printgm!(l, "Goodbye garrysmod!");
4242
0
4343
}

rglua-macros/Cargo.toml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
[package]
2+
name = "rglua-macros"
3+
description = "Procedural macros to be used with rglua"
4+
version = "0.1.0"
5+
authors = ["Vurv <vurvdevelops@gmail.com>"]
6+
keywords = ["glua", "garrysmod", "lua", "gmod"]
7+
categories = ["api-bindings", "external-ffi-bindings", "development-tools::ffi", "game-development", "accessibility"]
8+
readme = "README.md"
9+
license = "MIT"
10+
edition = "2021"
11+
repository = "https://github.com/Vurv78/rglua"
12+
13+
[lib]
14+
proc-macro = true
15+
16+
[[test]]
17+
name = "tests"
18+
path = "tests/main.rs"
19+
20+
[dependencies]
21+
proc-macro2 = "1.0.34"
22+
quote = "1.0.10"
23+
syn = { version = "1.0.82", features = ["full"] }
24+
25+
[dev-dependencies]
26+
trybuild = { version = "1.0.49", features = ["diff"] }
27+
rglua = { path = "../rglua" }

rglua-macros/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# 🌑 ``rglua-macros``
2+
> Proc-macros for use with rglua

0 commit comments

Comments
 (0)