This repository was archived by the owner on Nov 12, 2025. It is now read-only.
File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ ## `` interfaces ``
2+ Generic binary module to display usage of a few source interfaces.
3+
4+ ## interfaces.reloadTextures()
5+ Reloads gmod's texture system
Original file line number Diff line number Diff line change 11use rglua:: prelude:: * ;
2- use rglua:: interface:: { self , LuaShared } ;
2+ use rglua:: interface;
33
4- #[ derive ( Debug , thiserror :: Error ) ]
5- enum GenericError {
6- # [ error ( "Couldn't get interface {0}" ) ]
7- NoInterface ( String ) ,
4+ #[ lua_function ]
5+ fn reload_textures ( _l : LuaState ) -> Result < i32 , interface :: Error > {
6+ let matsys = iface ! ( MaterialSystem ) ? ;
7+ matsys . ReloadTextures ( ) ;
88
9- #[ error( "Couldn't get interface as reference {0}" ) ]
10- AsMut ( String )
9+ Ok ( 0 )
1110}
1211
1312#[ gmod_open]
14- fn open ( l : LuaState ) -> Result < i32 , GenericError > {
13+ fn open ( l : LuaState ) -> Result < i32 , interface :: Error > {
1514 // Access the lua state when you aren't directly given it.
1615 let lua_shared = iface ! ( LuaShared ) ?;
17- let menu = unsafe { lua_shared. GetLuaInterface ( 2 ) . as_mut ( ) }
16+
17+ // 0 to get client state. this will error if you try and run the binary module on the server or menu realms.
18+ let client = unsafe { lua_shared. GetLuaInterface ( 0 ) . as_mut ( ) }
1819 . ok_or ( interface:: Error :: AsMut ) ?;
1920
20- printgm ! ( menu. base as _, "Hello from ILuaShared!" ) ;
21+ printgm ! ( client. base as _, "Hello from ILuaShared!" ) ;
22+
23+ let lib = reg ! [
24+ "reloadTextures" => reload_textures
25+ ] ;
26+
27+ luaL_register ( l, cstr ! ( "interfaces" ) , lib. as_ptr ( ) ) ;
28+
2129 Ok ( 0 )
2230}
2331
Original file line number Diff line number Diff line change @@ -32,7 +32,7 @@ pub type MaterialHandle = c_ushort;
3232/// "materialsystem.dll"
3333#[ vtable]
3434pub struct MaterialSystem {
35- #[ offset( 70 ) ]
35+ #[ offset( 72 ) ]
3636 pub ReloadTextures : extern "C" fn ( ) ,
3737 pub ReloadMaterials : extern "C" fn ( pSubString : * const c_char ) ,
3838
@@ -45,7 +45,7 @@ pub struct MaterialSystem {
4545 complain_prefix : * const c_char
4646 ) -> * mut c_void ,
4747
48- #[ offset( 75 ) ]
48+ #[ offset( 77 ) ]
4949 pub FirstMaterial : extern "C" fn ( ) -> MaterialHandle ,
5050 pub NextMaterial : extern "C" fn ( handle : MaterialHandle ) -> MaterialHandle ,
5151 pub InvalidMaterial : extern "C" fn ( ) -> MaterialHandle ,
You can’t perform that action at this time.
0 commit comments