forked from odedstr/Godot-std_io
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstd_io.cpp
More file actions
50 lines (38 loc) · 1.13 KB
/
Copy pathstd_io.cpp
File metadata and controls
50 lines (38 loc) · 1.13 KB
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
45
46
47
48
49
50
//
// std_io.cpp
// std_io
//
// Created by Oded Streigold on 4/18/20.
//
#include "std_io.h"
#include "process.hpp"
#include <iostream>
using namespace std;
using namespace TinyProcessLib;
void STD_IO::add(int p_value) {
count += p_value;
auto exit_status=0;
cout << endl << "Example 7 - send data to cat through stdin" << endl;
Process process7("cat", "", [](const char *bytes, size_t n) {
cout << "Output from stdout: " << string(bytes, n);
}, nullptr, true);
process7.write("Hello cat\n");
process7.close_stdin();
exit_status=process7.get_exit_status();
cout << "Example 7 process returned: " << exit_status << " (" << (exit_status==0?"success":"failure") << ")" << endl;
this_thread::sleep_for(chrono::seconds(5));
}
void STD_IO::reset() {
count = 0;
}
int STD_IO::get_total() const {
return count;
}
void STD_IO::_bind_methods() {
ClassDB::bind_method(D_METHOD("add", "value"), &STD_IO::add);
ClassDB::bind_method(D_METHOD("reset"), &STD_IO::reset);
ClassDB::bind_method(D_METHOD("get_total"), &STD_IO::get_total);
}
STD_IO::STD_IO() {
count = 0;
}