-
Notifications
You must be signed in to change notification settings - Fork 0
/
value_size.rs
58 lines (45 loc) · 1.57 KB
/
value_size.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
use std::cell::RefCell;
use std::ptr::NonNull;
use std::rc::Rc;
enum LuaValue {
Nil,
Int(i32),
Float(f64),
String(LuaString),
NativeFunction(NativeFunction),
Function(BlockID),
Table(TableRef),
}
#[repr(packed(4))]
pub struct LuaString {
len: u32,
block: [u8; 8],
}
struct StrBlockHeader {
refcount: usize
}
struct StrBlock {
header: StrBlockHeader,
data: str,
}
fn main() {
println!("f64: {}\t\t\tOption<f64>: {}", std::mem::size_of::<f64>(), std::mem::size_of::<Option<f64>>());
println!("LuaValue: {}\t\tOption<LuaValue>: {}", std::mem::size_of::<LuaValue>(), std::mem::size_of::<Option<LuaValue>>());
println!("LuaString: {}\t\tOption<LuaString>: {}", std::mem::size_of::<LuaString>(), std::mem::size_of::<Option<LuaString>>());
println!("String: {}\t\tOption<String>: {}", std::mem::size_of::<String>(), std::mem::size_of::<Option<String>>());
println!("TableRef: {}\t\tOption<TableRef>: {}", std::mem::size_of::<TableRef>(), std::mem::size_of::<Option<TableRef>>());
println!("NativeFunction: {}\tOption<NativeFunction>: {}", std::mem::size_of::<NativeFunction>(), std::mem::size_of::<Option<NativeFunction>>());
println!("[LuaString;2]: {}", std::mem::size_of::<[LuaString; 2]>());
}
pub struct NativeFunction(pub(crate) Rc<NativeFunctionKind>);
pub(crate) enum NativeFunctionKind {
Dyn(Box<dyn NativeFunctionCallable>),
// OverloadSet(OverloadSet),
}
trait NativeFunctionCallable {
fn call(&self);
}
struct BlockID(u32);
pub struct TableValue {
}
pub struct TableRef(Rc<RefCell<TableValue>>);