-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can't pass null to font loading functions? #56
Comments
The current implementation of static Janet cfun_LoadFontEx(int32_t argc, Janet *argv) {
janet_fixarity(argc, 3);
const char *fileName = janet_getcstring(argv, 0);
int fontSize = janet_getinteger(argv, 1);
JanetView ints = janet_getindexed(argv, 2);
int *raw_ints = janet_smalloc(sizeof(int) * ints.len);
for (int32_t i = 0; i < ints.len; i++) {
raw_ints[i] = janet_getinteger(ints.items, i);
}
Font *font = janet_abstract(&AT_Font, sizeof(Font));
*font = LoadFontEx(fileName, fontSize, raw_ints, ints.len);
janet_sfree(raw_ints);
return janet_wrap_abstract(font);
} May be that's fairly straight-forward to do though by examining the arguments and acting appropriately. |
May be a change along the following lines could work: diff --git a/src/text.h b/src/text.h
index c9712df..5ce4ce7 100644
--- a/src/text.h
+++ b/src/text.h
@@ -42,17 +42,21 @@ static Janet cfun_IsFontReady(int32_t argc, Janet *argv) {
}
static Janet cfun_LoadFontEx(int32_t argc, Janet *argv) {
- janet_fixarity(argc, 3);
+ janet_arity(argc, 2, 3);
const char *fileName = janet_getcstring(argv, 0);
int fontSize = janet_getinteger(argv, 1);
- JanetView ints = janet_getindexed(argv, 2);
- int *raw_ints = janet_smalloc(sizeof(int) * ints.len);
- for (int32_t i = 0; i < ints.len; i++) {
- raw_ints[i] = janet_getinteger(ints.items, i);
- }
Font *font = janet_abstract(&AT_Font, sizeof(Font));
- *font = LoadFontEx(fileName, fontSize, raw_ints, ints.len);
- janet_sfree(raw_ints);
+ if (argc == 2) {
+ *font = LoadFontEx(fileName, fontSize, NULL, 0);
+ } else {
+ JanetView ints = janet_getindexed(argv, 2);
+ int *raw_ints = janet_smalloc(sizeof(int) * ints.len);
+ for (int32_t i = 0; i < ints.len; i++) {
+ raw_ints[i] = janet_getinteger(ints.items, i);
+ }
+ *font = LoadFontEx(fileName, fontSize, raw_ints, ints.len);
+ janet_sfree(raw_ints);
+ }
return janet_wrap_abstract(font);
} So, when invoked with 2 arguments: (load-font-ex file-name font-size) the underlying (Note: compiled ok, but execution untested) |
Tried it out, seems to work.
Submitted #57. |
Address #56: two-argument load-font-ex
The Raylib documentation for
LoadFontEx
says to "use NULL for codepoints and 0 for codepointCount to load the default character set". Literally every example of Raylib font loading I could find does this, but it seems not to be possible with Janet's wrapping of the API.The text was updated successfully, but these errors were encountered: