├── .gitignore ├── Cargo.lock ├── Cargo.toml ├── README.md ├── rust-toolchain.toml └── src └── lib.rs /.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | -------------------------------------------------------------------------------- /Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | version = 3 4 | 5 | [[package]] 6 | name = "cfg-if" 7 | version = "1.0.0" 8 | source = "registry+https://github.com/rust-lang/crates.io-index" 9 | checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" 10 | 11 | [[package]] 12 | name = "cstr" 13 | version = "0.2.9" 14 | source = "registry+https://github.com/rust-lang/crates.io-index" 15 | checksum = "f2846d3636dcaff720d311ea8983f5fa7a8288632b2f95145dd4b5819c397fd8" 16 | dependencies = [ 17 | "proc-macro2", 18 | "quote", 19 | ] 20 | 21 | [[package]] 22 | name = "gmod" 23 | version = "11.0.1" 24 | source = "registry+https://github.com/rust-lang/crates.io-index" 25 | checksum = "b4025ff9f746f57aff401d0a51ef45628f01546ff7b78e75206da9d43e9ffe60" 26 | dependencies = [ 27 | "cstr", 28 | "gmod-macros", 29 | "lazy_static", 30 | "libloading", 31 | ] 32 | 33 | [[package]] 34 | name = "gmod-macros" 35 | version = "1.0.3" 36 | source = "registry+https://github.com/rust-lang/crates.io-index" 37 | checksum = "9b98edb384e385384868fbede7d68accdf31654009fa23ed4abfa1dc5860e148" 38 | dependencies = [ 39 | "proc-macro2", 40 | "quote", 41 | "syn", 42 | ] 43 | 44 | [[package]] 45 | name = "gmod-module-base-rs" 46 | version = "0.1.0" 47 | dependencies = [ 48 | "gmod", 49 | ] 50 | 51 | [[package]] 52 | name = "lazy_static" 53 | version = "1.4.0" 54 | source = "registry+https://github.com/rust-lang/crates.io-index" 55 | checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" 56 | 57 | [[package]] 58 | name = "libloading" 59 | version = "0.7.2" 60 | source = "registry+https://github.com/rust-lang/crates.io-index" 61 | checksum = "afe203d669ec979b7128619bae5a63b7b42e9203c1b29146079ee05e2f604b52" 62 | dependencies = [ 63 | "cfg-if", 64 | "winapi", 65 | ] 66 | 67 | [[package]] 68 | name = "proc-macro2" 69 | version = "1.0.36" 70 | source = "registry+https://github.com/rust-lang/crates.io-index" 71 | checksum = "c7342d5883fbccae1cc37a2353b09c87c9b0f3afd73f5fb9bba687a1f733b029" 72 | dependencies = [ 73 | "unicode-xid", 74 | ] 75 | 76 | [[package]] 77 | name = "quote" 78 | version = "1.0.14" 79 | source = "registry+https://github.com/rust-lang/crates.io-index" 80 | checksum = "47aa80447ce4daf1717500037052af176af5d38cc3e571d9ec1c7353fc10c87d" 81 | dependencies = [ 82 | "proc-macro2", 83 | ] 84 | 85 | [[package]] 86 | name = "syn" 87 | version = "1.0.84" 88 | source = "registry+https://github.com/rust-lang/crates.io-index" 89 | checksum = "ecb2e6da8ee5eb9a61068762a32fa9619cc591ceb055b3687f4cd4051ec2e06b" 90 | dependencies = [ 91 | "proc-macro2", 92 | "quote", 93 | "unicode-xid", 94 | ] 95 | 96 | [[package]] 97 | name = "unicode-xid" 98 | version = "0.2.2" 99 | source = "registry+https://github.com/rust-lang/crates.io-index" 100 | checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3" 101 | 102 | [[package]] 103 | name = "winapi" 104 | version = "0.3.9" 105 | source = "registry+https://github.com/rust-lang/crates.io-index" 106 | checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" 107 | dependencies = [ 108 | "winapi-i686-pc-windows-gnu", 109 | "winapi-x86_64-pc-windows-gnu", 110 | ] 111 | 112 | [[package]] 113 | name = "winapi-i686-pc-windows-gnu" 114 | version = "0.4.0" 115 | source = "registry+https://github.com/rust-lang/crates.io-index" 116 | checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" 117 | 118 | [[package]] 119 | name = "winapi-x86_64-pc-windows-gnu" 120 | version = "0.4.0" 121 | source = "registry+https://github.com/rust-lang/crates.io-index" 122 | checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" 123 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "gmod-module-base-rs" 3 | authors = ["Your name here! "] 4 | version = "0.1.0" 5 | edition = "2021" 6 | 7 | [lib] 8 | crate-type = ["cdylib"] 9 | 10 | [dependencies] 11 | gmod = { version = "*", default-features = false, features = ["gmcl"] } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # gmod-module-base-rs 2 | 3 | A base for developing Garry's Mod binary modules in Rust. 4 | 5 | # Getting Started 6 | 7 | 1. [Install Rust](https://www.rust-lang.org/tools/install) 8 | 2. [Download](https://github.com/WilliamVenner/gmod-module-base-rs/archive/refs/heads/master.zip) or `git clone` this repository 9 | 3. Open the cloned repository in a command prompt or terminal 10 | 4. Type `cargo build` 11 | 12 | Your built module can be found in `target/debug`! 13 | 14 | ### Linux Note 15 | 16 | When building a Linux module, you'll find it has the extension `.so`, you can simply change it to `.dll` and it will still work fine in Garry's Mod. 17 | 18 | # What next? 19 | 20 | * Read the [`gmod` crate documentation](https://docs.rs/gmod/latest/gmod/) 21 | * Read the [Rust book](https://doc.rust-lang.org/book/) 22 | * Build in [release mode](https://doc.rust-lang.org/book/ch14-01-release-profiles.html)! -------------------------------------------------------------------------------- /rust-toolchain.toml: -------------------------------------------------------------------------------- 1 | [toolchain] 2 | channel = "nightly" -------------------------------------------------------------------------------- /src/lib.rs: -------------------------------------------------------------------------------- 1 | #![feature(c_unwind)] 2 | 3 | #[macro_use] extern crate gmod; 4 | 5 | #[lua_function] 6 | unsafe fn hello_world(lua: gmod::lua::State) -> i32 { 7 | // lua_run hello_world() 8 | 9 | lua.get_global(lua_string!("print")); 10 | lua.push_string("Hello, world!"); 11 | lua.call(1, 0); 12 | return 0; 13 | } 14 | 15 | #[gmod13_open] 16 | unsafe fn gmod13_open(lua: gmod::lua::State) -> i32 { 17 | println!("My {} module version {} has loaded!", env!("CARGO_PKG_NAME"), env!("CARGO_PKG_VERSION")); 18 | 19 | lua.push_function(hello_world); 20 | lua.set_global(lua_string!("hello_world")); 21 | 22 | return 0; 23 | } 24 | 25 | #[gmod13_close] 26 | unsafe fn gmod13_close(lua: gmod::lua::State) -> i32 { 27 | println!("My {} module version {} has unloaded!", env!("CARGO_PKG_NAME"), env!("CARGO_PKG_VERSION")); 28 | return 0; 29 | } --------------------------------------------------------------------------------