diff options
author | Julien Dessaux | 2022-08-13 01:23:32 +0200 |
---|---|---|
committer | Julien Dessaux | 2022-08-13 01:23:32 +0200 |
commit | 0f440dfb6fc21c460b6c621571921298d94eb1b0 (patch) | |
tree | 4a7011ce12f4bf611883ea9b645e59a213d301af /src/pointer.zig | |
parent | Implemented the under funge command (diff) | |
download | zigfunge98-0f440dfb6fc21c460b6c621571921298d94eb1b0.tar.gz zigfunge98-0f440dfb6fc21c460b6c621571921298d94eb1b0.tar.bz2 zigfunge98-0f440dfb6fc21c460b6c621571921298d94eb1b0.zip |
Add environment handling
Diffstat (limited to 'src/pointer.zig')
-rw-r--r-- | src/pointer.zig | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/src/pointer.zig b/src/pointer.zig index 7578a65..d604518 100644 --- a/src/pointer.zig +++ b/src/pointer.zig @@ -23,6 +23,7 @@ pub const Pointer = struct { stringMode: bool = false, // string mode flags lastCharWasSpace: bool = false, ss: *stackStack.StackStack, + env: []const [*:0]const u8, argv: []const []const u8, rand: *std.rand.Random, @@ -267,13 +268,14 @@ pub const Pointer = struct { self.step(); return result; } - pub fn init(allocator: std.mem.Allocator, f: *field.Field, argv: []const []const u8) !*Pointer { + pub fn init(allocator: std.mem.Allocator, f: *field.Field, argv: []const []const u8, env: []const [*:0]const u8) !*Pointer { var p = try allocator.create(Pointer); errdefer allocator.destroy(p); p.allocator = allocator; p.field = f; p.ss = try stackStack.StackStack.init(allocator); p.argv = argv; + p.env = env; p.x = 0; p.y = 0; p.dx = 1; @@ -356,7 +358,8 @@ test "minimal" { var f = try field.Field.init_from_reader(std.testing.allocator, minimal); defer f.deinit(); const argv = [_][]const u8{"minimal"}; - var p = try Pointer.init(std.testing.allocator, f, argv[0..]); + const env = [_][*:0]const u8{"ENV=TEST"}; + var p = try Pointer.init(std.testing.allocator, f, argv[0..], env[0..]); defer p.deinit(); var ioContext = io.context(std.io.getStdIn().reader(), std.io.getStdOut().writer()); try std.testing.expectEqual(p.exec(&ioContext), pointerReturn{}); @@ -366,7 +369,8 @@ test "almost minimal" { var f = try field.Field.init_from_reader(std.testing.allocator, minimal); defer f.deinit(); const argv = [_][]const u8{"minimal"}; - var p = try Pointer.init(std.testing.allocator, f, argv[0..]); + const env = [_][*:0]const u8{"ENV=TEST"}; + var p = try Pointer.init(std.testing.allocator, f, argv[0..], env[0..]); defer p.deinit(); var ioContext = io.context(std.io.getStdIn().reader(), std.io.getStdOut().writer()); try std.testing.expectEqual(p.exec(&ioContext), pointerReturn{}); |