A simple scripting language in C++
Ferenc Szontágh
2025-04-19 48d9278f0b75098e83e58c589ea86d006358604d
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// PrintModule.hpp
#ifndef MODULES_PRINTMODULE_HPP
#define MODULES_PRINTMODULE_HPP
 
#include <iostream>
 
#include "Modules/BaseModule.hpp"
#include "Modules/ModuleManager.hpp"
#include "Symbols/Value.hpp"
 
namespace Modules {
 
/**
 * @brief Module that provides a built-in print function.
 */
class PrintModule : public BaseModule {
  public:
    void registerModule() override {
        auto & mgr = ModuleManager::instance();
        mgr.registerFunction("print", [](const std::vector<Symbols::Value> & args) {
            for (const auto & v : args) {
                std::cout << Symbols::Value::to_string(v);
            }
            return Symbols::Value();
        });
        mgr.registerFunction("printnl", [](const std::vector<Symbols::Value> & args) {
            for (const auto & v : args) {
                std::cout << Symbols::Value::to_string(v);
            }
            std::cout << "\n";
            return Symbols::Value();
        });
        mgr.registerFunction("error", [](const std::vector<Symbols::Value> & args) {
            for (const auto & v : args) {
                std::cerr << Symbols::Value::to_string(v);
            }
            std::cerr << "\n";
            return Symbols::Value();
        });
    }
};
 
}  // namespace Modules
#endif  // MODULES_PRINTMODULE_HPP