65 lines
1.2 KiB
C++
65 lines
1.2 KiB
C++
export module kym;
|
|
|
|
import coral;
|
|
import coral.math;
|
|
|
|
export namespace kym {
|
|
enum class value_type {
|
|
nil,
|
|
boolean,
|
|
integer,
|
|
scalar,
|
|
vector2,
|
|
vector3,
|
|
object,
|
|
};
|
|
|
|
struct value {
|
|
value_type type{value_type::nil};
|
|
|
|
value() = default;
|
|
|
|
value(bool boolean) {
|
|
this->data[1] = 0xff * boolean;
|
|
this->type = value_type::boolean;
|
|
}
|
|
|
|
value(coral::i64 integer) {
|
|
(*reinterpret_cast<coral::u64 *>(this->data)) =
|
|
(*reinterpret_cast<coral::u64 *>(&integer));
|
|
|
|
this->type = value_type::integer;
|
|
}
|
|
|
|
value(coral::f64 scalar) {
|
|
(*reinterpret_cast<coral::u64 *>(this->data)) =
|
|
(*reinterpret_cast<coral::u64 *>(&scalar));
|
|
|
|
this->type = value_type::scalar;
|
|
}
|
|
|
|
value(coral::vector2 vector2) {
|
|
(*reinterpret_cast<coral::u64 *>(this->data)) =
|
|
(*reinterpret_cast<coral::u64 *>(&vector2));
|
|
|
|
this->type = value_type::vector2;
|
|
}
|
|
|
|
value(coral::vector3 const & vector3) {
|
|
coral::copy(this->data, coral::as_bytes(&vector3));
|
|
|
|
this->type = value_type::vector3;
|
|
}
|
|
|
|
coral::optional<coral::i64> as_integer() const {
|
|
if (this->type == value_type::integer)
|
|
return (*reinterpret_cast<coral::i64 const *>(&this->data));
|
|
|
|
return {};
|
|
}
|
|
|
|
private:
|
|
coral::u8 data[12]{0};
|
|
};
|
|
};
|