-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New structure + scaffholds for a few drafts + completed docs aswell (#9)
* Added docs about different utils * added few sources * reorganization of the index file * Updated the structure of the project + added scaffhold for some docs * its now a beautiful link * added the info that embedFile is compile time
- Loading branch information
Showing
9 changed files
with
1,967 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,11 @@ | ||
* Zig Documentation | ||
The purpose of this repository is to document the features of the Zig language, as well as examples of its use. | ||
|
||
You can use this documentation with 2 different ways: | ||
- Using emacs org mode so that you can execute codes on the fly(litterate programming) | ||
- Opening the index.html file in your browser or navigating to our [[hosted guide][https://pismice.github.io/HEIG_ZIG/]] | ||
|
||
** Remarks | ||
- We are going to move all the "Sources" to the "Bilbliography" chapter using Zotero | ||
- Some exemples are not working with emacs yet | ||
- You might see a few TODO or empty chapters, those are the ones we are working on or plan to work on in the future |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,58 @@ | ||
** Reading external files | ||
There are multiple ways to do it in ZIG: | ||
1. @embedFile | ||
Simply going to embed the file in the binary. | ||
https://ziglang.org/documentation/master/#embedFile | ||
*** @embedFile | ||
This method is simply going to embed the file in the binary at compile time. | ||
|
||
2. Use an allocator to dynamically store the content of the file | ||
Beware that by using this method the path to the file is going to be relative to the file you are calling it from and that the file must be in the same package. | ||
|
||
By using the other methods below you can use a file from anywhere but relative to your root folder and not main.zig. | ||
#+begin_src zig :imports '(std) :main 'yes :testsuite 'no | ||
const input = @embedFile("input.txt"); | ||
std.debug.print("{s}", .{input}); | ||
#+end_src | ||
|
||
*** Use an allocator to dynamically store the content of the file | ||
By using the method: readToEndAlloc | ||
https://ziglang.org/documentation/master/std/#std.fs.File.readToEndAlloc | ||
#+begin_src zig :imports '(std) :main 'yes :testsuite 'no | ||
// Alocator | ||
var gp = std.heap.GeneralPurposeAllocator(.{ .safety = true }){}; | ||
defer gp.deinit(); | ||
const allocator = gp.allocator(); | ||
|
||
// Path | ||
var path_buffer: [std.fs.MAX_PATH_BYTES]u8 = undefined; | ||
const path = try std.fs.realpath("./input.txt", &path_buffer); | ||
|
||
// Open file | ||
const file = try std.fs.openFileAbsolute(path, .{}); | ||
defer file.close(); | ||
|
||
// Read | ||
const file_content = try file.readToEndAlloc(allocator, std.math.maxInt(usize)); | ||
defer allocator.free(file_content); | ||
#+end_src | ||
|
||
3. Read the file and put it in a buffer | ||
*** Read the file and put it in a buffer | ||
By using the method readAll | ||
https://ziglang.org/documentation/master/std/#std.fs.File.readAll | ||
#+begin_src zig :imports '(std) :main 'yes :testsuite 'no | ||
// Path | ||
var path_buffer: [std.fs.MAX_PATH_BYTES]u8 = undefined; | ||
const path = try std.fs.realpath("./input.txt", &path_buffer); | ||
|
||
// Open file | ||
const file = try std.fs.openFileAbsolute(path, .{}); | ||
defer file.close(); | ||
|
||
// Read | ||
var content_buffer: [1024]u8 = undefined; | ||
const size = try file.readAll(&content_buffer); | ||
|
||
std.debug.print("{s}", .{content_buffer[0..size]}); | ||
#+end_src | ||
|
||
TODO reading files with org babel doesnt work yet idk why | ||
|
||
TODO mettre des exemples pour chacun | ||
Sources: | ||
- https://ziglang.org/documentation/master/std/#std.fs.File.readToEndAlloc | ||
- https://ziglang.org/documentation/master/std/#std.fs.File.readAll | ||
- https://ziglang.org/documentation/master/#embedFile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
** HTTP from the std | ||
*** Description | ||
Http.zig: Dispatcher based, you create the dispatch chai (As far as I understand it) | ||
Zap: Callback based, we define certain callbacks, we configure from there | ||
Tokamak: Middleware (scoped) and DI Based | ||
Jetzig: Middleware (as part of a request chain) and Convention based | ||
|
||
https://www.reddit.com/r/reactjs/comments/16blsh3/how_do_i_use_react_with_an_express_application/ | ||
*** Exemples | ||
TODO |
Oops, something went wrong.