runner: ignore one arg when its in repl

closes #8
This commit is contained in:
Luna 2019-10-06 15:16:41 -03:00
parent 7cf16f9ffa
commit c05be26dbd
2 changed files with 16 additions and 8 deletions

View file

@ -54,11 +54,9 @@ pub fn doRepl(allocator: *std.mem.Allocator, args_it: var) !void {
}
} else {
// if there isn't any commands on the file, we load our default
// 'load :1' command
// TODO load should +1 the index if its on repl
// 'load :0' command
var loadargs = langs.ArgList.init(allocator);
try loadargs.append(":1");
try loadargs.append(":0");
try cmds.append(langs.Command{
.command = .Load,
@ -90,7 +88,7 @@ pub fn doRepl(allocator: *std.mem.Allocator, args_it: var) !void {
var current: langs.Command = undefined;
var runner = runners.Runner.init(allocator);
var runner = runners.Runner.init(allocator, true);
defer runner.deinit();
// run the load command
@ -164,7 +162,7 @@ pub fn main() !void {
var lang = langs.Lang.init(allocator);
defer lang.deinit();
var runner = runners.Runner.init(allocator);
var runner = runners.Runner.init(allocator, false);
defer runner.deinit();
var args_it = std.process.args();

View file

@ -19,11 +19,17 @@ pub const RunError = error{
pub const Runner = struct {
allocator: *std.mem.Allocator,
/// The currently opened image in the runner
image: ?*Image = null,
pub fn init(allocator: *std.mem.Allocator) Runner {
/// If the runner is in REPL mode
repl: bool = false,
pub fn init(allocator: *std.mem.Allocator, repl: bool) Runner {
return Runner{
.allocator = allocator,
.repl = repl,
};
}
@ -41,7 +47,11 @@ pub const Runner = struct {
fn resolveArg(self: *Runner, load_path: []const u8) ![]const u8 {
if (load_path[0] == ':') {
// parse the index from 1 to end
const index = try std.fmt.parseInt(usize, load_path[1..], 10);
var index = try std.fmt.parseInt(usize, load_path[1..], 10);
// don't care about the 'repl' being prepended when we're in repl
if (self.repl) index += 1;
var args_it = std.process.args();
_ = args_it.skip();