gmod/
net.rs

1use crate::{lua::{self, LuaFunction}, lua_string};
2
3#[inline(always)]
4pub unsafe fn add_network_strings<S: AsRef<str>>(lua: lua::State, network_strings: &[S]) {
5	match network_strings.len() {
6		0 => {},
7		1 => {
8			lua.get_global(lua_string!("util"));
9			lua.get_field(-1, lua_string!("AddNetworkString"));
10			lua.push_string(network_strings[0].as_ref());
11			lua.call(1, 0);
12			lua.pop();
13		},
14		_ => {
15			lua.get_global(lua_string!("util"));
16			lua.get_field(-1, lua_string!("AddNetworkString"));
17			for network_string in network_strings {
18				lua.push_value(-1);
19				lua.push_string(network_string.as_ref());
20				lua.call(1, 0);
21			}
22			lua.pop_n(2);
23		}
24	}
25}
26
27#[inline(always)]
28pub unsafe fn receive<S: AsRef<str>>(lua: lua::State, network_string: S, func: LuaFunction) {
29	lua.get_global(lua_string!("net"));
30	lua.get_field(-1, lua_string!("Receive"));
31	lua.push_string(network_string.as_ref());
32	lua.push_function(func);
33	lua.call(2, 0);
34	lua.pop();
35}