raylib LoadTexture Mismatch between

Steven Schveighoffer schveiguy at gmail.com
Fri Feb 19 23:29:18 UTC 2021


On 2/19/21 5:26 PM, Decabytes wrote:
> Dlang and curly brace language noob here. I'm trying to work with the 
> raylib-d library. I downloaded raylib-d using dub, and I installed 
> raylib with my package manager on Manjaro.  I'm getting a mismatch in 
> the arguments I'm passing to LoadTexture.
> 
> source/app.d(7,32): Error: function raylib.LoadTexture(const(char)* 
> fileName) is not callable using argument types (string)
> 
> In the raylib-d docs/cheatsheet it says LoadTexture uses a string as an 
> argument.The original raylib docs/cheatsheet says it's a const(char)* 
> value. So it seems I'm using the C version instead of the D version? The 
> relevant section of the code below is
> 
> import raylib;
> 
> void main()
> {
>      InitWindow(800, 600, "Hello, Raylib-D!");
>      string fname = "assets/tile_022.png";
>      Texture2D player = LoadTexture(fname);

raylib-d does not have D wrappers for everything. You are supposed to 
use the C functions.

D's string literals are null-terminated. However, the language only 
allows actual literals to be implicitly converted to immutable(char)* as 
literals, not as general strings.

So this will work:

Texture2D player = LoadTexture("assets/tile_022.png");

And this will work too (because string literals are null terminated):

string fname = "assets/tile_022.png";
Texture2D player = LoadTexture(fname.ptr);

If you have a string that you aren't sure is a string literal, you can 
use std.string.toStringz to convert it, but this will allocate another 
string (possibly).

import std.string;
Texture2D player = LoadTexture(fname.toStringz);

-Steve


More information about the Digitalmars-d-learn mailing list