|
| 1 | +# ⚠️ Deprecated |
| 2 | + |
| 3 | +There is a new, nicer to use, slimmer rglua on the horizon. |
| 4 | + |
| 5 | +For the lua api equivalent to rglua, [autorun-lua](https://github.com/thevurv/Autorun-ng/tree/master/packages/autorun-lua) |
| 6 | +For access to source sdk bindings for gmod, [autorun-interfaces](https://github.com/thevurv/Autorun-ng/tree/master/packages/autorun-interfaces) |
| 7 | + |
| 8 | +Don't let their names scare you. They're a part of the new Autorun-ng project, but similar to how rglua was to Autorun-rs, they will be able to be used outside of Autorun-ng. |
| 9 | + |
| 10 | +Here's an example. |
| 11 | + |
| 12 | +```rs |
| 13 | +/// A basic example of creating a binary module using `autorun-lua` |
| 14 | +/// Add this to your deps |
| 15 | +/// { git = "https://github.com/thevurv/Autorun-ng", package = "autorun-lua" } |
| 16 | +use autorun_lua::*; |
| 17 | + |
| 18 | +// Or return anyhow::Result<f64> |
| 19 | +fn lua_adder(lua: &LuaApi, state: *mut LuaState) -> Result<f64, Box<dyn std::error::Error>> { |
| 20 | + let x = lua.check_number(state, 1); |
| 21 | + let y = lua.check_number(state, 2); |
| 22 | + |
| 23 | + // This pushes it onto lua's stack for you. |
| 24 | + // You can return multiple values via a tuple of values |
| 25 | + // Additionally, Option<T> values work too, where None pushes nil. |
| 26 | + Ok(x + y) |
| 27 | +} |
| 28 | + |
| 29 | +#[unsafe(no_mangle)] |
| 30 | +pub extern "C-unwind" fn gmod13_open(state: *mut LuaState) -> std::ffi::c_int { |
| 31 | + let lua = autorun_lua::get_api().expect("Failed to get lua api"); |
| 32 | + |
| 33 | + lua.push_globals(state); // Push _G |
| 34 | + |
| 35 | + lua.push(state, "adder"); |
| 36 | + lua.push(state, as_lua_function!(lua_adder)); |
| 37 | + lua.set_table(state, -3); // _G["adder"] = lua_adder |
| 38 | + |
| 39 | + 0 |
| 40 | +} |
| 41 | +``` |
| 42 | + |
1 | 43 | # 🌑 ``rglua`` [](https://crates.io/crates/rglua)  [](https://opensource.org/licenses/Apache-2.0) [](https://discord.gg/epJFC6cNsw) |
2 | 44 |
|
3 | 45 | This is a crate that allows interop with the (g)luajit c api as well as the source sdk through libloading and vtable bindings. |
|
0 commit comments