|
1 | | -# rglua [](https://crates.io/crates/rglua)  [](https://opensource.org/licenses/Apache-2.0) [](https://discord.gg/epJFC6cNsw) |
| 1 | +# 🌑 ``rglua`` [](https://crates.io/crates/rglua)  [](https://opensource.org/licenses/Apache-2.0) [](https://discord.gg/epJFC6cNsw) |
2 | 2 |
|
3 | 3 | This is a crate that contains bindings for using the lua c api in garrysmod through bindings using the rust libloading library. |
4 | 4 | Can be used for either binary modules or just manual injections into gmod, like with [Autorun-rs](https://github.com/Vurv78/Autorun-rs) |
5 | 5 |
|
6 | 6 | This works by finding a ``lua_shared.dll`` file relative to the currently running program, so you need to make sure your file is either in ``GarrysMod/bin/`` or ``GarrysMod/garrysmod/bin`` for srcds servers. The library will panic if the file is not found. |
7 | 7 |
|
8 | | -More information on binary modules can be found on the garrysmod wiki: [Creating Binary Modules](https://wiki.facepunch.com/gmod/Creating_Binary_Modules) and an example can be found at the bottom of this file. |
9 | | - |
| 8 | +More information on binary modules can be found on the garrysmod wiki: [Creating Binary Modules](https://wiki.facepunch.com/gmod/Creating_Binary_Modules) and an example [can be found here.](https://github.com/Vurv78/rglua/tree/master/examples/is_even) |
10 | 9 | ## Usage |
11 | | - |
12 | | -Add this to your ``Cargo.toml`` file |
13 | | -```toml |
14 | | -[lib] |
15 | | -crate-type = ["cdylib"] # This tells rust we want to create a .dll file that links to C code. |
16 | | - |
17 | | -[dependencies] |
18 | | -rglua = "0.7.0" |
19 | | -``` |
20 | | - |
21 | | -## Building |
22 | | -After [installing rust](https://www.rust-lang.org/tools/install), just run ``cargo build --release``. |
23 | | - |
24 | 10 | If you are targeting 32 bit make sure to install the toolchain and build to it: |
25 | 11 | ```bash |
26 | 12 | rustup target add i686-pc-windows-msvc |
27 | 13 | cargo build --release --target=i686-pc-windows-msvc |
28 | 14 | ``` |
29 | | - |
30 | | -## Notes |
31 | | -* This will most likely not work on other platforms and I am not able to vouch/test them. |
32 | | -* The nature of this crate is super unsafe and sort of defeats the purpose of rust's safety because of the interfacing you require to unsafe C code and the nature of linking to them. |
33 | | - |
34 | | -## Example Module |
35 | | -Find another larger example at examples/is_even |
36 | | -```rust |
37 | | -use rglua::prelude::*; |
38 | | - |
39 | | -#[no_mangle] |
40 | | -pub extern fn gmod13_open(state: LuaState) -> i32 { |
41 | | - lua_getglobal(state, cstr!("print")); |
42 | | - lua_pushstring(state, cstr!("Hello from rust!")); // Print to the in-game console |
43 | | - lua_call(state, 1, 0); |
44 | | - |
45 | | - // or |
46 | | - printgm!(state, "Hello world!"); |
47 | | - 0 |
48 | | -} |
49 | | - |
50 | | -#[no_mangle] |
51 | | -pub extern fn gmod13_close(_state: LuaState) -> i32 { |
52 | | - 0 |
53 | | -} |
54 | | -``` |
55 | | - |
56 | 15 | ## Acknowledgements |
57 | 16 | ### [garrysmod_common](https://github.com/danielga/garrysmod_common) |
58 | 17 | 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. |
0 commit comments