aboutsummaryrefslogtreecommitdiff
path: root/src/polyfill.c
diff options
context:
space:
mode:
authorChloe Kudryavtsev <code@toast.bunkerlabs.net>2023-05-12 14:53:20 -0400
committerChloe Kudryavtsev <code@toast.bunkerlabs.net>2023-05-12 14:53:20 -0400
commit78e775a1b89c827ad2e96b73a723c7caf83f5a82 (patch)
tree11baea453275a2c9d1d22a64bcbdb9344be0cfb7 /src/polyfill.c
parentupdate many things (diff)
rewrite
Split it into multiple things. The new tests will actually reflect how you should use the native library.
Diffstat (limited to 'src/polyfill.c')
-rw-r--r--src/polyfill.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/polyfill.c b/src/polyfill.c
new file mode 100644
index 0000000..0d99916
--- /dev/null
+++ b/src/polyfill.c
@@ -0,0 +1,19 @@
+#include "date.h"
+
+#ifdef POLYFILL_CBYTES
+const char* janet_getcbytes(const Janet *argv, int32_t n) {
+ JanetByteView view = janet_getbytes(argv, n);
+ const char *cstr = (const char *)view.bytes;
+ if (strlen(cstr) != (size_t) view.len) {
+ janet_panic("bytes contain embedded 0s");
+ }
+ return cstr;
+}
+
+const char *janet_optcbytes(const Janet *argv, int32_t argc, int32_t n, const char *dflt) {
+ if (n >= argc || janet_checktype(argv[n], JANET_NIL)) {
+ return dflt;
+ }
+ return janet_getcbytes(argv, n);
+}
+#endif