-
Notifications
You must be signed in to change notification settings - Fork 0
3. rift::Value
Oleksandr Nemesh edited this page Oct 25, 2024
·
1 revision
From examples you might have noticed the rift::Value
class.
It's a simple structure that can hold either:
int32_t
float
std::string
bool
- special null value
It's used as a storage for variables and intermediate values in the interpreter.
You can create a rift::Value
from any of the supported types using the from
method:
auto val1 = rift::Value::from(42); // int32_t
auto val2 = rift::Value::from(3.14f); // float
auto val3 = rift::Value::from("Hello, World!"); // std::string
auto val4 = rift::Value::from(true); // bool
There's also another way where you tell it explicitly which type you want:
auto val1 = rift::Value::integer(42);
auto val2 = rift::Value::floating(3.14f);
auto val3 = rift::Value::string("Hello, World!");
auto val4 = rift::Value::boolean(true);
auto val5 = rift::Value::null(); // null can only be created this way