bugfixes for ncurses library
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Wed, 27 Apr 2022 03:11:06 +0000 (22:11 -0500)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Wed, 27 Apr 2022 03:11:06 +0000 (22:11 -0500)
modules/ncurses/module.onyx
src/onyx_runtime.c
src/polymorph.h

index 4b1ca1c199de41bc114976f28356df79ce9b5e7e..3ca8d6b9bf6933db8753bea761e98baa6c2386af 100644 (file)
@@ -3,33 +3,6 @@ package ncurses
 use package core {cptr, conv, string}
 
 
-WINDOW :: #distinct u64
-SCREEN :: #distinct u64
-
-chtype :: u32
-
-attr_t :: u32
-A_NORMAL :: 0
-A_ATTRIBUTES :: 0xffffff00
-A_CHARTEXT   :: 0xff
-A_COLOR      :: 0xff00
-A_STANDOUT   :: 0x00010000
-A_UNDERLINE  :: 0x00020000
-A_REVERSE    :: 0x00040000
-A_BLINK      :: 0x00080000
-A_DIM        :: 0x00100000
-A_BOLD       :: 0x00200000
-A_ALTCHARSET :: 0x00400000
-A_INVIS      :: 0x00800000
-A_PROTECT    :: 0x01000000
-A_HORIZONTAL :: 0x02000000
-A_LEFT       :: 0x04000000
-A_LOW        :: 0x08000000
-A_RIGHT      :: 0x10000000
-A_TOP        :: 0x20000000
-A_VERTICAL   :: 0x40000000
-A_ITALIC     :: 0x80000000
-
 #library "onyx_ncurses"
 #foreign "onyx_ncurses" {
 
@@ -308,12 +281,30 @@ getparyx  :: __get_par_yx
 getbegyx  :: __get_beg_yx
 getmaxyx  :: __get_max_yx
 
-ogetstr :: ($max_length: i32) -> str {
+ogetstr :: ($max_length: i32 = 1024) => {
     buf: [max_length] u8;
     err := getnstr(buf);
     return string.alloc_copy(string.from_cstr(~~ buf));
 }
 
+mvogetstr :: (y, x: i32, $max_length: i32 = 1024) => {
+    buf: [max_length] u8;
+    err := mvgetnstr(y, x, buf);
+    return string.alloc_copy(string.from_cstr(~~ buf));
+}
+
+wogetstr :: (w: WINDOW, $max_length: i32 = 1024) => {
+    buf: [max_length] u8;
+    err := wgetnstr(w, buf);
+    return string.alloc_copy(string.from_cstr(~~ buf));
+}
+
+mvwogetstr :: (w: WINDOW, y, x: i32, $max_length: i32 = 1024) => {
+    buf: [max_length] u8;
+    err := mvwgetnstr(w, y, x, buf);
+    return string.alloc_copy(string.from_cstr(~~ buf));
+}
+
 printw :: (fmt: str, args: ..any) {
     buf: [1024] u8;
     to_output := conv.format_va(buf, fmt, args);
@@ -338,6 +329,31 @@ mvwprintw :: (w: WINDOW, y, x: i32, fmt: str, args: ..any) {
     mvwaddnstr(w, y, x, to_output);
 }
 
+WINDOW :: #distinct u64
+SCREEN :: #distinct u64
+chtype :: u32
+attr_t :: u32
+
+A_NORMAL :: 0
+A_ATTRIBUTES :: 0xffffff00
+A_CHARTEXT   :: 0xff
+A_COLOR      :: 0xff00
+A_STANDOUT   :: 0x00010000
+A_UNDERLINE  :: 0x00020000
+A_REVERSE    :: 0x00040000
+A_BLINK      :: 0x00080000
+A_DIM        :: 0x00100000
+A_BOLD       :: 0x00200000
+A_ALTCHARSET :: 0x00400000
+A_INVIS      :: 0x00800000
+A_PROTECT    :: 0x01000000
+A_HORIZONTAL :: 0x02000000
+A_LEFT       :: 0x04000000
+A_LOW        :: 0x08000000
+A_RIGHT      :: 0x10000000
+A_TOP        :: 0x20000000
+A_VERTICAL   :: 0x40000000
+A_ITALIC     :: 0x80000000
 
 COLOR_BLACK    :: 0
 COLOR_RED      :: 1
index 7e871e2beca24cb423a88d4c8adae2258d39bd83..33410e0238507a9f66a02fab62656308599d9f4c 100644 (file)
@@ -402,6 +402,8 @@ ONYX_DEF(__kill_thread, (WASM_I32), (WASM_I32)) {
     bh_arr_each(OnyxThread, thread, threads) {
         if (thread->id == thread_id) {
             #ifdef _BH_LINUX
+            // This leads to some weirdness and bugs...
+            //
             pthread_kill(thread->thread, SIGKILL);
             #endif
 
index 744cbfa43719056af09dfb96e65af9eb4fd3955b..34b4ced4f24c31dce51155fa3288d11a83fbe65d 100644 (file)
@@ -408,6 +408,12 @@ static AstTyped* lookup_param_in_arguments(AstFunction* func, AstPolyParam* para
             }
         }
 
+        if (param->idx <= (u64) bh_arr_length(func->params)) {
+            if (func->params[param->idx].default_value) {
+                return (AstTyped *) func->params[param->idx].default_value;
+            }
+        }
+
         // CLEANUP
         if (err_msg) *err_msg = "Not enough arguments to polymorphic procedure. This error message may not be entirely right.";