Embedded programming language for Zig
1
fork

Configure Feed

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

add getcwd function

IamPyu 6690eeb6 08261695

+16 -13
+13 -9
runtime/lib/os.zig
··· 31 31 std.process.exit(num); 32 32 } 33 33 34 - // pub fn system(scope: *z.Scope, args: []const *z.Value) z.RuntimeError!*z.Value { 35 - // var sb = try scope.stringBuilder(); 36 - // defer sb.deinit(); 34 + pub fn getcwd(scope: *z.Scope, args: []const *z.Value) z.RuntimeError!*z.Value { 35 + var sb = try scope.stringBuilder(); 36 + defer sb.deinit(); 37 37 38 - // if (args.len != 1) { 39 - // try z.util.unexpectedArguments(&sb, .{ .expected = 1, .got = args.len }); 40 - // try scope.setException(sb.written()); 41 - // return z.RuntimeError.InvalidArguments; 42 - // } 38 + if (args.len != 0) { 39 + try z.util.unexpectedArguments(&sb, .{ .expected = 0, .got = args.len }); 40 + try scope.setException(sb.written()); 41 + return z.RuntimeError.InvalidArguments; 42 + } 43 43 44 - // } 44 + const cwd = std.process.getCwdAlloc(scope.allocator) catch return z.RuntimeError.External; 45 + defer scope.allocator.free(cwd); 46 + 47 + return try z.Value.initString(scope, cwd); 48 + }
+1
runtime/root.zig
··· 8 8 // -- OS -- 9 9 .{ "abort", z.Value.initNativeFunc(scope, os.abort) catch return }, 10 10 .{ "exit", z.Value.initNativeFunc(scope, os.exit) catch return }, 11 + .{ "getcwd", z.Value.initNativeFunc(scope, os.getcwd) catch return }, 11 12 }) catch return; 12 13 }
+2 -1
runtime/test.zexa
··· 1 1 (loadlib "zig-out/lib/libzexaruntime.so") 2 - (exit 2) 2 + (print (getcwd)) 3 + (exit 2)
-3
src/corelib.zig
··· 10 10 11 11 const util = @import("./util.zig"); 12 12 const SliceIterator = util.SliceIterator; 13 - // const StringBuilder = util.StringBuilder; 14 - 15 - const EXCEPTION_SIZE = 30; 16 13 17 14 /// Load the standard library for `scope` 18 15 pub fn loadCoreLibrary(scope: *Scope) !void {