4
Copyright (c) 2021 МГТУ им. Н.Э. Баумана, кафедра ИУ-6, Михаил Фетисов,
6
https://bmstu.codes/lsx/simodo/loom
9
#include "simodo/variable/Module_interface.h"
10
#include "simodo/variable/VariableSetWrapper.h"
11
#include "simodo/interpret/Interpret_interface.h"
18
// MinGW related workaround
19
#define BOOST_DLL_FORCE_ALIAS_INSTANTIATION
22
#include <boost/dll/alias.hpp>
24
using namespace simodo;
28
variable::Value createOutput(variable::Module_interface * host, const variable::VariableSetWrapper & args);
29
variable::Value openOutput(variable::Module_interface * host, const variable::VariableSetWrapper & args);
30
variable::Value openInput(variable::Module_interface * host, const variable::VariableSetWrapper & args);
31
variable::Value output(variable::Module_interface * host, const variable::VariableSetWrapper & args);
32
variable::Value outputLine(variable::Module_interface * host, const variable::VariableSetWrapper & args);
33
variable::Value inputLine(variable::Module_interface * host, const variable::VariableSetWrapper & args);
34
variable::Value _close(variable::Module_interface * host, const variable::VariableSetWrapper & args);
35
variable::Value _read(variable::Module_interface * host, const variable::VariableSetWrapper & args);
36
variable::Value _write(variable::Module_interface * host, const variable::VariableSetWrapper & args);
39
class Io_module : public variable::Module_interface
42
virtual version_t version() const override { return lib_version(); }
44
virtual variable::Value instantiate(std::shared_ptr<Module_interface> module_object) override
47
{u"createOutput", {variable::ValueType::Function, variable::Object {{
48
{u"@", variable::ExternalFunction {module_object, ::createOutput}},
49
{{}, variable::ValueType::Int},
50
{u"file_name", variable::ValueType::String},
52
{u"openOutput", {variable::ValueType::Function, variable::Object {{
53
{u"@", variable::ExternalFunction {module_object, ::openOutput}},
54
{{}, variable::ValueType::Int},
55
{u"file_name", variable::ValueType::String},
57
{u"openInput", {variable::ValueType::Function, variable::Object {{
58
{u"@", variable::ExternalFunction {module_object, ::openInput}},
59
{{}, variable::ValueType::Int},
60
{u"file_name", variable::ValueType::String},
62
{u"output", {variable::ValueType::Function, variable::Object {{
63
{u"@", variable::ExternalFunction {module_object, ::output}},
64
{{}, variable::ValueType::Bool},
65
{u"file_id", variable::ValueType::Int},
66
{u"value_string", variable::ValueType::String},
68
{u"outputLine", {variable::ValueType::Function, variable::Object {{
69
{u"@", variable::ExternalFunction {module_object, ::outputLine}},
70
{{}, variable::ValueType::Bool},
71
{u"file_id", variable::ValueType::Int},
72
{u"value_string", variable::ValueType::String},
74
{u"inputLine", {variable::ValueType::Function, variable::Object {{
75
{u"@", variable::ExternalFunction {module_object, ::inputLine}},
76
{{}, variable::ValueType::Object},
77
{u"file_id", variable::ValueType::Int},
79
{u"close", {variable::ValueType::Function, variable::Object {{
80
{u"@", variable::ExternalFunction {module_object, ::_close}},
81
{{}, variable::ValueType::Bool},
82
{u"file_id", variable::ValueType::Int},
84
{u"read", {variable::ValueType::Function, variable::Object {{
85
{u"@", variable::ExternalFunction {module_object, ::_read}},
86
{{}, variable::ValueType::Object},
87
{u"file_name", variable::ValueType::String},
89
{u"write", {variable::ValueType::Function, variable::Object {{
90
{u"@", variable::ExternalFunction {module_object, ::_write}},
91
{{}, variable::ValueType::Bool},
92
{u"file_name", variable::ValueType::String},
93
{u"text_string", variable::ValueType::String},
99
static std::shared_ptr<Module_interface> create(interpret::Interpret_interface * ) {
100
return std::make_shared<Io_module>();
105
Io_module::create, // <-- this function is exported with...
106
create_simodo_module // <-- ...this alias name
111
variable::Value createOutput(variable::Module_interface * , const variable::VariableSetWrapper & args)
113
assert(args.size() == 1);
115
const variable::Value & file_name_value = args[0].origin().value();
117
assert(file_name_value.isString());
124
variable::Value openOutput(variable::Module_interface * , const variable::VariableSetWrapper & args)
126
assert(args.size() == 1);
128
const variable::Value & file_name_value = args[0].origin().value();
130
assert(file_name_value.isString());
137
variable::Value openInput(variable::Module_interface * , const variable::VariableSetWrapper & args)
139
assert(args.size() == 1);
141
const variable::Value & file_name_value = args[0].origin().value();
143
assert(file_name_value.isString());
150
variable::Value output(variable::Module_interface * , const variable::VariableSetWrapper & /*args*/)
157
variable::Value outputLine(variable::Module_interface * , const variable::VariableSetWrapper & /*args*/)
164
variable::Value inputLine(variable::Module_interface * /*host*/, const variable::VariableSetWrapper & /*args*/)
171
variable::Value _close(variable::Module_interface * /*host*/, const variable::VariableSetWrapper & /*args*/)
178
variable::Value _read(variable::Module_interface * /*host*/, const variable::VariableSetWrapper & /*args*/)
185
variable::Value _write(variable::Module_interface * /*host*/, const variable::VariableSetWrapper & /*args*/)