-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommand
More file actions
90 lines (64 loc) · 3.4 KB
/
command
File metadata and controls
90 lines (64 loc) · 3.4 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#pragma once
#include "command_impl.h"
#include "script.h"
#include <iostream>
#include <format>
#include <split.h>
#include <findMatch.h>
// Registers one command using the current source file basename as the command name.
// Your, the programmer, write the code body that goes with it
// (which will be executed as a lambda).
//
// Usage:
// REGISTER_COMMAND
// {
// // body can access `args`
// };
#define REGISTER_COMMAND REGISTER_COMMAND_IMPL(FILE_BASENAME)
// The current command name derived from the source file basename.
#define COMMAND STRINGIFY(FILE_BASENAME)
// The current script line number at execution time.
#define LINE ScriptInstance::getLineNumber()
#define SOURCE ScriptInstance::getSource()
// The current instruction index in the active program.
#define INSTRUCTION ScriptInstance::getInstructionIndex()
// The number of commands in the active program.
#define COMMAND_COUNT ScriptInstance::getCommandCount()
// The current command object in the active program.
#define CURRENT_COMMAND ScriptInstance::getCurrentCommand()
// Returns the command at the given instruction index.
#define GET_COMMAND(index) ScriptInstance::getCommand(index)
// Returns whether an instruction index is valid for the active program.
#define VALID_INSTRUCTION(index) ScriptInstance::isValidInstruction(index)
// Sets the current instruction index.
#define SET_INSTRUCTION(index) ScriptInstance::setInstruction(index)
// Resolves $variables in a string. Returns false and leaves the input unchanged on failure.
#define DEREFERENCE(text) Script::dereferenceVariables(text)
// Pushes an inheriting context frame onto the runtime call stack.
#define PUSH_STACK(returnIndex) ScriptInstance::pushStack(returnIndex, ContextFrame::INHERIT)
// Pushes an isolated context frame onto the runtime call stack.
#define PUSH_STACK_ISOLATED(returnIndex) ScriptInstance::pushStack(returnIndex, ContextFrame::ISOLATE)
// Restores the most recent instruction index from the runtime call stack.
#define POP_STACK ScriptInstance::popStack()
// Sets or overwrites a variable value.
#define SET_VARIABLE(name, value) ScriptInstance::setVariable(name, value)
// Sets or overwrites current-frame metadata.
#define SET_METADATA(name, value) ScriptInstance::setMetadata(name, value)
// Exposes the current frame's variable map and typed helpers like `asInt`.
#define VARIABLES ScriptInstance::getLocalVariables()
// Gets a visible variable value with typed helpers like `asInt()`.
#define GET_VARIABLE(name) StringValue(ScriptInstance::getVariable(name))
// Exposes the current frame's metadata map and typed helpers like `asInt`.
#define METADATA ScriptInstance::getLocalMetadata()
// Gets current-frame metadata by key with typed helpers like `asInt()`.
#define GET_METADATA(name) METADATA.get(name)
// Returns whether a variable exists.
#define HAS_VARIABLE(name) ScriptInstance::hasVariable(name)
// Returns whether current-frame metadata exists.
#define HAS_METADATA(name) ScriptInstance::hasMetadata(name)
// Removes a variable and returns whether one was removed.
#define REMOVE_VARIABLE(name) ScriptInstance::removeVariable(name)
// Removes current-frame metadata and returns whether one was removed.
#define REMOVE_METADATA(name) ScriptInstance::removeMetadata(name)
// Writes a standard command error message with the command name and line number.
#define ERROR(msg) {std::cerr << std::endl << "ERROR: '" << COMMAND << "' " << msg << " : " << SOURCE; std::exit(1);}