Thread overview | |||||
---|---|---|---|---|---|
|
February 19, 2021 raylib LoadTexture Mismatch between | ||||
---|---|---|---|---|
| ||||
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); while (!WindowShouldClose()){ ... } { "authors": [ "Me" ], "copyright": "Copyright © 2021, Me", "dependencies": { "raylib-d": "~>3.0.3" }, "description": "A minimal D application.", "libs": [ "raylib" ], "license": "proprietary", "name": "raylib_test" } Does anyone know why this is happening? |
February 19, 2021 Re: raylib LoadTexture Mismatch between | ||||
---|---|---|---|---|
| ||||
Posted in reply to Decabytes | 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 |
February 20, 2021 Re: raylib LoadTexture Mismatch between | ||||
---|---|---|---|---|
| ||||
Posted in reply to Steven Schveighoffer | On Friday, 19 February 2021 at 23:29:18 UTC, Steven Schveighoffer wrote: > On 2/19/21 5:26 PM, Decabytes wrote: > 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 I see now. Thank you Steve! |
Copyright © 1999-2021 by the D Language Foundation