├── .gitattributes ├── .gitignore ├── LICENSE ├── README.md ├── build.zig ├── src ├── lib.zig └── main.zig └── zig.mod /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /.zigmod 2 | /deps.zig 3 | /zig-* 4 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Meghan Denny 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # zig-range 2 | ![loc](https://sloc.xyz/github/nektro/zig-range) 3 | [![license](https://img.shields.io/github/license/nektro/zig-range.svg)](https://github.com/nektro/zig-range/blob/master/LICENSE) 4 | [![discord](https://img.shields.io/discord/551971034593755159.svg?logo=discord)](https://discord.gg/P6Y4zQC) 5 | 6 | A range function to loop over an index without an extra variable 7 | 8 | ## Usage 9 | ```zig 10 | for (range(10)) |_, i| { 11 | // 'i' will increment from 0 -> 9 12 | } 13 | ``` 14 | 15 | ## Building Example Program 16 | ``` 17 | $ zigmod fetch 18 | $ zig build 19 | ``` 20 | 21 | ## Built With 22 | - Zig Master & [Zigmod Package Manager](https://github.com/nektro/zigmod) 23 | 24 | ## License 25 | MIT 26 | -------------------------------------------------------------------------------- /build.zig: -------------------------------------------------------------------------------- 1 | const std = @import("std"); 2 | const deps = @import("./deps.zig"); 3 | 4 | pub fn build(b: *std.build.Builder) void { 5 | // Standard target options allows the person running `zig build` to choose 6 | // what target to build for. Here we do not override the defaults, which 7 | // means any target is allowed, and the default is native. Other options 8 | // for restricting supported target set are available. 9 | const target = b.standardTargetOptions(.{}); 10 | 11 | // Standard release options allow the person running `zig build` to select 12 | // between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall. 13 | const mode = b.standardReleaseOptions(); 14 | 15 | const exe = b.addExecutable("zig-range", "src/main.zig"); 16 | exe.setTarget(target); 17 | exe.setBuildMode(mode); 18 | deps.addAllTo(exe); 19 | exe.install(); 20 | 21 | const run_cmd = exe.run(); 22 | run_cmd.step.dependOn(b.getInstallStep()); 23 | if (b.args) |args| { 24 | run_cmd.addArgs(args); 25 | } 26 | 27 | const run_step = b.step("run", "Run the app"); 28 | run_step.dependOn(&run_cmd.step); 29 | } 30 | -------------------------------------------------------------------------------- /src/lib.zig: -------------------------------------------------------------------------------- 1 | /// Use this as a way to increment an index using a for loop. Works with both 2 | /// runtime and comptime integers. 3 | /// 4 | /// ```zig 5 | /// for (range(10)) |_, i| { 6 | /// // 'i' will increment from 0 -> 9 7 | /// } 8 | /// ``` 9 | pub fn range(len: usize) []const void { 10 | return @as([*]void, undefined)[0..len]; 11 | } 12 | -------------------------------------------------------------------------------- /src/main.zig: -------------------------------------------------------------------------------- 1 | const std = @import("std"); 2 | 3 | const range = @import("range").range; 4 | 5 | pub fn main() anyerror!void { 6 | std.log.info("All your codebase are belong to us.", .{}); 7 | 8 | for (range(10)) |_, i| { 9 | std.log.info("{}", .{i}); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /zig.mod: -------------------------------------------------------------------------------- 1 | id: tnj3qf44tpeq469x94qnu7jzus5n7sen9ewrrn8kldngbac0 2 | name: range 3 | main: src/lib.zig 4 | license: MIT 5 | description: A range function to loop over an index without an extra variable 6 | --------------------------------------------------------------------------------