Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- std::shared_ptr<value> getVariable_namespace_string(virtualmachine* vm, std::shared_ptr<value> left, std::shared_ptr<value> right)
- {
- auto l = std::static_pointer_cast<sqfnamespace>(left->data());
- auto r = right->as_string();
- auto var = l->getvar_empty(r);
- return var;
- }
- std::shared_ptr<value> getVariable_namespace_array(virtualmachine* vm, std::shared_ptr<value> left, std::shared_ptr<value> right)
- {
- auto l = std::static_pointer_cast<sqfnamespace>(left->data());
- auto r = right->as_vector();
- if (r.size() != 2)
- {
- vm->err() << L"Expected 2 elements in array, got " << r.size() << L". Returning NIL." << std::endl;
- return std::shared_ptr<value>();
- }
- if (r[0]->dtype() != sqf::type::STRING)
- {
- vm->err() << L"Index position 0 was expected to be of type 'STRING' but was '" << sqf::type_str(r[0]->dtype()) << L"'." << std::endl;
- return std::shared_ptr<value>();
- }
- auto def = r[1];
- auto var = l->getvar_empty(r[0]->as_string());
- return var.get() ? var : def;
- }
- std::shared_ptr<value> setVariable_namespace_array(virtualmachine* vm, std::shared_ptr<value> left, std::shared_ptr<value> right)
- {
- auto l = std::static_pointer_cast<sqfnamespace>(left->data());
- auto r = right->as_vector();
- if (r.size() != 2 && r.size() != 3)
- {
- vm->err() << L"Expected 2 elements in array, got " << r.size() << L". Returning NIL." << std::endl;
- return std::shared_ptr<value>();
- }
- if (r.size() == 3 && r[2]->dtype() != sqf::type::BOOL)
- {
- vm->err() << L"Index position 0 was expected to be of type 'BOOL' but was '" << sqf::type_str(r[2]->dtype()) << L"'." << std::endl;
- return std::shared_ptr<value>();
- }
- if (r[0]->dtype() != sqf::type::STRING)
- {
- vm->err() << L"Index position 0 was expected to be of type 'STRING' but was '" << sqf::type_str(r[0]->dtype()) << L"'." << std::endl;
- return std::shared_ptr<value>();
- }
- auto val = r[1];
- l->setvar(r[0]->as_string(), val);
- return std::make_shared<value>();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement