3static std::string
toHex(
int value)
6 ss << std::showbase << std::hex << value;
44 const std::string &fmt = args[0].
asString();
48 for (
size_t i = 0; i < fmt.size(); ++i)
50 if (fmt[i] ==
'%' && i + 1 < fmt.size())
53 if (argIndex < args.size())
55 const Value &v = args[argIndex++];
63 out += std::to_string(v.
asInt());
66 out += std::to_string(v.
asFloat());
98 std::vector<Value> formatArgs(args.begin(), args.end());
106 std::string input = args[0].toString();
114 std::vector<Value> formatArgs(args.begin(), args.end());
131 std::string input = args[0].toString();
139 std::vector<Value> formatArgs(args.begin(), args.end());
static Value io_clear(const std::vector< Value > &args, VM *vm)
Clear the console.
static Value io_printf(const std::vector< Value > &args, VM *vm)
Print formatted string.
static Value io_puts_error(const std::vector< Value > &args, VM *vm)
Print string with newline to error output.
static void registerIOFunctions(VM *vm)
static Value io_puts(const std::vector< Value > &args, VM *vm)
Print string with newline.
static Value io_putf(const std::vector< Value > &args, VM *vm)
Print formatted string with newline.
static Value io_prints(const std::vector< Value > &args, VM *vm)
Print string without newline.
static void checkArgCount(const std::vector< Value > &args, size_t minimumArguments, const std::string &name, bool allowMoreArguments=false)
static Value io_c_format(const std::vector< Value > &args, VM *vm)
Format string.
static Value io_putf_error(const std::vector< Value > &args, VM *vm)
Print formatted string with newline to error output.
static Value io_gets(const std::vector< Value > &args, VM *vm)
Get string.
void registerNativeFunction(const std::string &name, NativeFunction fn)
Register a native function.
Value regRun(OpCode opcode, Args &&...args)
Run an opcode with arguments pre-loaded into registers.
A value in the Phasor VM.
std::string toString() const
Convert to string for printing.
double asFloat() const
Get the value as a double.
std::string asString() const
Get the value as a string.
int64_t asInt() const
Get the value as an integer.
static std::string toHex(int value)
The Phasor Programming Language and Runtime.
@ PRINTERROR_R
Print register to stderr: printerror(R[rA]).
@ READLINE_R
Read line into register: readline(R[rA]).
@ PRINT_R
Print register: print(R[rA]).