Skip to main content

luaur_bytecode/records/
constant.rs

1#[allow(non_camel_case_types)]
2use crate::enums::r#type::Type;
3
4#[derive(Debug, Clone, Copy)]
5pub struct Constant {
6    pub(crate) r#type: Type,
7    pub(crate) value: ConstantValue,
8}
9
10#[derive(Clone, Copy)]
11#[repr(C)]
12#[allow(non_snake_case)]
13pub union ConstantValue {
14    pub(crate) valueBoolean: bool,
15    pub(crate) valueNumber: f64,
16    pub(crate) valueInteger64: i64,
17    pub(crate) valueVector: [f32; 4],
18    pub(crate) valueString: u32,
19    pub(crate) valueImport: u32,
20    pub(crate) valueTable: u32,
21    pub(crate) valueClosure: u32,
22    pub(crate) valueClassShape: u32,
23}
24
25// A union has no active-variant tag of its own, so `Debug` cannot read a field
26// safely; print it opaquely. The active variant is known only via the owning
27// `Constant`'s `type` discriminant.
28impl core::fmt::Debug for ConstantValue {
29    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
30        f.write_str("ConstantValue(..)")
31    }
32}