aboutsummaryrefslogtreecommitdiff
path: root/src/pointer.zig
diff options
context:
space:
mode:
authorJulien Dessaux2022-08-13 01:23:32 +0200
committerJulien Dessaux2022-08-13 01:23:32 +0200
commit0f440dfb6fc21c460b6c621571921298d94eb1b0 (patch)
tree4a7011ce12f4bf611883ea9b645e59a213d301af /src/pointer.zig
parentImplemented the under funge command (diff)
downloadzigfunge98-0f440dfb6fc21c460b6c621571921298d94eb1b0.tar.gz
zigfunge98-0f440dfb6fc21c460b6c621571921298d94eb1b0.tar.bz2
zigfunge98-0f440dfb6fc21c460b6c621571921298d94eb1b0.zip
Add environment handling
Diffstat (limited to '')
-rw-r--r--src/pointer.zig10
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{});