summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorOmniscient <17525998+omnisci3nce@users.noreply.github.com>2024-02-25 17:36:36 +1100
committerOmniscient <17525998+omnisci3nce@users.noreply.github.com>2024-02-25 17:36:36 +1100
commit06ed6edcedf30fd8f7e036fffe8f81e8ca89d4b0 (patch)
treef5ae75e431817a53ee5725b4c0d6f3e61b15a664 /examples
parent109b6dd1881d90915e972f0d263a032bd262adb5 (diff)
parentb5b7cea24c46d28a4b72bc18ca8ccb2d532007d3 (diff)
Merge branch 'master' of github.com:omnisci3nce/celeritas-core
Diffstat (limited to 'examples')
-rw-r--r--examples/main_loop/ex_main_loop.c2
-rw-r--r--examples/standard_lib/ex_std.c30
2 files changed, 31 insertions, 1 deletions
diff --git a/examples/main_loop/ex_main_loop.c b/examples/main_loop/ex_main_loop.c
index 2afc3c0..3b2354a 100644
--- a/examples/main_loop/ex_main_loop.c
+++ b/examples/main_loop/ex_main_loop.c
@@ -19,4 +19,4 @@ int main() {
}
return 0;
-} \ No newline at end of file
+}
diff --git a/examples/standard_lib/ex_std.c b/examples/standard_lib/ex_std.c
new file mode 100644
index 0000000..9d474de
--- /dev/null
+++ b/examples/standard_lib/ex_std.c
@@ -0,0 +1,30 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include "file.h"
+#include "str.h"
+
+int main() {
+ // Examples of how to work with arenas and strings
+ size_t arena_size = 1024;
+ arena scratch = arena_create(malloc(arena_size), arena_size);
+ arena* a = &scratch;
+
+ str8 hello = str8lit("Hello World");
+
+ // this works but we should be careful because str8 is not *guaranteed* to point to
+ // a null-terminated string
+ printf("String before: '%s' (null-terminated: %s) \n ", hello.buf,
+ str8_is_null_term(hello) ? "true" : "false");
+
+ char* c = str8_to_cstr(&scratch, hello);
+
+ printf("String after: %s\n", c);
+
+ str8_opt test_file = str8_from_file(&scratch, str8lit("assets/shaders/ui_rect.vert"));
+ if (test_file.has_value) {
+ printf("Contents: %.*s \n", (int)test_file.contents.len, test_file.contents.buf);
+ printf("Null-terminated: %s\n", str8_is_null_term(test_file.contents) ? "true" : "false");
+ }
+
+ return 0;
+}