mirror of
https://github.com/fedddddd/iw5-gsc-utils.git
synced 2025-04-21 05:15:44 +00:00
Catch insufficient arguments
This commit is contained in:
parent
376e7f11ec
commit
2a0789692f
@ -13,6 +13,32 @@
|
||||
|
||||
namespace gsc
|
||||
{
|
||||
function_args::function_args(std::vector<scripting::script_value> values)
|
||||
: values_(values)
|
||||
{
|
||||
}
|
||||
|
||||
unsigned int function_args::size() const
|
||||
{
|
||||
return this->values_.size();
|
||||
}
|
||||
|
||||
std::vector<scripting::script_value> 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<unsigned, script_function> functions;
|
||||
std::unordered_map<unsigned, script_method> methods;
|
||||
|
||||
@ -50,7 +76,7 @@ namespace gsc
|
||||
|
||||
function_args get_arguments()
|
||||
{
|
||||
function_args args;
|
||||
std::vector<scripting::script_value> args;
|
||||
|
||||
const auto top = game::scr_VmPub->top;
|
||||
|
||||
|
@ -2,7 +2,22 @@
|
||||
|
||||
namespace gsc
|
||||
{
|
||||
using function_args = std::vector<scripting::script_value>;
|
||||
class function_args
|
||||
{
|
||||
public:
|
||||
function_args(std::vector<scripting::script_value>);
|
||||
|
||||
unsigned int function_args::size() const;
|
||||
std::vector<scripting::script_value> 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<scripting::script_value> values_;
|
||||
};
|
||||
|
||||
using builtin_function = void(*)();
|
||||
using builtin_method = void(*)(game::scr_entref_t);
|
||||
|
@ -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();
|
||||
});
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user