View previous topic :: View next topic |
Author |
Message |
Silveri
Joined: 07 Jul 2011 Posts: 2
|
Posted: Thu Jul 07, 2011 3:15 pm Post subject: String conversions with functions in derelict.il.ilut |
|
|
Hi, I'm using Derelict2 (revision 556) with dmd 2.053 on WinXP, and I've started working with the DevIL bindings and have had a few odd problems.
First, when trying to import the library with:
Code: | import derelict.il.il; |
I got the following error:
Quote: | Error: module il is in file 'derelict\devil\il.d' which cannot be read |
I fixed this by renaming my "\import\derelict\il" directory to "import\derelict\devil" and used
Code: | import derelict.devil.il; |
instead.
Anyway, after doing that I got it right to call the following function without problem:
Code: | ilLoadImage("test.png"); |
(I haven't actually tested it's result yet, but it at least didn't segfault), but when I try a similar call with the following function (from devil.ilut):
Code: | ilutGLLoadImage("test.png"); |
it doesn't even compile, and throws the following error:
Quote: | Error: cannot implicitly convert expression ("test.png") of type string to char* |
I attempted to use toStringz(), but it threw an error about toStringz() only returning immutable(char)*, instead of char*. Regardless, I can convert it on my own and get it to compile at least (still segfaults, but I could've made a mistake with the initialization), but shouldn't the function wrapper be able to handle D2's native strings (like the call to ilLoadImage())?
PS: Except for these few oddities the Derelict library seems to be quite excellent, and has made OpenGL programming much easier. Thanks, it's much appreciated! |
|
Back to top |
|
|
aldacron
Joined: 05 May 2004 Posts: 1322 Location: Seoul, South Korea
|
Posted: Thu Jul 07, 2011 10:43 pm Post subject: Re: String conversions with functions in derelict.il.ilut |
|
|
Silveri wrote: |
First, when trying to import the library with:
Code: | import derelict.il.il; |
I got the following error:
Quote: | Error: module il is in file 'derelict\devil\il.d' which cannot be read |
I fixed this by renaming my "\import\derelict\il" directory to "import\derelict\devil" and used
Code: | import derelict.devil.il; |
instead. |
That was from a silly mistake in the make file. It's fixed in SVN.
Quote: | Anyway, after doing that I got it right to call the following function without problem:
Code: | ilLoadImage("test.png"); |
(I haven't actually tested it's result yet, but it at least didn't segfault), but when I try a similar call with the following function (from devil.ilut):
Code: | ilutGLLoadImage("test.png"); |
it doesn't even compile, and throws the following error:
Quote: | Error: cannot implicitly convert expression ("test.png") of type string to char* |
I attempted to use toStringz(), but it threw an error about toStringz() only returning immutable(char)*, instead of char*. Regardless, I can convert it on my own and get it to compile at least (still segfaults, but I could've made a mistake with the initialization), but shouldn't the function wrapper be able to handle D2's native strings (like the call to ilLoadImage())? |
First, Derelict has no function "wrappers". All of the bound functions are pointers to C functions, so they use the C calling convention and don't know anything about D strings.
Second, all of the function pointers in Derelict are declared to match the C declaration as closely as possible. ilutGLoadImage is declared in C to take a parameter of type ILstring, whereas liLoadImage uses ILconst_string, so Derelict does the same. ILstring is an alias to char*, and ILconst_string is aliased (in D2) as const(char)*.That's why the former fails with toStringz strings, but the latter succeeds. Changing the declaration of ilutGLLoadImage to take an ILconst_string would be bad form, because then it wouldn't match the C declaration.
Quote: | PS: Except for these few oddities the Derelict library seems to be quite excellent, and has made OpenGL programming much easier. Thanks, it's much appreciated! |
You're welcome! And thank you for reporting your problems. _________________ The One With D | The One With Aldacron | D Bits |
|
Back to top |
|
|
Silveri
Joined: 07 Jul 2011 Posts: 2
|
Posted: Fri Jul 08, 2011 8:27 am Post subject: Re: String conversions with functions in derelict.il.ilut |
|
|
Quote: | First, Derelict has no function "wrappers". All of the bound functions are pointers to C functions, so they use the C calling convention and don't know anything about D strings.
Second, all of the function pointers in Derelict are declared to match the C declaration as closely as possible. ilutGLoadImage is declared in C to take a parameter of type ILstring, whereas liLoadImage uses ILconst_string, so Derelict does the same. ILstring is an alias to char*, and ILconst_string is aliased (in D2) as const(char)*.That's why the former fails with toStringz strings, but the latter succeeds. Changing the declaration of ilutGLLoadImage to take an ILconst_string would be bad form, because then it wouldn't match the C declaration. |
Okay, that makes sense; thanks for the explanation. And I've got it working fine now (even eventually with the unicode version of the DevIL dll's).
BTW, I saw a ticket (http://www.dsource.org/projects/derelict/ticket/30) about possibly setting a directory from which the libraries should load. Is there any news on that front? It seems like an awesome and useful idea. |
|
Back to top |
|
|
aldacron
Joined: 05 May 2004 Posts: 1322 Location: Seoul, South Korea
|
Posted: Fri Jul 08, 2011 9:26 am Post subject: Re: String conversions with functions in derelict.il.ilut |
|
|
It's on my todo list. It's something I think would be useful, too.
For me, development on Derelict for a long time has been a "when I have the time and feel like it" kind of thing. I try to get bugs squashed as soon as I hear of them, but as for updates and new features it's been rather slow. Derelict 2 has been "in development" for longer than I care to think about.
But, since you're not the first person to ask for it, I'll see about looking into it this weekend. No promises, though! _________________ The One With D | The One With Aldacron | D Bits |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|