diff --git a/src/component/gsc.cpp b/src/component/gsc.cpp index c36bb12..26fd678 100644 --- a/src/component/gsc.cpp +++ b/src/component/gsc.cpp @@ -13,6 +13,32 @@ namespace gsc { + function_args::function_args(std::vector values) + : values_(values) + { + } + + unsigned int function_args::size() const + { + return this->values_.size(); + } + + std::vector function_args::get_raw() const + { + return this->values_; + } + + scripting::script_value function_args::get(const int index) const + { + if (index >= this->values_.size()) + { + throw std::runtime_error(utils::string::va("Insufficient arguments, got %i expected %i", + this->values_.size(), index + 1)); + } + + return this->values_[index]; + } + std::unordered_map functions; std::unordered_map methods; @@ -50,7 +76,7 @@ namespace gsc function_args get_arguments() { - function_args args; + std::vector args; const auto top = game::scr_VmPub->top; diff --git a/src/component/gsc.hpp b/src/component/gsc.hpp index d44a32e..8dcc3c2 100644 --- a/src/component/gsc.hpp +++ b/src/component/gsc.hpp @@ -2,7 +2,22 @@ namespace gsc { - using function_args = std::vector; + class function_args + { + public: + function_args(std::vector); + + unsigned int function_args::size() const; + std::vector function_args::get_raw() const; + scripting::script_value get(const int index) const; + + scripting::script_value operator[](const int index) const + { + return this->get(index); + } + private: + std::vector values_; + }; using builtin_function = void(*)(); using builtin_method = void(*)(game::scr_entref_t); diff --git a/src/component/json.cpp b/src/component/json.cpp index 1b4e7fd..6344533 100644 --- a/src/component/json.cpp +++ b/src/component/json.cpp @@ -143,7 +143,7 @@ namespace json { gsc::function::add("array", [](gsc::function_args args) { - scripting::array array(args); + scripting::array array(args.get_raw()); return array.get_raw(); });