-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathret.cpp
More file actions
37 lines (32 loc) · 817 Bytes
/
ret.cpp
File metadata and controls
37 lines (32 loc) · 817 Bytes
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
#include <command>
#include <format>
#include <split.h>
/*
NAME
ret - return from the current script frame
SYNOPSIS
ret <value>
DESCRIPTION
Returns control to the previous stack frame with the given integer status.
If there is no previous frame, the process exits with that status code.
*/
REGISTER_COMMAND
{
try
{
auto expandedArgs = args;
DEREFERENCE(expandedArgs);
size_t numArgs = utils::split(expandedArgs).size();
if (expandedArgs.empty())
throw std::invalid_argument("requires a single integer argument <value>");
if (numArgs > 1)
throw std::invalid_argument(std::format("Too many arguments. Expected 1 got {}", numArgs));
const int value = std::stoi(expandedArgs);
if (!POP_STACK)
std::exit(value);
}
catch (const std::exception& e)
{
ERROR(e.what());
}
};