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

Commit f51fa1d

Browse files
committed
2.0.0-beta
Full changelist will be in 2.0.0. Essentially a lot of breaking changes, added Userdata support for Vector and Angle, some missing lua c api functions, and a lot of documentation.
1 parent 8fae2a0 commit f51fa1d

File tree

23 files changed

+1066
-217
lines changed

23 files changed

+1066
-217
lines changed

README.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
11
# 🌑 ``rglua`` [![cratesio](https://img.shields.io/crates/v/rglua.svg)](https://crates.io/crates/rglua) ![Build Status](https://github.com/Vurv78/rglua/actions/workflows/ci.yml/badge.svg) [![License](https://img.shields.io/github/license/Vurv78/rglua?color=red)](https://opensource.org/licenses/Apache-2.0) [![github/Vurv78](https://img.shields.io/discord/824727565948157963?label=Discord&logo=discord&logoColor=ffffff&labelColor=7289DA&color=2c2f33)](https://discord.gg/epJFC6cNsw)
22

3-
This is a crate that allows interop with the luajit c api as well as the source sdk through libloading and vtable bindings.
3+
This is a crate that allows interop with the (g)luajit c api as well as the source sdk through libloading and vtable bindings.
44
You can then use these for binary modules or manually injected code, like with [Autorun-rs](https://github.com/Vurv78/Autorun-rs)
55

66
More information on binary modules can be found on the garrysmod wiki: [Creating Binary Modules](https://wiki.facepunch.com/gmod/Creating_Binary_Modules) and examples [can be found here.](https://github.com/Vurv78/rglua/tree/master/examples)
77
## Usage
88
If you are targeting 32 bit make sure to install the toolchain and build to it:
99
```bash
1010
rustup target add i686-pc-windows-msvc
11-
cargo build --release --target=i686-pc-windows-msvc
11+
cargo build --target=i686-pc-windows-msvc
1212
```
13-
## Acknowledgements
14-
### [garrysmod_common](https://github.com/danielga/garrysmod_common)
15-
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.
1613

1714
## Comparison
1815
There are actually a decent amount of libraries out there for gmod development.
@@ -34,6 +31,10 @@ Here's a comparison and why you could use this one.
3431
| Real world examples | ✔️ || ✔️ ||
3532
| Github Stars | 😢 | 👍 | 👑 | 🤷‍♂️ |
3633

34+
__*You can help with that last one 😉*__
35+
3736
\* They technically do, but they depend on autogenerated bindings which is inaccurate for gmod, leading to missing functions. (See lua_resume_real)
3837

39-
__*You can help with that last one 😉*__
38+
## Acknowledgements
39+
### [garrysmod_common](https://github.com/danielga/garrysmod_common)
40+
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.

examples/is_even/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
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.2.0"
4+
version = "0.3.0"
55
edition = "2021"
66
publish = false
77

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

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

examples/is_even/src/lib.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
use rglua::prelude::*;
22

33
// The functions we want to provide to lua
4-
extern "C" fn is_even(l: LuaState) -> i32 {
4+
#[lua_function]
5+
fn is_even(l: LuaState) -> i32 {
56
let num = luaL_checkinteger(l, 1);
67
// Ask for the first argument of the function.
78
// If this is the wrong type or missing, an error will be thrown to lua (if you don't want this, use the lua_to* functions)
@@ -12,13 +13,16 @@ extern "C" fn is_even(l: LuaState) -> i32 {
1213
1
1314
}
1415

15-
extern "C" fn is_odd(l: LuaState) -> i32 {
16+
#[lua_function]
17+
fn is_odd(l: LuaState) -> i32 {
1618
let num = luaL_checkinteger(l, 1);
1719

1820
lua_pushboolean(l, (num % 2 != 0) as i32);
1921
1
2022
}
2123

24+
// Note that since this is #[gmod_open] the name of the function does not matter
25+
// This is the same for #[gmod_close]
2226
#[gmod_open]
2327
fn open(l: LuaState) -> i32 {
2428
// Print to the gmod console
@@ -31,7 +35,7 @@ fn open(l: LuaState) -> i32 {
3135
];
3236

3337
// Register our functions in ``_G.math``
34-
// This WILL NOT overwrite _G.math if it already exists ()
38+
// This WILL NOT overwrite _G.math if it already exists (which it should..)
3539
luaL_register(l, cstr!("math"), lib.as_ptr());
3640
1
3741
}

examples/vector/Cargo.toml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[package]
2+
name = "vector"
3+
description = "Binary module that adds some extra functions to the gmod Vector type"
4+
version = "0.1.0"
5+
edition = "2021"
6+
publish = false
7+
8+
[lib]
9+
crate-type = ["cdylib"]
10+
11+
[dependencies]
12+
rglua = { path = "../../rglua" }

examples/vector/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# 🔢 ``vector``
2+
Binary module that adds some extra functions to the ``Vector`` type.
3+
4+
## Vector:IsPositive()
5+
Returns if the vector consists of positive numbers
6+
7+
## Vector:GetPow(n: number)
8+
Returns the vector multiplied by itself n times (exp ^)

examples/vector/src/lib.rs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
use rglua::prelude::*;
2+
3+
#[lua_function]
4+
fn is_positive(l: LuaState) -> i32 {
5+
let vec = luaL_checkvector(l, 1);
6+
lua_pushboolean(l, (vec.x > 0.0 && vec.y > 0.0 && vec.z > 0.0) as i32);
7+
1
8+
}
9+
10+
#[lua_function]
11+
fn get_pow(l: LuaState) -> i32 {
12+
let vec = luaL_checkvector(l, 1);
13+
let by = luaL_checknumber(l, 2) as f32;
14+
15+
lua_pushvector(l, Vector::new(vec.x.powf(by), vec.y.powf(by), vec.z.powf(by)));
16+
1
17+
}
18+
19+
// Note that since this is #[gmod_open] the name of the function does not matter
20+
// This is the same for #[gmod_close]
21+
#[gmod_open]
22+
fn open(l: LuaState) -> i32 {
23+
// Create a library consisting of functions to export to gmod.
24+
let lib = reg! [
25+
"IsPositive" => is_positive,
26+
"GetPow" => get_pow
27+
];
28+
29+
// Get the ``Vector`` metatable from the lua registry and put it onto the stack.
30+
luaL_getmetatable(l, cstr!("Vector"));
31+
32+
// Give a null pointer as the libname so that luaL_register knows we are trying to instead add these functions to the value on top of the stack;
33+
// This being the Vector metatable at (-1).
34+
luaL_register(l, std::ptr::null(), lib.as_ptr());
35+
36+
// Return nothing (0 objects)
37+
0
38+
}
39+
40+
#[gmod_close]
41+
fn close(l: LuaState) -> i32 {
42+
printgm!(l, "Goodbye garrysmod!");
43+
0
44+
}

rglua/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "rglua"
33
description = "Toolkit for garrysmod development with the source sdk and luajit api"
4-
version = "1.0.0"
4+
version = "2.0.0-beta"
55
authors = ["Vurv <vurvdevelops@gmail.com>"]
66
keywords = ["glua", "garrysmod", "lua", "gmod"]
77
categories = ["api-bindings", "external-ffi-bindings", "development-tools::ffi", "game-development", "accessibility"]

rglua/src/interface/common.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use super::prelude::*;
2+
13
#[repr(C)]
24
#[allow(non_snake_case)]
35
pub struct PlayerInfo {
@@ -18,3 +20,27 @@ pub struct PlayerInfo {
1820
filesDownloaded: u8,
1921
pad: [i8; 304],
2022
}
23+
24+
#[repr(C)]
25+
pub struct StudioHdr {
26+
pub id: c_int,
27+
pub version: c_int,
28+
pub checksum: c_int,
29+
30+
pub name: [c_char; 64],
31+
pub length: c_int,
32+
33+
pub eyeposition: Vector,
34+
pub illumposition: Vector,
35+
pub hull_min: Vector,
36+
pub hull_max: Vector,
37+
pub view_bbmin: Vector,
38+
pub view_bbmax: Vector,
39+
pub flags: c_int,
40+
pub numbones: c_int,
41+
pub boneindex: c_int,
42+
pub numbonecontrollers: c_int,
43+
pub bonecontrollerindex: c_int,
44+
pub numhitboxsets: c_int,
45+
pub hitboxsetindex: c_int,
46+
}

rglua/src/interface/cvar.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ pub struct ConCommandBase {
1111
}
1212

1313
iface! {
14-
/// VEngineCvar007
15-
/// vstdlib.dll
14+
#[version("VEngineCvar007")]
15+
#[file("vstdlib.dll")]
1616
pub abstract struct ICVar {};
1717
}
1818

rglua/src/interface/engine.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ use super::prelude::*;
44
use std::os::raw::c_char;
55

66
iface! {
7-
/// VEngineClient015
8-
/// Offsets are confirmed correct as of 12/19/2021
7+
#[version("VEngineClient015")]
8+
#[file("engine.dll")]
99
pub abstract struct EngineClient {};
1010
}
1111

0 commit comments

Comments
 (0)