#[repr(C, u64)]pub enum Value {
Nil,
Bool(bool),
Int(i64),
Num(f64),
Str(StrRef),
Table(TableRef),
Func(FuncRef),
UserData(UdRef),
Thread(ThreadRef),
}Expand description
Variants§
Nil
nil.
Bool(bool)
true or false.
Int(i64)
An integer (64-bit, wrapping).
Num(f64)
A float (64-bit).
Str(StrRef)
A string (bytes, not necessarily UTF-8).
Table(TableRef)
A table.
Func(FuncRef)
A function.
UserData(UdRef)
A full userdata.
Thread(ThreadRef)
A coroutine.
Implementations§
Source§impl Value
impl Value
Sourcepub fn truthy(self) -> bool
pub fn truthy(self) -> bool
Whether it counts as true in a condition (everything but nil and false).
Sourcepub fn is_nil(self) -> bool
pub fn is_nil(self) -> bool
Whether it is nil.
Examples found in repository?
examples/sechost.rs (line 40)
11fn main() {
12 let a: Vec<String> = std::env::args().collect();
13 let kind = a.get(1).cloned().unwrap_or_else(|| "ud".into());
14 let n: usize = a.get(2).and_then(|s| s.parse().ok()).unwrap_or(200_000);
15 let mut lua = Lua::new(Limits::default().memory(1 << 30).fuel(1 << 40), Libs::ALL);
16 lua.exec("KEEP = {}", "=s").unwrap();
17 let keep = match lua.exec("return KEEP", "=s").unwrap()[0] { Value::Table(t) => t, _ => panic!() };
18 let mut roots = Vec::new();
19 lua.collect_garbage().unwrap();
20 let (r0, m0) = (rss(), lua.memory_used());
21 for i in 0..n {
22 let v = match kind.as_str() {
23 "ud" | "ud_root" => lua.create_userdata(i as u64, None).unwrap(),
24 "ud_tracked" => lua.create_userdata_tracked(i as u64, None, i as u64).unwrap(),
25 "fn" | "fn_root" => lua.create_function("f", move |_, _| Ok(vec![Value::Int(i as i64)])).unwrap(),
26 "root" => Value::Int(i as i64),
27 "register" => {
28 lua.register(&format!("g{i}"), move |_, _| Ok(vec![Value::Int(i as i64)])).unwrap();
29 Value::Nil
30 }
31 _ => panic!("kind"),
32 };
33 if kind.ends_with("root") {
34 let t = if kind == "root" { lua.create_table().map(Value::Table).unwrap() } else { v };
35 roots.push(lua.root(t));
36 if kind == "root" {
37 continue;
38 }
39 }
40 if !v.is_nil() {
41 lua.table_set(keep, Value::Int(i as i64 + 1), v).unwrap();
42 }
43 if i % 4096 == 0 {
44 lua.exec("", "=s").unwrap();
45 }
46 }
47 lua.exec("", "=s").unwrap();
48 lua.collect_garbage().unwrap();
49 let (r1, m1) = (rss(), lua.memory_used());
50 let (dr, dm) = (r1.saturating_sub(r0) as f64 / n as f64, m1.saturating_sub(m0) as f64 / n as f64);
51 println!("{kind}: {dr:.0} B resident, {dm:.0} B counted per object ({:.2}x)", dr / dm.max(1.0));
52 drop(roots);
53}Sourcepub fn raw_eq(self, other: Value) -> bool
pub fn raw_eq(self, other: Value) -> bool
Equality without metamethods, by identity for strings: short strings (up to 40
bytes) are interned, so this is rawequal for them, but two equal long strings may be
different objects. Hosts compare values with Lua::raw_equal.
Trait Implementations§
impl Copy for Value
Auto Trait Implementations§
impl Forget for Value
impl Freeze for Value
impl Move for Value
impl RefUnwindSafe for Value
impl Send for Value
impl Sync for Value
impl Unpin for Value
impl UnsafeUnpin for Value
impl UnwindSafe for Value
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more