Skip to content

Commit

Permalink
Fixed bug on the MyShell wrapper implementation on standard library.
Browse files Browse the repository at this point in the history
  • Loading branch information
nthnn committed Dec 12, 2024
1 parent 0bee4ce commit e8f3d5b
Showing 1 changed file with 32 additions and 37 deletions.
69 changes: 32 additions & 37 deletions std/n8std/Sys.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#include <myshell.hpp>
#include <unordered_map>

static std::unordered_map<std::string, std::shared_ptr<MyShell>> shellMap;
inline std::unordered_map<std::string, std::shared_ptr<MyShell>> shellMap;

N8_FUNC(sys_quickShell) {
if(args.size() != 1)
Expand Down Expand Up @@ -55,6 +55,8 @@ N8_FUNC(sys_shellConnect) {
std::string uuid = N8Util::generateUuid();

shellMap[uuid] = std::make_shared<MyShell>(value.toString());
std::this_thread::sleep_for(std::chrono::milliseconds(20));

return DynamicObject(uuid);
}

Expand All @@ -68,7 +70,7 @@ N8_FUNC(sys_shellWrite) {

DynamicObject value = args.at(0),
content = args.at(1);
std::string uuid = N8Util::generateUuid();
std::string uuid = value.toString();

if(shellMap.find(uuid) == shellMap.end())
throw TerminativeThrowSignal(
Expand All @@ -81,16 +83,15 @@ N8_FUNC(sys_shellWrite) {
}

N8_FUNC(sys_shellReadOutput) {
if(args.size() != 2)
if(args.size() != 1)
throw TerminativeThrowSignal(
std::move(address),
"Expecting 2 argument, got " +
"Expecting 1 argument, got " +
std::to_string(args.size())
);

DynamicObject value = args.at(0),
content = args.at(1);
std::string uuid = N8Util::generateUuid();
DynamicObject value = args.at(0);
std::string uuid = value.toString();

if(shellMap.find(uuid) == shellMap.end())
throw TerminativeThrowSignal(
Expand All @@ -104,16 +105,15 @@ N8_FUNC(sys_shellReadOutput) {
}

N8_FUNC(sys_shellReadError) {
if(args.size() != 2)
if(args.size() != 1)
throw TerminativeThrowSignal(
std::move(address),
"Expecting 2 argument, got " +
"Expecting 1 argument, got " +
std::to_string(args.size())
);

DynamicObject value = args.at(0),
content = args.at(1);
std::string uuid = N8Util::generateUuid();
DynamicObject value = args.at(0);
std::string uuid = value.toString();

if(shellMap.find(uuid) == shellMap.end())
throw TerminativeThrowSignal(
Expand All @@ -127,16 +127,15 @@ N8_FUNC(sys_shellReadError) {
}

N8_FUNC(sys_shellForceExit) {
if(args.size() != 2)
if(args.size() != 1)
throw TerminativeThrowSignal(
std::move(address),
"Expecting 2 argument, got " +
"Expecting 1 argument, got " +
std::to_string(args.size())
);

DynamicObject value = args.at(0),
content = args.at(1);
std::string uuid = N8Util::generateUuid();
DynamicObject value = args.at(0);
std::string uuid = value.toString();

if(shellMap.find(uuid) == shellMap.end())
throw TerminativeThrowSignal(
Expand All @@ -149,16 +148,15 @@ N8_FUNC(sys_shellForceExit) {
}

N8_FUNC(sys_shellHasExited) {
if(args.size() != 2)
if(args.size() != 1)
throw TerminativeThrowSignal(
std::move(address),
"Expecting 2 argument, got " +
"Expecting 1 argument, got " +
std::to_string(args.size())
);

DynamicObject value = args.at(0),
content = args.at(1);
std::string uuid = N8Util::generateUuid();
DynamicObject value = args.at(0);
std::string uuid = value.toString();

if(shellMap.find(uuid) == shellMap.end())
throw TerminativeThrowSignal(
Expand All @@ -170,16 +168,15 @@ N8_FUNC(sys_shellHasExited) {
}

N8_FUNC(sys_shellExitCode) {
if(args.size() != 2)
if(args.size() != 1)
throw TerminativeThrowSignal(
std::move(address),
"Expecting 2 argument, got " +
"Expecting 1 argument, got " +
std::to_string(args.size())
);

DynamicObject value = args.at(0),
content = args.at(1);
std::string uuid = N8Util::generateUuid();
DynamicObject value = args.at(0);
std::string uuid = value.toString();

if(shellMap.find(uuid) == shellMap.end())
throw TerminativeThrowSignal(
Expand All @@ -195,16 +192,15 @@ N8_FUNC(sys_shellExitCode) {
}

N8_FUNC(sys_shellProcessId) {
if(args.size() != 2)
if(args.size() != 1)
throw TerminativeThrowSignal(
std::move(address),
"Expecting 2 argument, got " +
"Expecting 1 argument, got " +
std::to_string(args.size())
);

DynamicObject value = args.at(0),
content = args.at(1);
std::string uuid = N8Util::generateUuid();
DynamicObject value = args.at(0);
std::string uuid = value.toString();

if(shellMap.find(uuid) == shellMap.end())
throw TerminativeThrowSignal(
Expand All @@ -220,16 +216,15 @@ N8_FUNC(sys_shellProcessId) {
}

N8_FUNC(sys_shellClose) {
if(args.size() != 2)
if(args.size() != 1)
throw TerminativeThrowSignal(
std::move(address),
"Expecting 2 argument, got " +
"Expecting 1 argument, got " +
std::to_string(args.size())
);

DynamicObject value = args.at(0),
content = args.at(1);
std::string uuid = N8Util::generateUuid();
DynamicObject value = args.at(0);
std::string uuid = value.toString();

if(shellMap.find(uuid) == shellMap.end())
throw TerminativeThrowSignal(
Expand Down

0 comments on commit e8f3d5b

Please sign in to comment.