Advertisement
Guest User

Untitled

a guest
Feb 21st, 2018
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.97 KB | None | 0 0
  1.  
  2.     std::shared_ptr<value> getVariable_namespace_string(virtualmachine* vm, std::shared_ptr<value> left, std::shared_ptr<value> right)
  3.     {
  4.         auto l = std::static_pointer_cast<sqfnamespace>(left->data());
  5.         auto r = right->as_string();
  6.         auto var = l->getvar_empty(r);
  7.         return var;
  8.     }
  9.     std::shared_ptr<value> getVariable_namespace_array(virtualmachine* vm, std::shared_ptr<value> left, std::shared_ptr<value> right)
  10.     {
  11.         auto l = std::static_pointer_cast<sqfnamespace>(left->data());
  12.         auto r = right->as_vector();
  13.         if (r.size() != 2)
  14.         {
  15.             vm->err() << L"Expected 2 elements in array, got " << r.size() << L". Returning NIL." << std::endl;
  16.             return std::shared_ptr<value>();
  17.         }
  18.         if (r[0]->dtype() != sqf::type::STRING)
  19.         {
  20.             vm->err() << L"Index position 0 was expected to be of type 'STRING' but was '" << sqf::type_str(r[0]->dtype()) << L"'." << std::endl;
  21.             return std::shared_ptr<value>();
  22.         }
  23.         auto def = r[1];
  24.         auto var = l->getvar_empty(r[0]->as_string());
  25.         return var.get() ? var : def;
  26.     }
  27.     std::shared_ptr<value> setVariable_namespace_array(virtualmachine* vm, std::shared_ptr<value> left, std::shared_ptr<value> right)
  28.     {
  29.         auto l = std::static_pointer_cast<sqfnamespace>(left->data());
  30.         auto r = right->as_vector();
  31.         if (r.size() != 2 && r.size() != 3)
  32.         {
  33.             vm->err() << L"Expected 2 elements in array, got " << r.size() << L". Returning NIL." << std::endl;
  34.             return std::shared_ptr<value>();
  35.         }
  36.         if (r.size() == 3 && r[2]->dtype() != sqf::type::BOOL)
  37.         {
  38.             vm->err() << L"Index position 0 was expected to be of type 'BOOL' but was '" << sqf::type_str(r[2]->dtype()) << L"'." << std::endl;
  39.             return std::shared_ptr<value>();
  40.         }
  41.         if (r[0]->dtype() != sqf::type::STRING)
  42.         {
  43.             vm->err() << L"Index position 0 was expected to be of type 'STRING' but was '" << sqf::type_str(r[0]->dtype()) << L"'." << std::endl;
  44.             return std::shared_ptr<value>();
  45.         }
  46.         auto val = r[1];
  47.         l->setvar(r[0]->as_string(), val);
  48.         return std::make_shared<value>();
  49.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement