MCPcopy Create free account
hub / github.com/StrataWM/strata / from_value

Method from_value

src/bindings/input/modflags.rs:21–45  ·  view source on GitHub ↗
(_: lua::Context<'gc>, value: lua::Value<'gc>)

Source from the content-addressed store, hash-verified

19
20impl<'gc> FromValue<'gc> for ModFlags {
21 fn from_value(_: lua::Context<'gc>, value: lua::Value<'gc>) -> Result<Self, lua::TypeError> {
22 match value {
23 lua::Value::Table(mods) => {
24 let mut r = Self::empty();
25
26 for (_, v) in mods {
27 match v {
28 lua::Value::UserData(ud) => {
29 let bits = *ud.downcast_static::<Self>().map_err(|_| {
30 lua::TypeError { expected: "Mod", found: value.type_name() }
31 })?;
32
33 r |= bits;
34 }
35 _ => {
36 return Err(lua::TypeError { expected: "Mod", found: v.type_name() });
37 }
38 };
39 }
40
41 return Ok(r);
42 }
43 _ => Err(lua::TypeError { found: value.type_name(), expected: "table" }),
44 }
45 }
46}
47
48pub fn module<'gc>(

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected