Skip to content
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

Should default value for cstring be nil? #162

Open
StefanSalewski opened this issue Jul 26, 2021 · 4 comments
Open

Should default value for cstring be nil? #162

StefanSalewski opened this issue Jul 26, 2021 · 4 comments

Comments

@StefanSalewski
Copy link
Owner

proc gtk_entry_set_icon_from_icon_name(self: ptr Entry00; iconPos: EntryIconPosition;
    iconName: cstring) {.
    importc, libprag.}

proc setIconFromIconName*(self: Entry; iconPos: EntryIconPosition;
    iconName: cstring = "") =
  gtk_entry_set_icon_from_icon_name(cast[ptr Entry00](self.impl), iconPos, safeStringToCString(iconName))

I would guess yes.

@Dankr4d
Copy link

Dankr4d commented Jul 28, 2021

Makes sense. Then you can also get rid of the safeStringToCString call on set prefixed functions. To "clear" it, it's just called without passing the optional cstring, which maybe should be made clear for users in the readme.

@StefanSalewski
Copy link
Owner Author

I have done that fix and some more fixes.

You may test with

nimble uninstall gintro
nimble install gintro@#head

This is the upcomming v0.9.4 which I intend to ship this evening.

I have done a test for the gtk3 examples compiled with ARC, and for sdt compiled with ARC. Compiles and runs fine for me. Maybe I will do a few more test later this day.

@StefanSalewski
Copy link
Owner Author

We may have to revert this fix due to

nim-lang/Nim#18698

@Dankr4d
Copy link

Dankr4d commented Aug 21, 2021

I agree.
Adding more than 1k overloaded functions is maybe not the best, but I don't know how much the compile time would increase.
Also I think we shouldn't use Options, because it bloats the code readability (and is much more to write). Options may be helpful, but I don't think that they're required in this case.
I think the "old way" is currently the best solution, because the user also doesn't need to know anything about c null string pointers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants