A simple scripting language in C++
Ferenc Szontágh
2025-04-14 d7cd4947b37a168034e9fca2501d98553fdcc137
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#ifndef MATH_UTILS_MODULE_HPP
#define MATH_UTILS_MODULE_HPP
 
#include <stdexcept>
#include <vector>
 
#include "ScriptExceptionMacros.h"
#include "Value.hpp"
 
class MathUtils {
  public:
    static Value multiply(const std::vector<Value> & args) {
        if (args.size() != 2) {
            throw std::runtime_error("multiply expects two arguments.");
        }
        if (args[0].type == Variables::Type::VT_INT && args[1].type == Variables::Type::VT_INT) {
            int  left   = args[0].ToInt();
            int  right  = args[1].ToInt();
            auto result = Value();
            result.data = left * right;
            result.type = Variables::Type::VT_INT;
            return result;
            //return Value::fromInt(left * right);
        }
        THROW_INVALID_FUNCTION_ARGUMENT_ERROR("multiply", args[0].TypeToString(), args[0].GetToken());
    };
};
#endif