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

Commit d9967fb

Browse files
committed
3.0.0-beta2
Add more bindings, make use of new viable #[skip] option, remove derive_more as a dependency (bloat)
1 parent ea39387 commit d9967fb

File tree

15 files changed

+346
-109
lines changed

15 files changed

+346
-109
lines changed

examples/interfaces/src/lib.rs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use rglua::prelude::*;
2-
use rglua::interface;
2+
use rglua::interface::{self, NetChannel, CNetChan};
33

44
#[lua_function]
55
fn reload_textures(_l: LuaState) -> Result<i32, interface::Error> {
@@ -9,6 +9,22 @@ fn reload_textures(_l: LuaState) -> Result<i32, interface::Error> {
99
Ok(0)
1010
}
1111

12+
#[lua_function]
13+
fn disconnect(l: LuaState) -> Result<i32, interface::Error> {
14+
let msg = luaL_checkstring(l, 1);
15+
let engine = iface!(EngineClient)?;
16+
17+
let chan = engine.GetNetChannelInfo() as *mut CNetChan;
18+
let chan = unsafe { chan.as_mut() }
19+
.ok_or(interface::Error::AsMut)?;
20+
21+
printgm!(l, "{:?}", try_rstr!(chan.GetAddress()));
22+
23+
chan.Clear();
24+
chan.Shutdown(msg);
25+
return Ok(0);
26+
}
27+
1228
#[gmod_open]
1329
fn open(l: LuaState) -> Result<i32, interface::Error> {
1430
// Access the lua state when you aren't directly given it.
@@ -21,7 +37,8 @@ fn open(l: LuaState) -> Result<i32, interface::Error> {
2137
printgm!(client.base as _, "Hello from ILuaShared!");
2238

2339
let lib = reg! [
24-
"reloadTextures" => reload_textures
40+
"reloadTextures" => reload_textures,
41+
"disconnect" => disconnect
2542
];
2643

2744
luaL_register(l, cstr!("interfaces"), lib.as_ptr());

rglua/Cargo.toml

Lines changed: 4 additions & 7 deletions
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 = "3.0.0-beta"
4+
version = "3.0.0-beta2"
55
authors = ["Vurv <[email protected]>"]
66
keywords = ["glua", "garrysmod", "lua", "gmod"]
77
categories = ["api-bindings", "external-ffi-bindings", "development-tools::ffi", "game-development", "accessibility"]
@@ -18,12 +18,9 @@ once_cell = "1.8.0"
1818
thiserror = "1.0.30"
1919

2020
rglua-macros = { version = "0.2.0", path = "../rglua-macros" }
21-
derive_more = { version = "0.99.17", optional = true }
2221

23-
viable = { version = "0.1", optional = true }
22+
viable = { version = "0.2", optional = true }
2423

2524
[features]
26-
default = ["interfaces", "userdata"]
27-
28-
interfaces = ["viable"]
29-
userdata = ["derive_more"]
25+
default = ["interfaces"]
26+
interfaces = ["viable"]

rglua/src/interface/client/mod.rs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
use super::{prelude::*, net::{NetChannelHandler, NetChannel, NetMessage}};
2+
#[vtable]
3+
/// Client retrieved from Server interface.
4+
pub struct Client {
5+
base: *mut *mut NetChannelHandler,
6+
7+
#[skip(1)] // Skip destructor
8+
Connect: extern "C" fn(name: *const c_char, userid: c_int, chan: *mut NetChannel, fakeply: bool, challenge: c_int) -> bool,
9+
Inactivate: extern "C" fn(),
10+
Reconnect: extern "C" fn(),
11+
12+
// Variadics don't work so..
13+
Disconnect: extern "C" fn(reason: *const c_char, ...),
14+
GetPlayerSlot: extern "C" fn() -> c_int,
15+
GetUserID: extern "C" fn() -> c_int,
16+
// GetNetworkID: extern "C" fn() -> UserID,
17+
18+
#[skip(1)]
19+
GetClientName: extern "C" fn() -> *const c_char,
20+
GetNetChannel: extern "C" fn() -> *mut NetChannel,
21+
// GetServer: extern "C" fn() -> *mut Server,
22+
23+
#[skip(1)]
24+
GetUserSetting: extern "C" fn(cvar: *const c_char) -> *const c_char,
25+
GetNetworkIDString: extern "C" fn() -> *const c_char,
26+
27+
SetRate: extern "C" fn(rate: c_int, force: bool),
28+
GetRate: extern "C" fn() -> c_int,
29+
30+
SetUpdateRate: extern "C" fn(rate: c_int, force: bool),
31+
GetUpdateRate: extern "C" fn() -> c_int,
32+
33+
Clear: extern "C" fn(),
34+
GetMaxAckTickCount: extern "C" fn() -> c_int,
35+
ExecuteStringCommand: extern "C" fn(command: *const c_char) -> bool,
36+
SendNetMsg: extern "C" fn(msg: &mut NetMessage, force_reliable: bool),
37+
ClientPrint: extern "C" fn(msg: *const c_char, ...),
38+
IsConnected: extern "C" fn() -> bool,
39+
IsSpawned: extern "C" fn() -> bool,
40+
IsActive: extern "C" fn() -> bool,
41+
IsFakeClient: extern "C" fn() -> bool,
42+
IsHLTV: extern "C" fn() -> bool,
43+
44+
// IsReplay ?
45+
46+
IsHearingClient: extern "C" fn(id: c_int) -> bool,
47+
IsProximityHearingClient: extern "C" fn(id: c_int) -> bool,
48+
SetMaxRoutablePayloadSize: extern "C" fn(size: c_int),
49+
}

rglua/src/interface/common.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,3 +175,10 @@ impl ButtonCode {
175175
pub const KeyLAST: Self = Self::KeySCROLLLOCKTOGGLE;
176176
pub const KeyCOUNT: i32 = (Self::KeyLAST as i32 - Self::KeyFIRST as i32 + 1);
177177
}
178+
179+
#[repr(C)]
180+
pub enum SkyboxVisibility {
181+
NotVisible,
182+
Visible3D,
183+
Visible2D
184+
}

rglua/src/interface/engine/client.rs

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use crate::interface::common::SkyboxVisibility;
12
use crate::interface::{MaterialSystem, NetChannelInfo};
23

34
use super::common::ButtonCode;
@@ -33,10 +34,10 @@ pub struct ClientTextMessage {
3334
#[vtable]
3435
pub struct EngineClient {
3536
#[offset(1)]
36-
#[cfg(feature = "userdata")]
37+
3738
pub GetLightForPoint: extern "C" fn(pos: &Vector, bClamp: bool) -> Vector,
3839

39-
#[cfg(feature = "userdata")]
40+
4041
pub TraceLineMaterialAndLighting: extern "C" fn(
4142
start: &Vector,
4243
end: &Vector,
@@ -114,35 +115,47 @@ pub struct EngineClient {
114115
pub SaveAllocMemory: extern "C" fn(num: usize, size: usize) -> *mut c_void,
115116
pub SaveFreeMemory: extern "C" fn(pSaveMem: *mut c_void),
116117

117-
#[offset(72)]
118+
#[check(72)]
118119
pub GetNetChannelInfo: extern "C" fn() -> *mut NetChannelInfo,
119-
120-
#[offset(76)]
120+
#[skip(1)]
121+
pub CheckPoint: extern "C" fn(pname: *const c_char),
122+
pub DrawPortals: extern "C" fn(),
123+
#[check(76)]
121124
pub IsPlayingDemo: extern "C" fn() -> bool,
122125
pub IsRecordingDemo: extern "C" fn() -> bool,
123-
124-
#[offset(84)]
126+
pub IsPlayingTimeDemo: extern "C" fn() -> bool,
127+
pub GetDemoRecordingTick: extern "C" fn() -> c_int,
128+
pub GetDemoPlaybackTick: extern "C" fn() -> c_int,
129+
pub GetDemoPlaybackStartTick: extern "C" fn() -> c_int,
130+
pub GetDemoPlaybackTimeScale: extern "C" fn() -> c_float,
131+
pub GetDemoPlaybackTotalTicks: extern "C" fn() -> c_int,
132+
#[check(84)]
125133
pub IsPaused: extern "C" fn() -> bool,
126134
pub IsTakingScreenshot: extern "C" fn() -> bool,
127135
pub IsHLTV: extern "C" fn() -> bool,
128136
pub IsLevelMainMenuBackground: extern "C" fn() -> bool,
129137
pub GetMainMenuBackgroundName: extern "C" fn(dest: *mut c_char, destlen: c_int),
130138

131-
#[offset(91)]
139+
#[skip(2)]
140+
#[check(91)]
132141
pub GetUILanguage: extern "C" fn(dest: *mut c_char, destlen: c_int),
133-
134-
#[offset(94)]
142+
pub IsSkyboxVisibleFromPoint: extern "C" fn(vecPoint: &Vector) -> SkyboxVisibility,
143+
pub GetMapEntitiesString: extern "C" fn() -> *const c_char,
135144
pub IsInEditMode: extern "C" fn() -> bool,
136145
pub GetScreenAspectRatio: extern "C" fn() -> c_float,
137146

138-
#[offset(101)]
147+
#[skip(2)]
148+
pub GetEngineBuildNumber: extern "C" fn() -> c_uint,
149+
pub GetProductVersionString: extern "C" fn() -> *const c_char,
150+
pub GrabPreColorCorrectedFrame: extern "C" fn(x: c_int, y: c_int, width: c_int, height: c_int),
151+
#[check(101)]
139152
pub IsHammerRunning: extern "C" fn() -> bool,
140153
/// This is NOT checked against the FCVAR_CLIENTCMD_CAN_EXECUTE vars
141154
pub ExecuteClientCmd: extern "C" fn(cmd: *const c_char),
142155
pub MapHasHDRLighting: extern "C" fn() -> bool,
143156
pub GetAppID: extern "C" fn() -> c_int,
144157

145-
#[cfg(feature = "userdata")]
158+
146159
pub GetLightForPointFast: extern "C" fn(pos: &Vector, bClamp: bool) -> Vector,
147160

148161
#[offset(106)]

rglua/src/interface/lua/shared.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use super::prelude::*;
44
/// This doesn't work on x86. =(
55
#[vtable]
66
pub struct LuaShared {
7-
#[offset(2)] // 2
7+
#[skip(2)] // ~LuaShared, Init
88
pub Shutdown: extern "C" fn(),
99
pub DumpStats: extern "C" fn(),
1010
pub CreateLuaInterface: extern "C" fn(realm: c_uchar, b: bool) -> *mut LuaInterface,
@@ -14,10 +14,14 @@ pub struct LuaShared {
1414
/// 1 - Server
1515
/// 2 - Menu
1616
pub GetLuaInterface: extern "C" fn(realm: c_uchar) -> *mut LuaInterface,
17-
18-
#[offset(9)]
17+
#[skip(2)] // LoadFile, GetCache
1918
pub MountLua: extern "C" fn(l: *const c_char),
2019
pub MountLuaAdd: extern "C" fn(l: *const c_char, l2: *const c_char),
2120
pub UnMountLua: extern "C" fn(l: *const c_char),
22-
pub SetFileContents: extern "C" fn(l: *const c_char, c: *const c_char)
21+
pub SetFileContents: extern "C" fn(l: *const c_char, c: *const c_char),
22+
pub SetLuaFindHook: extern "C" fn(p: *mut c_void),
23+
#[skip(1)] // FindScripts
24+
pub GetStackTraces: extern "C" fn() -> *const c_char,
25+
#[skip(1)] // InvalidateCache
26+
pub EmptyCache: extern "C" fn(),
2327
}

rglua/src/interface/materials.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ pub struct Material {
1212
pub IsAlphaTested: extern "C" fn() -> bool,
1313
pub IsVertexLit: extern "C" fn() -> bool,
1414

15-
#[cfg(feature = "userdata")]
15+
1616
#[offset(31)]
1717
pub GetReflectivity: extern "C" fn(reflect: &mut Vector),
1818

rglua/src/interface/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ pub(crate) mod prelude {
77
pub(crate) use std::os::raw::{
88
c_char, c_double, c_float, c_int, c_long, c_uchar, c_uint, c_ushort, c_void
99
};
10-
11-
#[cfg(feature = "userdata")]
1210
pub(crate) use crate::userdata::Vector;
1311
}
1412

@@ -20,14 +18,16 @@ mod materials;
2018
mod mdl;
2119
mod net;
2220
mod panel;
21+
mod client;
2322

2423
pub use cvar::{CVar, ConVar};
2524
pub use engine::{EngineClient, EngineServer};
2625
pub use lua::{LuaInterface, LuaObject, LuaShared};
2726
pub use materials::MaterialSystem;
2827
pub use mdl::{MdlCache, MdlCacheNotify};
29-
pub use net::NetChannelInfo;
28+
pub use net::{NetChannelInfo, NetChannel, NetChannelHandler, NetMessage, CNetChan};
3029
pub use panel::Panel;
30+
pub use client::Client;
3131

3232
use crate::try_cstr;
3333
use libloading::{Library, Symbol};

rglua/src/interface/net.rs

Lines changed: 0 additions & 61 deletions
This file was deleted.

0 commit comments

Comments
 (0)