From 761ea65d817693308da34be98ed22d7646db5395 Mon Sep 17 00:00:00 2001 From: Calvin Rose Date: Thu, 30 Apr 2020 23:21:26 -0500 Subject: [PATCH] Add fiber/roor and allow net/server to take a numeric port. --- CHANGELOG.md | 1 + src/core/fiber.c | 12 ++++++++++++ src/core/net.c | 7 ++++++- 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ff600b58..f65f9ec1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ All notable changes to this project will be documented in this file. ## Unreleased - ??? - Add `%M`, `%m`, `%N`, and `%n` formatters to formatting functions. These are the same as `%Q`, `%q`, `%P`, and `%p`, but will not truncate long values. +- Add `fiber/root`. - Add beta `net/` module to core for socket based networking. - Add the `parse` function to parse strings of source code more conveniently. - Add `jpm rule-tree` subcommand. diff --git a/src/core/fiber.c b/src/core/fiber.c index f67ae0cf..80e8e5e3 100644 --- a/src/core/fiber.c +++ b/src/core/fiber.c @@ -512,6 +512,12 @@ static Janet cfun_fiber_current(int32_t argc, Janet *argv) { return janet_wrap_fiber(janet_vm_fiber); } +static Janet cfun_fiber_root(int32_t argc, Janet *argv) { + (void) argv; + janet_fixarity(argc, 0); + return janet_wrap_fiber(janet_vm_root_fiber); +} + static Janet cfun_fiber_maxstack(int32_t argc, Janet *argv) { janet_fixarity(argc, 1); JanetFiber *fiber = janet_getfiber(argv, 0); @@ -579,6 +585,12 @@ static const JanetReg fiber_cfuns[] = { "\t:alive - the fiber is currently running and cannot be resumed\n" "\t:new - the fiber has just been created and not yet run") }, + { + "fiber/root", cfun_fiber_root, + JDOC("(fiber/root)\n\n" + "Returns the current root fiber. The root fiber is the oldest ancestor " + "that does not have a parent.") + }, { "fiber/current", cfun_fiber_current, JDOC("(fiber/current)\n\n" diff --git a/src/core/net.c b/src/core/net.c index 0ab84500..0d7c968d 100644 --- a/src/core/net.c +++ b/src/core/net.c @@ -453,7 +453,12 @@ JANET_NO_RETURN static void janet_sched_write_stringlike(JanetStream *stream, co static struct addrinfo *janet_get_addrinfo(Janet *argv, int32_t offset) { /* Get host and port */ const char *host = janet_getcstring(argv, offset); - const char *port = janet_getcstring(argv, offset + 1); + const char *port; + if (janet_checkint(argv[offset + 1])) { + port = (const char *)janet_to_string(argv[offset + 1]); + } else { + port = janet_getcstring(argv, offset + 1); + } /* getaddrinfo */ struct addrinfo *ai = NULL; struct addrinfo hints = {0};