Closed kojix2 closed 1 year ago
Yes. Because char
is signed 8 bit integer in C.
But we can pass one byte string directly with the following change:
diff --git a/ext/fiddle/conversions.c b/ext/fiddle/conversions.c
index 6e0ce36..f7b0b75 100644
--- a/ext/fiddle/conversions.c
+++ b/ext/fiddle/conversions.c
@@ -209,7 +209,11 @@ rb_fiddle_value_to_generic(int type, VALUE *src, fiddle_generic *dst)
dst->pointer = NUM2PTR(rb_Integer(*src));
break;
case TYPE_CHAR:
- dst->schar = (signed char)NUM2INT(*src);
+ if (RB_TYPE_P(*src) == RUBY_T_STRING && RSTRING_LEN(*src) == 1) {
+ dst->schar = RSTRING_PTR(*src)[0];
+ } else {
+ dst->schar = (signed char)NUM2INT(*src);
+ }
break;
case -TYPE_CHAR:
dst->uchar = (unsigned char)NUM2UINT(*src);
Thanks. I hadn't thought about changing the Fiddle. However, I understand what you are saying. Certainly this is something that many people would do on the Ruby code side .
My issue has been resolved, but as a suggestion for possible changes, shall I leave this issue open?
Yes, please.
Hi! I have a question about c char.
https://github.com/andlabs/libui/blob/fea45b2d5b75839be0af9acc842a147c5cba9295/ui.h#L767
c function
ruby method
I wonder if I should call ord like this?
Thank you.