Embedded programming language for Zig
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Add `loadFile` to `State`

IamPyu d3608b4d 005d601f

+11 -3
+1 -1
runtime/root.zig
··· 1 1 const std = @import("std"); 2 2 const z = @import("./z.zig"); 3 3 4 - const os = @import("./lib/os.zig"); 4 + pub const os = @import("./lib/os.zig"); 5 5 6 6 pub export fn load(scope: *z.Scope) void { 7 7 scope.insertRegistry(&.{
+10 -2
src/root.zig
··· 63 63 return &self.env.primary_scope; 64 64 } 65 65 66 - /// Load `buf` into the frontend for execution 66 + /// Load `buf` into a frontend for execution 67 67 pub fn loadString(self: *Self, buf: []const u8) !void { 68 68 self.frontend = try Frontend.init(self.allocator, &self.env, buf); 69 69 } 70 70 71 + /// Load the contents of `reader` into a frontend for execution 72 + pub fn loadFile(self: *Self, reader: *std.Io.Reader) !void { 73 + const contents = try reader.allocRemaining(self.allocator, .unlimited); 74 + defer self.allocator.free(contents); 75 + 76 + try self.loadString(contents); 77 + } 78 + 71 79 /// Load the library `lib` 72 - pub fn loadLibrary(self: *Self, lib: lang.Library) !void { 80 + pub fn loadLibrary(self: *Self, lib: lang.Library) lang.RuntimeError!void { 73 81 try self.getScope().loadLibrary(lib); 74 82 } 75 83