Re: BetterC issues with ErupteD Vulkan binding typedef handles
[snip] Forgot to add another question. The mentioned error message is not too helpful in locating the real offended code. Is there a way to get more information or additional hints about the actual cause of the problem?
Re: BetterC issues with ErupteD Vulkan binding typedef handles
On Sunday, 20 December 2020 at 15:52:39 UTC, Adam D. Ruppe wrote: On Sunday, 20 December 2020 at 15:45:59 UTC, ParticlePeter wrote: VkSemaphore[] wait_semaphores = [], // error: TypeInfo required does it still error if you just use = null? they work the same way but might avoid the annoying error. Wow, it does, that was unexpected and unexpectedly hassle free, thanks a lot :-)
BetterC issues with ErupteD Vulkan binding typedef handles
Hello, I am experimenting with betterC and Vulkan through Erupted [0] binding, but unfortunately I find myself hunting down these kind of errors: ..\ErupteD\source\erupted\types.d-mixin-77(77,1): Error: `TypeInfo` cannot be used with -betterC The issue is with Vulkan type handles. One such error occurs when a function's parameter list contains an optional slice of such handles, e.g.: void queueSubmit( VkQueuequeue, VkCommandBuffer[] command_buffers, VkSemaphore[] wait_semaphores = [], // error: TypeInfo required VkPipelineStageFlags[] wait_dest_stage_masks = [], // ok, not a handle VkSemaphore[] signal_semaphores = [] // error: TypeInfo required ) { .. } A possible workaround which I found is: VkSemaphore[] wait_semaphores = ( const VkSemaphore[] ).init, but this feels more like fighting a symptom instead of getting rid of the cause. I am wondering if there is a better way to translate these C typedefs to D: // from vulkan_core.h [1] // ... #define VK_DEFINE_HANDLE(object) typedef struct object##_T* object; #if !defined(VK_DEFINE_NON_DISPATCHABLE_HANDLE) #if defined(__LP64__) || defined(_WIN64) || (defined(__x86_64__) && !defined(__ILP32__) ) || defined(_M_X64) || defined(__ia64) || defined (_M_IA64) || defined(__aarch64__) || defined(__powerpc64__) #define VK_DEFINE_NON_DISPATCHABLE_HANDLE(object) typedef struct object##_T *object; #else #define VK_DEFINE_NON_DISPATCHABLE_HANDLE(object) typedef uint64_t object; #endif #endif // ... VK_DEFINE_HANDLE(VkQueue) VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkSemaphore) // ... Correspondingly to the C typedefs: // from erupted/types.d [2] // ... enum VK_DEFINE_HANDLE( string name ) = "struct " ~ name ~ "_handle; alias " ~ name ~ " = " ~ name ~ "_handle*;"; version( X86_64 ) { alias VK_DEFINE_NON_DISPATCHABLE_HANDLE( string name ) = VK_DEFINE_HANDLE!name; enum VK_NULL_ND_HANDLE = null; } else { enum VK_DEFINE_NON_DISPATCHABLE_HANDLE( string name ) = "alias " ~ name ~ " = ulong;"; enum VK_NULL_ND_HANDLE = 0uL; } // ... mixin( VK_DEFINE_HANDLE!q{VkQueue} ); mixin( VK_DEFINE_NON_DISPATCHABLE_HANDLE!q{VkSemaphore} ); // ... I am running building for x64, would anyone know a smoother betterC approach to these typedefs? [0] https://github.com/ParticlePeter/ErupteD [1] https://github.com/KhronosGroup/Vulkan-Headers/blob/master/include/vulkan/vulkan_core.h [2] https://github.com/ParticlePeter/ErupteD/blob/master/source/erupted/types.d
Re: dub run subPackage by default
On Tuesday, 1 September 2020 at 14:45:43 UTC, Andre Pany wrote: On Tuesday, 1 September 2020 at 11:45:34 UTC, ParticlePeter wrote: [snip] I have a enhancement for dub in my mind, which would also solve your issue. Similiar to setup.py in python you would be able to define an entry point in dub.json. "entryPoints": {"foo":"subPackageName"} Command `dub install mypackage` would create a batch file/bash script with name foo containing the command `dub run mypackage:subPackageName -- %*`. Unfortunately I do not have any time to work on this. Kind regards Andre So, I take it that such a feature does not exist already. Your suggestion sounds nice, but why do you think it would be necessary to go through a batch file or script? I think it should be possible from within dub, to feed the chosen compiler backend with the proper commands to either build or run the appropriate entryPoint. - PP
dub run subPackage by default
Hello, I have a targetType sourceLibrary and demonstrate its usage through a subPackage. For the library itself 'dub run' is meaningless, but not for the subPackage. Is there a way to tell dub through dub.sdl or dub.json to build and run a specific subPackage by default, without having to call: 'dub run mySourceLib:myPackage' ? Why do I want this? Because I use Sublime Text build systems to execute a dub build/run. As far as I can see I would have to set up a build version for any package:subPackeg combination. - PP
Re: How to create DDoc for string mixin generated functions?
On Thursday, 28 November 2019 at 14:00:56 UTC, Adam D. Ruppe wrote: On Wednesday, 27 November 2019 at 15:14:21 UTC, ParticlePeter wrote: I judged it being the least feasible to produce appropriate doc comments. How could this work? Just like: /// Forwards members to [Whatever] auto opDispatch.. and then the documentation shows that with the link so they can refer to the other thing easily enough. That's what I did on my thing for example http://dpldocs.info/experimental-docs/arsd.dom.ElementCollection.opDispatch.html (possible I could make my doc gen recognize the pattern and paste in generated docs too, but I personally like the link enough) That would not work nicely in my case. Firstly my inner structs are from foreign code (vulkan structs through erupted binding) for which I do not create documentation. Secondly, I am skipping some of the inner struct members. Basically I use a template to produce the string mixin. The template has an VarArg list accepting inner struct member names to be skipped. Hence it would be better to actually create individual doc comments for each forwarding property instantiation.
Re: How to create DDoc for string mixin generated functions?
On Wednesday, 27 November 2019 at 15:14:21 UTC, ParticlePeter wrote: On Tuesday, 26 November 2019 at 19:41:26 UTC, Adam D. Ruppe wrote: On Tuesday, 26 November 2019 at 19:27:55 UTC, ParticlePeter wrote: In may case I use the string mixin to forward outer struct property calls to members of an inner struct. Did you try opDispatch btw? It might be simpler to implement and to document. No I didn't, I judged it being the least feasible to produce appropriate doc comments. How could this work? Maybe not asked precisely enough. Its clear how op dispatch works, but how could I create different documentation for different dispatch instantiations?
Re: How to create DDoc for string mixin generated functions?
On Tuesday, 26 November 2019 at 19:41:26 UTC, Adam D. Ruppe wrote: On Tuesday, 26 November 2019 at 19:27:55 UTC, ParticlePeter wrote: In may case I use the string mixin to forward outer struct property calls to members of an inner struct. Did you try opDispatch btw? It might be simpler to implement and to document. No I didn't, I judged it being the least feasible to produce appropriate doc comments. How could this work?
Re: How to create DDoc for string mixin generated functions?
On Tuesday, 26 November 2019 at 13:02:39 UTC, Jonathan M Davis wrote: On Monday, November 25, 2019 9:25:08 AM MST ParticlePeter via ... - Jonathan M Davis Thanks for that thorough explanation. In may case I use the string mixin to forward outer struct property calls to members of an inner struct. I'll try to refactor the string mixin as template mixin. From top of my head I see one complication. The parameter name to the property would change and that means its name in the doc comment should change as well. Any ideas how to solve that? Or would it be possible only with same param name for all the property instantiations?
Anything like HPPTOD out there?
I would like to auto convert c++ header to d module. Is there some project aiming for this? I know of VisualD c++ to d conversion wizzard [1] and LLVM tooling based CPP2D [2], both of them aiming for whole cpp conversion. But I a searching for something lightweight like HTOD extended to C++. [1] https://rainers.github.io/visuald/visuald/CppConversion.html [2] https://github.com/lhamot/CPP2D
How to create DDoc for string mixin generated functions?
I am producing a bunch of functions/methods through string mixins. I also generated DDoc comments for those functions, in the hope that they would produce proper documentation, but they don't. So how can this be accomplished?
Re: mixed in struct constructor is ignored when another (non mixed in) constructor is specified
On Monday, 26 February 2018 at 14:42:58 UTC, Adam D. Ruppe wrote: On Monday, 26 February 2018 at 14:38:22 UTC, ParticlePeter wrote: This cool, I didn't know that we can name mixins when instantiating but also never taught that there could be any purpose for naming. Works, thanks. oh yes, there's a lot of cool things with mixin. You might want to skim my tip of the week index: http://arsdnet.net/this-week-in-d/totw-index.html and see if more jump out at you. template mixins have behavior that look stupid until you understand why - then it gets pretty nice. Like the naming and overloading rules allow selective overriding and integration once you know how. Ok and that is an awesome link as well, I wished having this on several occasions. By the way, I also remembered reading your tip already once ... yeah, while reading it again. Anyway, thanks.
Re: mixed in struct constructor is ignored when another (non mixed in) constructor is specified
On Monday, 26 February 2018 at 14:02:56 UTC, Adam D. Ruppe wrote: On Monday, 26 February 2018 at 12:30:24 UTC, ParticlePeter wrote: Is this expected behavior? yes sort of, but there are bugs associated with it too... I wrote about this in the "Tip of the Week" section here before http://arsdnet.net/this-week-in-d/2016-feb-07.html there's a workaround there and a bit more explanation of weirdness. This cool, I didn't know that we can name mixins when instantiating but also never taught that there could be any purpose for naming. Works, thanks.
Re: mixed in struct constructor is ignored when another (non mixed in) constructor is specified
On Monday, 26 February 2018 at 12:47:48 UTC, Jonathan M Davis wrote: On Monday, February 26, 2018 12:30:24 ParticlePeter via Digitalmars-d-learn wrote: mixin template Common() { private int m_member; this( int m ) { m_member = m; } } struct Foo { mixin Common; } struct Bar { mixin Common; this( int m, float n ) { m_member = m * n; } } auto foo = Foo(1); // ok auto b_1 = Bar( 1, 2 ); // ok auto b_2 = Bar( 3 ); // Error: constructor main.Bar.this (int m, int n) is not callable using argument types (int) Is this expected behavior? Yes. Stuff that's mixed in is treated as having a different scope than other mixins or stuff that wasn't mixed in. To quote towards the bottom of here: https://dlang.org/spec/template-mixin.html "Alias declarations can be used to overload together functions declared in different mixins" It gives an example of mixin Foo!() F; mixin Bar!() B; alias func = F.func; alias func = B.func; I don't know if you can do the same thing with constructors or not, though alias this statements don't allow the = syntax. So, maybe that won't conflict, and it will work to do something like alias this = Common.this; If that doesn't work, then it seems like a good enhancement request. - Jonathan M Davis Thanks for clarification, unfortunately your suggestion doesn't work. Since when is alias this = something; supposed to work? alias Common.this this; doesn't work as well and following also not: struct Baz { Foo foo; alias foo this; this( int m, int n ) { m_member = m * n; } } auto baz = Baz(1); // Error, same as above Not sure if I do require an enhancement, I just stumbled on that and was wondering.
mixed in struct constructor is ignored when another (non mixed in) constructor is specified
mixin template Common() { private int m_member; this( int m ) { m_member = m; } } struct Foo { mixin Common; } struct Bar { mixin Common; this( int m, float n ) { m_member = m * n; } } auto foo = Foo(1); // ok auto b_1 = Bar( 1, 2 ); // ok auto b_2 = Bar( 3 ); // Error: constructor main.Bar.this (int m, int n) is not callable using argument types (int) Is this expected behavior?
Re: How to instantiate a template struct with a template constructor without relying on auto deduction?
On Wednesday, 21 February 2018 at 14:29:31 UTC, Simen Kjærås wrote: On Wednesday, 21 February 2018 at 14:11:10 UTC, ParticlePeter wrote: struct Foo(T) { T bar; this(S)(S s) { bar = convert(s); } } auto foo = Foo!int(some_float); this works because S is deduced as typeof(some_float), but how would I instantiate the struct without relying on auto deduction? Suppose we would have this kind of constructor where auto deduction is not possible: this(int n)(float f) { static foreach( i; 0..n) { do_some_ctfe_magic;} } How to instantiate Foo then? No can do. The solution is to use a factory function: Feared the same, thanks. struct Foo(T) { static Foo create(int n)(float f) { Foo result; static foreach( i; 0..n) { do_some_ctfe_magic;} return result; } } -- Simen I will consider this, actually I use something quite close, but my create is not static and does not return anything. It simply initializes the struct after it has been constructed with the default ctor. The templated user ctor would have been nice, though.
How to instantiate a template struct with a template constructor without relying on auto deduction?
struct Foo(T) { T bar; this(S)(S s) { bar = convert(s); } } auto foo = Foo!int(some_float); this works because S is deduced as typeof(some_float), but how would I instantiate the struct without relying on auto deduction? Suppose we would have this kind of constructor where auto deduction is not possible: this(int n)(float f) { static foreach( i; 0..n) { do_some_ctfe_magic;} } How to instantiate Foo then?
Re: Linker error since upgrade to DMD 2.077.1: fatal error C1905: Front end and back end not compatible
On Sunday, 17 December 2017 at 20:09:02 UTC, ParticlePeter wrote: On Sunday, 17 December 2017 at 19:29:00 UTC, ParticlePeter wrote: On Sunday, 17 December 2017 at 19:16:02 UTC, ParticlePeter [snip] LINKCMD=%VCINSTALLDIR%\bin\HostX32\x64\link.exe or LINKCMD=%VCINSTALLDIR%\bin\HostX64\x64\link.exe First one is BS, of course it must be: LINKCMD=%VCINSTALLDIR%\bin\HostX86\x64\link.exe Filed a bug: https://issues.dlang.org/show_bug.cgi?id=18098
Re: Linker error since upgrade to DMD 2.077.1: fatal error C1905: Front end and back end not compatible
On Sunday, 17 December 2017 at 19:29:00 UTC, ParticlePeter wrote: On Sunday, 17 December 2017 at 19:16:02 UTC, ParticlePeter wrote: On Sunday, 17 December 2017 at 17:56:47 UTC, John wrote: I don't think so, all that would need to be changed is this line: https://github.com/dlang/dmd/blob/v2.077.1/ini/windows/bin/sc.ini#L53 Not very many people use it I guess if it's been there for 8 months lol. Hm, actually that line IS uncommented in my installed sc.ini and VCINSTALLDIR is properly detected. Any idea what still might go wrong? Think I figured it out. For me it works when changing that particular line to: LINKCMD=%VCINSTALLDIR%\bin\HostX32\x64\link.exe or LINKCMD=%VCINSTALLDIR%\bin\HostX64\x64\link.exe First one is BS, of course it must be: LINKCMD=%VCINSTALLDIR%\bin\HostX86\x64\link.exe
Re: Linker error since upgrade to DMD 2.077.1: fatal error C1905: Front end and back end not compatible
On Sunday, 17 December 2017 at 19:16:02 UTC, ParticlePeter wrote: On Sunday, 17 December 2017 at 17:56:47 UTC, John wrote: I don't think so, all that would need to be changed is this line: https://github.com/dlang/dmd/blob/v2.077.1/ini/windows/bin/sc.ini#L53 Not very many people use it I guess if it's been there for 8 months lol. Hm, actually that line IS uncommented in my installed sc.ini and VCINSTALLDIR is properly detected. Any idea what still might go wrong? Think I figured it out. For me it works when changing that particular line to: LINKCMD=%VCINSTALLDIR%\bin\HostX32\x64\link.exe or LINKCMD=%VCINSTALLDIR%\bin\HostX64\x64\link.exe
Re: Linker error since upgrade to DMD 2.077.1: fatal error C1905: Front end and back end not compatible
On Sunday, 17 December 2017 at 17:56:47 UTC, John wrote: I don't think so, all that would need to be changed is this line: https://github.com/dlang/dmd/blob/v2.077.1/ini/windows/bin/sc.ini#L53 Not very many people use it I guess if it's been there for 8 months lol. Hm, actually that line IS uncommented in my installed sc.ini and VCINSTALLDIR is properly detected. Any idea what still might go wrong?
Re: Linker error since upgrade to DMD 2.077.1: fatal error C1905: Front end and back end not compatible
On Sunday, 17 December 2017 at 16:40:46 UTC, John wrote: Yah the sc.ini file is wrong for Environment64. [Environment64] LIB="%@P%\..\lib64" . . . ; Windows installer uncomments the version detected LINKCMD=%VCINSTALLDIR%\bin\HostX86\x86\link.exe Thanks! Is this a known, reported bug?
Re: Linker error since upgrade to DMD 2.077.1: fatal error C1905: Front end and back end not compatible
On Sunday, 17 December 2017 at 15:57:08 UTC, ParticlePeter wrote: I upgraded from DMD 2.074.1 (!) to 2.077.1 and tried to compile a mixed c++/d project (DMD links to one c++ lib). Here is the full error message: Forgot most important info, ita an x64 project those used VS linker by default afaik.
Linker error since upgrade to DMD 2.077.1: fatal error C1905: Front end and back end not compatible
I upgraded from DMD 2.074.1 (!) to 2.077.1 and tried to compile a mixed c++/d project (DMD links to one c++ lib). Here is the full error message: fatal error C1905: Front end and back end not compatible (must target same processor). LINK : fatal error LNK1257: code generation failed Error: linker exited with status 1257 dmd failed with exit code 1257. No such problems with my previous DMD version. What has changed with linking since then? (Skimmed through changelogs but found nothing). I found a workaround with specifying LINKCMD64 to my VS 2017 linker, but this is not a viable solution. The project must build with DMD on any system with VS installed without me knowing its exact location. What can I do to make it run out of the box and without the link command specified?
Re: How you guys go about -BetterC Multithreading?
On Friday, 10 November 2017 at 11:55:57 UTC, Guillaume Piolat wrote: For now we do have some @nogc alternatives for mutex, condition variables, thread-pool, file reading, etc... (dplug:core package) for use with the runtime disabled - the middle ground that's way more usable than -betterC. They may, or not, be applicable to -betterC. Your thread module (among others) is an amazing read and a very nice starting point for my endeavor. Thanks for pointing me in this direction!
Re: How you guys go about -BetterC Multithreading?
On Thursday, 9 November 2017 at 12:19:00 UTC, Petar Kirov [ZombineDev] wrote: On Thursday, 9 November 2017 at 11:08:21 UTC, ParticlePeter wrote: Any experience reports or general suggestions? I've used only D threads so far. It would be far easier if you use druntime + @nogc and/or de-register latency-sensitive threads from druntime [1], so they're not interrupted even if some other thread calls the GC. Probably the path of least resistance is to call [2] and queue @nogc tasks on [3]. If you really want to pursue the version(D_BetterC) route, then you're essentially on your own to use the threading facilities provided by your target OS, e.g.: https://linux.die.net/man/3/pthread_create https://msdn.microsoft.com/en-us/library/windows/desktop/ms682516(v=vs.85).aspx Though you need to be extra careful not to use thread-local storage (e.g. only shared static and __gshared) and not to rely on (shared) static {con|de}structors, dynamic arrays, associative arrays, exceptions, classes, RAII, etc., which is really not worth it, unless you're writing very low-level code (e.g. OS kernels and drivers). [1]: https://dlang.org/phobos/core_thread#.thread_detachThis [2]: https://dlang.org/phobos/core_memory#.GC.disable [3]: https://dlang.org/phobos/std_parallelism#.taskPool Forgot to mention, I'll try this first, I think its a good first step towards -BetterC usage. But in the end I want to see how far I can get with the -BetterC feature.
Re: How you guys go about -BetterC Multithreading?
On Thursday, 9 November 2017 at 12:43:54 UTC, Petar Kirov [ZombineDev] wrote: On Thursday, 9 November 2017 at 12:30:49 UTC, rikki cattermole wrote: On 09/11/2017 12:19 PM, Petar Kirov [ZombineDev] wrote: On Thursday, 9 November 2017 at 11:08:21 UTC, ParticlePeter wrote: Any experience reports or general suggestions? I've used only D threads so far. It would be far easier if you use druntime + @nogc and/or de-register latency-sensitive threads from druntime [1], so they're not interrupted even if some other thread calls the GC. Probably the path of least resistance is to call [2] and queue @nogc tasks on [3]. If you really want to pursue the version(D_BetterC) route, then you're essentially on your own to use the threading facilities provided by your target OS, e.g.: https://linux.die.net/man/3/pthread_create https://msdn.microsoft.com/en-us/library/windows/desktop/ms682516(v=vs.85).aspx You can use a library like libuv to handle threads (non-language based TLS too, not sure that it can be tied in unfortunately). Yeah, any cross-platform thread-pool / event loop library with C interface should obviously be preferred than manual use of raw thread primitives. Essentially, try to follow Sean Parent's advice on "No Raw/Incidental *": https://www.youtube.com/watch?v=zULU6Hhp42w This all is good input, thanks. I was looking into: https://github.com/GerHobbelt/pthread-win32 Anyone used this?
How you guys go about -BetterC Multithreading?
Any experience reports or general suggestions? I've used only D threads so far.
Re: C++ binding issues with C++ function returning a simple POD struct.
On Monday, 22 May 2017 at 14:01:56 UTC, Jerry wrote: IIRC the problem is that it isn't a POD type. ImVec2 has its own default constructor. The problem now is that because it no longer is POD, Window's ABI handles it different and doesn't put the value in a register. Now with D is that you aren't allowed to specify your own default constructor, so there's no equivalent way for it to know that it isn't a POD. A way around this is to specify your own destructor or copy constructor in the D ImVec2. I forget what the rules are for it, but I think that should do it. Thanks, with any of them, ~this or this(this) (both can be empty), the functions work as expected, nice. Also replying your next post, extern(C++) is on for the whole module: https://github.com/ParticlePeter/imgui_lib/blob/master/source/imgui/types.d#L39 but I learned how to link to github lines from your post :-)
Re: C++ binding issues with C++ function returning a simple POD struct.
On Monday, 22 May 2017 at 13:03:17 UTC, evilrat wrote: On Monday, 22 May 2017 at 11:25:31 UTC, ParticlePeter wrote: Then I am not getting your hack, this function here, does not exist on the C++ side. HACK --- // extern(C++) of course void GetCursorPos(ImVec2* v); How is it supposed to work then if there is no definition? you "forge" this signature insted of correct one, I suggest also wrap it some handy version in case this is "suddenly got working" version (PROPER_ABI) { extern(C++) ImVec2 GetCursorPos(); } else // hacky one { extern(C++) void GetCursorPos(ImVec2* v); ... put helper here to match excepted API, in case of C++ class add it to the end as 'final'... } This works because it matches name mangling on this one. And even if its not it is possible to hammer it in with pragma mangle. Never stop learning, that actually works! But only with the pragma mangle hammer. Nice, but again some more mangle pragmas. The better way seems to be Jerry's suggestion, works as well, see bellow.
Re: C++ binding issues with C++ function returning a simple POD struct.
On Monday, 22 May 2017 at 08:25:45 UTC, evilrat wrote: On Monday, 22 May 2017 at 08:03:07 UTC, ParticlePeter wrote: No, no, this (other) way around :-), still C++ to D. It actually works btw: HACK --- // original C++ ImVec2 GetCursorPos(); // C++ helper void GetCursorPos(ImVec2& result) { result = GetCursorPos(); } // bind with extern(C++) void GetCursorPos(ref ImVec2 result); -- My proposed hack is purely D side though O_- Then I am not getting your hack, this function here, does not exist on the C++ side. HACK --- // extern(C++) of course void GetCursorPos(ImVec2* v); How is it supposed to work then if there is no definition?
Re: C++ binding issues with C++ function returning a simple POD struct.
On Monday, 22 May 2017 at 07:24:20 UTC, evilrat wrote: On Monday, 22 May 2017 at 06:33:37 UTC, ParticlePeter wrote: On Monday, 22 May 2017 at 01:39:04 UTC, evilrat wrote: And this is actually D problem. In fact first bug report on this thing was dated back to 2014. Still not fixed. Thanks for your reply, do you have any links to some bug report of that issue? Just search for "c++ struct" https://issues.dlang.org/buglist.cgi?quicksearch=c%2B%2B%20struct https://issues.dlang.org/show_bug.cgi?id=13207 https://issues.dlang.org/show_bug.cgi?id=16527 That's really old, and of essential requirement I would assume. Thanks, I will comment the bug. Actually, your example would work just fine, my problem and possible solution is the other way around :-). First I'll try to force a copy with a wrapper func and same sig. You mean from D to C++? Well, that sucks. No, no, this (other) way around :-), still C++ to D. It actually works btw: HACK --- // original C++ ImVec2 GetCursorPos(); // C++ helper void GetCursorPos(ImVec2& result) { result = GetCursorPos(); } // bind with extern(C++) void GetCursorPos(ref ImVec2 result); --
Re: C++ binding issues with C++ function returning a simple POD struct.
On Monday, 22 May 2017 at 01:39:04 UTC, evilrat wrote: On Monday, 22 May 2017 at 01:27:22 UTC, Nicholas Wilson wrote: Probably because the D side is expecting to have the struct returned in a pointer allocated by the callee and then the C++ puts it in regs and BOOM. If you wrap the C++ side to return the struct by a pointer then use that in D, then it should work. And this is actually D problem. In fact first bug report on this thing was dated back to 2014. Still not fixed. Thanks for your reply, do you have any links to some bug report of that issue? There is possible hacky workaround to try - put struct as pointer arg instead of return and make helper method to use it, like this HACK --- // extern(C++) of course void GetCursorPos(ImVec2* v); // helper ImVec2 GetCursorPos() { ImVec2 temp; GetCursorPos(); return temp; } -- Actually, your example would work just fine, my problem and possible solution is the other way around :-). First I'll try to force a copy with a wrapper func and same sig.
Re: C++ binding issues with C++ function returning a simple POD struct.
On Monday, 22 May 2017 at 01:27:22 UTC, Nicholas Wilson wrote: On Sunday, 21 May 2017 at 19:33:06 UTC, ParticlePeter wrote: I am statically linking to ImGui [1] on Win 10 x64, quite successfully till this issue came up. The noticed error so far comes when an ImGui function returns an ImVec2, a simple POD struct of two float members. I can use this struct as argument to functions but when it is returned from a function I get a 0xC005: Access violation reading location 0x. I can even debug the process with Visual Studion, mixed d and c++ sources. The functions I tested return data from some internal global ImGui data, which I can fully examine, the crash happens on the return statement. Moreover, some functions have variations which return only one component from that ImVec2 POD, which do work as expected, e.g.: ImVec2 GetCursorPos(); // crash float GetCursorPosX(); // works float GetCursorPosY(); // works The latter do basically the same as the first one, but return ImVec.x or .y respectively. How could I further debug this? If somebody would be willing to look at the source, the binding is here [2]. [1] https://github.com/ocornut/imgui [2] https://github.com/ParticlePeter/imgui_lib Probably because the D side is expecting to have the struct returned in a pointer allocated by the callee and then the C++ puts it in regs and BOOM. Thanks for your reply, but that would be wired. The function signature clearly tells me: I am returning a (copy of a) ImVec2 on the stack. How could D expect any kind of pointer in that case? And should that not be true for the variants returning float as well? Almost same signature. But I agree with enhanced fishiness happening in the interface. If you wrap the C++ side to return the struct by a pointer then use that in D, then it should work. I've hoped to avoid extra work other then translating the header, but now I fear it won't. I'll give it a try.
Re: C++ binding issues with C++ function returning a simple POD struct.
On Sunday, 21 May 2017 at 19:58:32 UTC, Stefan Koch wrote: On Sunday, 21 May 2017 at 19:33:06 UTC, ParticlePeter wrote: I am statically linking to ImGui [1] on Win 10 x64, quite successfully till this issue came up. The noticed error so far comes when an ImGui function returns an ImVec2, a simple POD struct of two float members. I can use this struct as argument to functions but when it is returned from a function I get a 0xC005: Access violation reading location 0x. I can even debug the process with Visual Studion, mixed d and c++ sources. The functions I tested return data from some internal global ImGui data, which I can fully examine, the crash happens on the return statement. Moreover, some functions have variations which return only one component from that ImVec2 POD, which do work as expected, e.g.: [...] are you aware of https://github.com/Extrawurst/DerelictImgui ? Yes I am, its (understandably) not being updated too regularly, it goes the route of creating a C binding, and a D binding on top, lot of work. We should be able to bind the C++ variant directly by now I think.
C++ binding issues with C++ function returning a simple POD struct.
I am statically linking to ImGui [1] on Win 10 x64, quite successfully till this issue came up. The noticed error so far comes when an ImGui function returns an ImVec2, a simple POD struct of two float members. I can use this struct as argument to functions but when it is returned from a function I get a 0xC005: Access violation reading location 0x. I can even debug the process with Visual Studion, mixed d and c++ sources. The functions I tested return data from some internal global ImGui data, which I can fully examine, the crash happens on the return statement. Moreover, some functions have variations which return only one component from that ImVec2 POD, which do work as expected, e.g.: ImVec2 GetCursorPos(); // crash float GetCursorPosX(); // works float GetCursorPosY(); // works The latter do basically the same as the first one, but return ImVec.x or .y respectively. How could I further debug this? If somebody would be willing to look at the source, the binding is here [2]. [1] https://github.com/ocornut/imgui [2] https://github.com/ParticlePeter/imgui_lib
Re: C++ Interfacing:'static' array function parameter contradiction
On Saturday, 29 April 2017 at 10:17:47 UTC, Atila Neves wrote: On Saturday, 29 April 2017 at 06:22:03 UTC, ParticlePeter wrote: On Saturday, 29 April 2017 at 01:49:56 UTC, Atila Neves wrote: On Friday, 28 April 2017 at 18:41:22 UTC, kinke wrote: [...] The worst part about that is mangling aside, the two declarations are identical to the compiler. Atila In this context, can anybody explain [1], in particular, in this case, one should extern( C++ ) void cppSArray( ref float[3] color ); instead of: extern( C++ ) void cppSArray( float* color ); Others and me in this discussion seem to agree that parameter (float color[3]) is equivalent to (float* color) in C++ world. [1] http://dlang.org/spec/interfaceToC.html#passing_d_array It's "just" the mangling. If it were `extern(C)` there'd be nothing to talk about. Atila O.k. got it, so both D variants work with the same C++ mangling, thanks.
Re: C++ Interfacing:'static' array function parameter contradiction
On Saturday, 29 April 2017 at 00:31:32 UTC, Nicholas Wilson wrote: If you are having problems with the linker with Ali's you can do ``` extern(C++) bool cppFunc( float[3] color ); // correct signature, but causes compiler error pragma(mangle, cppFunc.mangleof) float cppFunc(float * color); // compatible signature but wrong mangling overridden with pragma(mangle,...) Thanks for that hint! I got it to work. Side note, cppFunc.mangleof cannot be used as it is unknown. I guess your intention was to get the C++ mangling from somewhere else, I got it from dependency walker.
Re: C++ Interfacing:'static' array function parameter contradiction
On Saturday, 29 April 2017 at 01:49:56 UTC, Atila Neves wrote: On Friday, 28 April 2017 at 18:41:22 UTC, kinke wrote: On Friday, 28 April 2017 at 18:07:49 UTC, ParticlePeter wrote: Interesting, your example corresponds to my third case, the linker error. I am on Window, building an x64 App, afaik in that case the MS Visual Studio linker is used instead of optilink. Will add your findings to the bug report. Apparently Microsoft's C++ compiler doesn't mangle `float arg[3]` parameters identically to `float* arg`: void cppSArray(float color[3]) => ?cppSArray@@YAXQEAM@Z void cppPtr(float* color) => ?cppPtr@@YAXPEAM@Z The worst part about that is mangling aside, the two declarations are identical to the compiler. Atila In this context, can anybody explain [1], in particular, in this case, one should extern( C++ ) void cppSArray( ref float[3] color ); instead of: extern( C++ ) void cppSArray( float* color ); Others and me in this discussion seem to agree that parameter (float color[3]) is equivalent to (float* color) in C++ world. [1] http://dlang.org/spec/interfaceToC.html#passing_d_array
Re: C++ Interfacing:'static' array function parameter contradiction
On Friday, 28 April 2017 at 17:57:34 UTC, Ali Çehreli wrote: On 04/28/2017 08:56 AM, ParticlePeter wrote: > C++ Function: > bool cppFunc( float[3] color ); > > D binding: > extern(C++) bool cppFunc( float[3] color ); > > Using with: > float[3] my_color; > cppFunc( my_color ); > > -> Error: Internal Compiler Error: unable to pass static array to That part is a bug at least in the compiler message. Is it really an internal ctompiler error? Doesn't look like it: the compiler is talking to us happily. :) My simple test works for me: // deneme.cpp float cppFunc(float color[3]) { return color[0] + color[1] + color[2]; } $ g++ -c deneme.cpp -o deneme_cpp.o // deneme.d extern(C++) float cppFunc(float * color); void main() { float[3] my_color = [ 1.5, 2.5, 3.5 ] ; assert(cppFunc(my_color.ptr) == 7.5); } $ dmd deneme_cpp.o deneme.d -of=deneme Builds and runs fine... on Linux... I don't know whether that's significant. Ali Btw, according to [1] your example should not work either, I doubt that there is a difference between C and C++ interfacing, it should be: extern(C++) float cppFunc( ref float[3] color ); In my case its a linker error as well. [1] http://dlang.org/spec/interfaceToC.html#passing_d_array
Re: C++ Interfacing:'static' array function parameter contradiction
On Friday, 28 April 2017 at 17:57:34 UTC, Ali Çehreli wrote: On 04/28/2017 08:56 AM, ParticlePeter wrote: > C++ Function: > bool cppFunc( float[3] color ); > > D binding: > extern(C++) bool cppFunc( float[3] color ); > > Using with: > float[3] my_color; > cppFunc( my_color ); > > -> Error: Internal Compiler Error: unable to pass static array to That part is a bug at least in the compiler message. Is it really an internal ctompiler error? Doesn't look like it: the compiler is talking to us happily. :) My simple test works for me: // deneme.cpp float cppFunc(float color[3]) { return color[0] + color[1] + color[2]; } $ g++ -c deneme.cpp -o deneme_cpp.o // deneme.d extern(C++) float cppFunc(float * color); void main() { float[3] my_color = [ 1.5, 2.5, 3.5 ] ; assert(cppFunc(my_color.ptr) == 7.5); } $ dmd deneme_cpp.o deneme.d -of=deneme Builds and runs fine... on Linux... I don't know whether that's significant. Ali Interesting, your example corresponds to my third case, the linker error. I am on Window, building an x64 App, afaik in that case the MS Visual Studio linker is used instead of optilink. Will add your findings to the bug report.
Re: C++ Interfacing:'static' array function parameter contradiction
On Friday, 28 April 2017 at 17:15:54 UTC, kinke wrote: On Friday, 28 April 2017 at 15:56:17 UTC, ParticlePeter wrote: So what next? How can I interface to the cpp function? *** C++: bool cppFunc(float ()[3]) { color[0] = 1; color[1] = 2; color[2] = 3; return true; } *** D: extern(C++) bool cppFunc(ref float[3] color); void main() { float[3] my_color; cppFunc(my_color); assert(my_color == [ 1, 2, 3 ]); } The c++ lib is not mine and your answer implies extra work on the c++ from my side. Possible, but not desired, I think calling my original c++ function should interface with an d pointer. That being said, I think Kagamin is right.
C++ Interfacing:'static' array function parameter contradiction
C++ Function: bool cppFunc( float[3] color ); D binding: extern(C++) bool cppFunc( float[3] color ); Using with: float[3] my_color; cppFunc( my_color ); -> Error: Internal Compiler Error: unable to pass static array to extern(C++) function. Error: Use pointer instead. Using with: cppFunc( my_color.ptr ); -> Error: function cppFunc( float[3] color ) is not callable using argument types (float*) Altering D binding: extern(C++) bool cppFunc( float* color ); Using with: cppFunc( my_color.ptr ); -> error LNK2001: unresolved external symbol "bool __cdecl cppFunc(float *)" Binding.exe : fatal error LNK1120: 1 unresolved externals Error: linker exited with status 1120 dmd failed with exit code 1120. So what next? How can I interface to the cpp function?
Re: How to overload member function pointer and a regualr member function
On Wednesday, 26 April 2017 at 08:24:08 UTC, Basile B. wrote: On Tuesday, 25 April 2017 at 18:58:58 UTC, Ali Çehreli wrote: On 04/25/2017 11:54 AM, Ali Çehreli wrote: My analysis is wrong because that writefln() is for the bar(float) overload but I still think what you want is achieved. Ali No it's ok, it works. The additional indirection is well avoided: Let's take this module: == #!dmd -release -inline -O module runnable; struct Foo { private void function(int,float) _bar; void bar(float){} pragma(inline, false) void bar(int i, float f){_bar(i,f);} } struct FooInline { private void function(int,float) _bar; void bar(float){} pragma(inline, true) void bar(int i, float f){_bar(i,f);} } void testInlined(ref FooInline foo) { foo.bar(0,0); } void test(ref Foo foo) { foo.bar(0,0); } void main() { import disassembler, std.stdio; disassembler.symbolTable.addModule!runnable; prettyDisasm().writeln; prettyDisasm(, 2).writeln; // dig up to 2 levels, required for the indir. } == and looks at the output: ;--- SUB 00459970h --- ; NAMED: testInlined 00459970h push rbp 00459971h mov rbp, rsp 00459974h sub rsp, 20h 00459978h mov qword ptr [rbp-08h], rdi 0045997Ch xor edi, edi 0045997Eh mov dword ptr [rbp-20h], edi 00459981h movss xmm0, dword ptr [rbp-20h] 00459986h mov rax, qword ptr [rbp-08h] 0045998Ah call qword ptr [rax] 0045998Dh mov rsp, rbp 00459990h pop rbp 00459991h ret ;- ;--- SUB 00459934h --- ; XREFS: [004599A6h] 00459934h push rbp 00459935h mov rbp, rsp 00459938h sub rsp, 10h 0045993Ch mov qword ptr [rbp-08h], rdi 00459940h mov rdi, rsi 00459943h mov rax, qword ptr [rbp-08h] 00459947h call qword ptr [rax] 0045994Ah mov rsp, rbp 0045994Dh pop rbp 0045994Eh ret ;- ;--- SUB 00459994h --- ; NAMED: test 00459994h push rbp 00459995h mov rbp, rsp 00459998h sub rsp, 10h 0045999Ch xor esi, esi 0045999Eh mov dword ptr [rbp-10h], esi 004599A1h movss xmm0, dword ptr [rbp-10h] 004599A6h call 00459934h 004599ABh mov rsp, rbp 004599AEh pop rbp 004599AFh ret ;- - testInlined() contains only the delegate call. (call qword ptr [rax]) - test() contains a call (call 00459934h) which contains the delegate call (call qword ptr [rax]) Actually i've even had to add (pragma inline false) to show the difference since DMD inlined automatically bar() in test(). Guys, you're great! Thanks a lot!
Re: How to overload member function pointer and a regualr member function
On Tuesday, 25 April 2017 at 16:27:43 UTC, Basile B. wrote: On Tuesday, 25 April 2017 at 15:43:48 UTC, ParticlePeter wrote: On Tuesday, 25 April 2017 at 09:50:14 UTC, Basile B. wrote: On Monday, 24 April 2017 at 16:46:21 UTC, ParticlePeter wrote: Thanks for your reply, but that's what I would like to avoid, the additional indirection to call the function pointer with the original argument count. Oops, i can believe i didn't read the last part of your question. Do you have any idea about the likelihood of the compiler removing this indirection as an optimizations? with pragma(inline, true), the function body should be injected at the call sites. This would not help I fear, the body of the function pointer is unknown in an external lib. I rather hoped that the compiler "sees" the parameter forwarding to the fp and is able to directly call it. Best thing would be for both overloads, but I would not know how to verify this.
Re: How to overload member function pointer and a regualr member function
On Tuesday, 25 April 2017 at 09:50:14 UTC, Basile B. wrote: On Monday, 24 April 2017 at 16:46:21 UTC, ParticlePeter wrote: I would like to have this kind of struct: struct Foo { private int i; void function( int i, float f ) bar; // will be defined at runtime void bar( float f ) { bar( i, f ); } } [...] How else can I get the required behavior? Like this: struct Foo1 { private void function(int,float) _bar; void bar(float){} void bar(int i, float f){_bar(i,f);} } Thanks for your reply, but that's what I would like to avoid, the additional indirection to call the function pointer with the original argument count. Do you have any idea about the likelihood of the compiler removing this indirection as an optimizations?
How to overload member function pointer and a regualr member function
I would like to have this kind of struct: struct Foo { private int i; void function( int i, float f ) bar; // will be defined at runtime void bar( float f ) { bar( i, f ); } } But apparently the function pointer and the member function cannot have the same name: Error: function main.Foo.bar conflicts with variable main.Foo.bar ... I tried with an inner struct: struct Foo { private int i; void function( int i, float f ) bar; // will be defined at runtime private struct Inner { void bar( float f ) { bar( i, f ); } } Inner inner; } But this time I get following error: Error: need 'this' for 'i' of type 'int' What does this message tell me? Should the inner struct not be able to access Foo.i? How else can I get the required behavior? I would prefer to avoid another indirection like this: struct Foo { private int i; void function( int i, float f ) bar; // will be defined at runtime void baz( float f ) { bar( i, f ); } void baz( int ii, float f ) { bar( ii, f ); } }
Re: Search elemnt in Compile-time Argument List of strings
On Tuesday, 26 July 2016 at 21:20:18 UTC, ParticlePeter wrote: ... First of all there seems to be a typo, it should not be: else static if(i + 1 == arg.length) ignore must be used instead of arg, as arg.length is the length of a string: else static if(i + 1 == ignore.length) if ignore is empty, its length is 0, so that the statement would always evaluate to false. Btw, if ignore is not empty, only the last element (arg) is skipped. Test: void processMember( T, ignore... )() { foreach( member; __traits( allMembers, T )) { foreach( i, arg; ignore ) { // i is the index into the ignore tuple static if( arg == member ) break; // break out of the foreach loop, ... else static if( i + 1 == ignore.length ) { // this is the last element! pragma( msg, "processing ", member ); } } } } struct Foo { float a, b, c, d; } int main() { processMember!( Foo );// nada processMember!( Foo, "c" ); // works processMember!( Foo, "c", "b" ); // skips only b }
Re: Search elemnt in Compile-time Argument List of strings
On Tuesday, 26 July 2016 at 21:01:19 UTC, Ali Çehreli wrote: On 07/26/2016 01:58 PM, ParticlePeter wrote: On Tuesday, 26 July 2016 at 20:18:48 UTC, Steven Schveighoffer wrote: ... void processMember( T, ignore... )() { foreach( member; __traits( allMembers, T )) { // this is a compile-time list, so it's a static foreach. foreach(i, arg; ignore ){ // i is the index into the ignore tuple static if( arg == member ) break; // break out of the foreach loop, need to ignore it. else static if(i + 1 == arg.length) // this is the last element! { // process member here, generate e.g. setter function as string mixin } } } } There is one problem with this approach, ignore might be empty (I should have mentioned it). Would you know a workaround for that case as well? It should work for empty ignore. Can you show with a short example please. Ali First of all there seems to be a typo, it should not be: else static if(i + 1 == arg.length) ignore must be used instead of arg, as arg.length is the length of a string: else static if(i + 1 == ignore.length) if ignore is empty, its length is 0, so that the statement would always evaluate to false. Btw, if ignore is not empty, only the last element (arg) is skipped.
Re: Search elemnt in Compile-time Argument List of strings
On Tuesday, 26 July 2016 at 20:18:48 UTC, Steven Schveighoffer wrote: ... void processMember( T, ignore... )() { foreach( member; __traits( allMembers, T )) { // this is a compile-time list, so it's a static foreach. foreach(i, arg; ignore ){ // i is the index into the ignore tuple static if( arg == member ) break; // break out of the foreach loop, need to ignore it. else static if(i + 1 == arg.length) // this is the last element! { // process member here, generate e.g. setter function as string mixin } } } } There is one problem with this approach, ignore might be empty (I should have mentioned it). Would you know a workaround for that case as well?
Re: Search elemnt in Compile-time Argument List of strings
On Tuesday, 26 July 2016 at 20:18:48 UTC, Steven Schveighoffer wrote: ... Thanks a lot for this really cool and detailed explanation (upvoting!). It's a bit weird to work on these compile-time things, but they are so cool when you look at what is available in std.meta and std.traits :) Agreed with each aspect. When I (just) read Philippe Sigaud's D Templates Tutorial I didn't get a thing. Important thing is getting your hands dirty, then it comes slowly.
Re: Search elemnt in Compile-time Argument List of strings
On Tuesday, 26 July 2016 at 19:30:18 UTC, ParticlePeter wrote: // Second approach, get warnings for every skipped member // and every line after the return statement: // Warning: statement is not reachable void processMember( T, ignore... )() { foreach( member; __traits( allMembers, T )) { foreach( arg; ignore ) static if( arg == member ) return; // process member here, generate e.g. setter function as string mixin } } So how can I achieve my goal the right way? I just realized that the second approach, despite the warnings, does not achieve its goal. The members are still forwarded. So I should rather ask how I could filter the members at all.
Search elemnt in Compile-time Argument List of strings
I want to generate one function for any struct data member, but also want to be able to skip few of the members. The first part works, but I have some trouble with the skipping. I pass the struct type and a Compile-time Argument List of strings as template arguments to a template function, list all members of the struct and compare each member to each element of the List. If the member is in the List skip processing of that member. Pretty straight forward ... should be. // First approach doesn't work: // Error: variable skip cannot be read at compile time void processMember( T, ignore... )() { foreach( member; __traits( allMembers, T )) { bool skip = false; foreach( arg; ignore ) skip = skip || ( arg == member ); static if( !skip ) { // process member here, generate e.g. setter function as string mixin } } } // Second approach, get warnings for every skipped member // and every line after the return statement: // Warning: statement is not reachable void processMember( T, ignore... )() { foreach( member; __traits( allMembers, T )) { foreach( arg; ignore ) static if( arg == member ) return; // process member here, generate e.g. setter function as string mixin } } So how can I achieve my goal the right way?
Re: Transform/Compile to C/CPP as a target
On Saturday, 23 July 2016 at 19:20:10 UTC, Jacob Carlborg wrote: On 2016-07-23 14:27, ParticlePeter wrote: Is there any kind of project or workflow that converts D (subset) to C/CPP ? No idea about the status but: https://github.com/adamdruppe/tools/blob/dtoh/dtoh.d Thanks, I am looking into this, but I think its still not that what I am searching, it seems to create only C/CPP headers for D libs. I would like to have the whole source code transformed.
Re: Transform/Compile to C/CPP as a target
On Saturday, 23 July 2016 at 12:29:45 UTC, rikki cattermole wrote: On 24/07/2016 12:27 AM, ParticlePeter wrote: Is there any kind of project or workflow that converts D (subset) to C/CPP ? This probably will interest you for ldc: http://stackoverflow.com/questions/5180914/llvm-ir-back-to-human-readable-source-language Cool, I didn't know that one but I also didn't invest time in LLVM till now. However, this converts bitcode to C/CPP, my guess would be that the job can be done much better if the original D source would be used in tandem.
Transform/Compile to C/CPP as a target
Is there any kind of project or workflow that converts D (subset) to C/CPP ?
Re: Enum that can be 0 or null
On Tuesday, 7 June 2016 at 14:31:40 UTC, Alex Parrill wrote: I don't think opCast gets called for implicit conversions; it only gets called for explicit casts. I'll test it later. It does for type bool, but I fear that's the only exception.
Re: Enum that can be 0 or null
On Monday, 6 June 2016 at 20:32:23 UTC, Alex Parrill wrote: They'd be the same type, since you would define the vulkan functions to take these structures instead of pointer or integer types. It relies on a lot of assumptions about the ABI that make a raw pointer work the same as a structure containing just one pointer, which is why I did not give it much consideration. Is there a way to use opCast (just an idea, not working code) ? private struct VK_HANDLE_HELPER { const void * handle = null; alias handle this; T opCast(T)() if( is( T == uint64_t )) { return 0uL; } } const VK_NULL_HANDLE = VK_HANDLE_HELPER();
Re: Enum that can be 0 or null
On Saturday, 21 May 2016 at 06:36:53 UTC, tsbockman wrote: ... As an example, if VK_NULL_HANDLE only ever needs to be assigned to opaque types on the D side (that is, types that serve only as an ID or address for communicating with the C side), you could do this: private struct VkNullHandle { } enum VK_NULL_HANDLE = VkNullHandle.init; mixin template VkHandle(bool dispatchable) { static if (dispatchable || (size_t.sizeof == 8)) void* bits = null; else ulong bits = 0; this(typeof(this) that) { this.bits = that.bits; } this(VkNullHandle that) { this.bits = typeof(this.bits).init; } ref typeof(this) opAssign(typeof(this) that) { this.bits = that.bits; return this; } ref typeof(this) opAssign(VkNullHandle that) { this.bits = typeof(this.bits).init; return this; } } struct VkDevice { mixin VkHandle!true; } struct VkInstance { mixin VkHandle!true; } struct VkFence { mixin VkHandle!false; } struct VkSemaphore { mixin VkHandle!false; } void main() { VkInstance a = VK_NULL_HANDLE; VkFence b = VK_NULL_HANDLE; } (DPaste: https://dpaste.dzfl.pl/8f4ce39a907f ) The above is typesafe, and can easily be made compatible with a typical C API, since C does no parameter-related name mangling. In this case I don't see how it would be possible to use your VkDevice, etc. as argument to the C functions, as they are of different type, no?
Re: Emulate C's (polymorphic) NULL type
On Monday, 6 June 2016 at 18:33:36 UTC, ParticlePeter wrote: On Monday, 6 June 2016 at 16:19:02 UTC, Alex Parrill wrote: On Monday, 6 June 2016 at 09:43:23 UTC, ParticlePeter wrote: In C NULL can be used as integer as well as null pointer. Is there a way to create such a type in D? The type should have only one value which is obviously (0/null). A extern( C ) function should be able to take it as either one. Overloaded enum pops into my mind as example: enum NULL = 0; enum NULL = null; Is this possible somehow? I already asked about this: https://forum.dlang.org/post/bnkqevhyxwdjjxsct...@forum.dlang.org Tldr; doesn't seem to be possible without multiple alias this or using ABI hacks. O.k., my web search didn't find that topic. The last reply looks promising, wouldn't that work? Lets bump it and discuss there.
Re: Emulate C's (polymorphic) NULL type
On Monday, 6 June 2016 at 16:19:02 UTC, Alex Parrill wrote: On Monday, 6 June 2016 at 09:43:23 UTC, ParticlePeter wrote: In C NULL can be used as integer as well as null pointer. Is there a way to create such a type in D? The type should have only one value which is obviously (0/null). A extern( C ) function should be able to take it as either one. Overloaded enum pops into my mind as example: enum NULL = 0; enum NULL = null; Is this possible somehow? I already asked about this: https://forum.dlang.org/post/bnkqevhyxwdjjxsct...@forum.dlang.org Tldr; doesn't seem to be possible without multiple alias this or using ABI hacks. O.k., my web search didn't find that topic. The last reply looks promising, wouldn't that work?
Re: Emulate C's (polymorphic) NULL type
On Monday, 6 June 2016 at 11:40:11 UTC, Anonymouse wrote: On Monday, 6 June 2016 at 09:43:23 UTC, ParticlePeter wrote: In C NULL can be used as integer as well as null pointer. Is there a way to create such a type in D? The type should have only one value which is obviously (0/null). A extern( C ) function should be able to take it as either one. Overloaded enum pops into my mind as example: enum NULL = 0; enum NULL = null; Is this possible somehow? If you want it for use in logical expressions then implicit boolean conversion will treat them as the same. https://dpaste.dzfl.pl/d82f60657c37 I don't see the connection here, you introduced two symbols with two different types. I want one symbol which can pose as two different (constant) types.
Emulate C's (polymorphic) NULL type
In C NULL can be used as integer as well as null pointer. Is there a way to create such a type in D? The type should have only one value which is obviously (0/null). A extern( C ) function should be able to take it as either one. Overloaded enum pops into my mind as example: enum NULL = 0; enum NULL = null; Is this possible somehow?
Re: Why does std.container.array does not work with foraech( i, a; array ) {} ?
On Sunday, 29 May 2016 at 09:07:07 UTC, Jonathan M Davis wrote: On Sunday, May 29, 2016 07:14:12 ParticlePeter via Digitalmars-d-learn wrote: Which of the op(Index) operators is responsible for enabling this kind of syntax? Would it be possible to get it work with UFCS or would I have to wrap the array? std.container.array.Array works with foreach via ranges. foreach(e; myContainer) { } gets lowered to foreach(e; myContainer[]) { } which in turn gets lowered to something like for(auto r = myContainer[]; !r.empty; r.popFront()) { auto e = r.front; } Ranges do not support indices with foreach, and that's why you're not able to get the index with foreach and Array. However, if you use std.range.lockstep, you can wrap a range to get indices with foreach. e.g. foreach(i, e; lockstep(myContainer[])) { } http://dlang.org/phobos/std_range.html#.lockstep - Jonathan M Davis Thanks, due to your answer I found a way which is even better for me. I pimped the Array containers with some UFCS functions anyway, one of them returns the array data as a slice and this works nicely with that foreach variant as well auto data( T )( Array!T array ) { if( array.length == 0 ) return null; return (())[ 0..array.length ]; } // this works now foreach( i, a; someArrayContainer.data ) { ... } - PP
Why does std.container.array does not work with foraech( i, a; array ) {} ?
Which of the op(Index) operators is responsible for enabling this kind of syntax? Would it be possible to get it work with UFCS or would I have to wrap the array?
Introspect alias name of an aliased type
alias uint32_t = uint; struct Offset() { uint32_t x; uint32_t y; } // Introspect with: void printStructInfo( T )( T info ) { import std.stdio : writefln; foreach (memb; __traits(allMembers, T)) { writefln(typeof(__traits(getMember, info, memb)).stringof); } } // Result is uint Is there a way to get the alias uint32_t instead ?
Re: Game Development Using D
On Saturday, 21 May 2016 at 16:01:26 UTC, Stefan Koch wrote: On Saturday, 21 May 2016 at 15:53:18 UTC, David wrote: Hi, I want to try to create a game using D. I'm a complete newbie though (other than having C/C++ experience). Where would I start? Does D have an openGL binding? I am assuming I'll need to leverage a good amount C APIs? Any list of these that would be useful it a game setting? Obviously this all depends on *how* much work I want to do. Ideally, I'd like a collection of tools that will get me roughly the equivalent of what XNA provides. The is derilict-gl and then there is the dgame library Check out the DerelictOrg bindings in general: https://github.com/DerelictOrg In particular DerelictAssimp3 might help with animation and scene loading. Other related game libraries are in the dub registry: https://code.dlang.org/search?q=game
Cannot link daimos glfw using x64
I am failing to link statically to glfw library with deimos glfw. The repo includes an example for glfw2. I downloaded the latest glfw2.lib and tried build the example with -m64 and got these errors: C:\ ... \deimos-glfw>dmd GLFW.lib examples/glfw2/openwindow/openwindow.d -m64 MSVCRT.lib(MSVCR120.dll) : error LNK2005: free already defined in LIBCMT.lib(free.obj) MSVCRT.lib(MSVCR120.dll) : error LNK2005: strchr already defined in LIBCMT.lib(strchr.obj) MSVCRT.lib(MSVCR120.dll) : error LNK2005: malloc already defined in LIBCMT.lib(malloc.obj) MSVCRT.lib(MSVCR120.dll) : error LNK2005: __iob_func already defined in LIBCMT.lib(_file.obj) MSVCRT.lib(MSVCR120.dll) : error LNK2005: fprintf already defined in LIBCMT.lib(fprintf.obj) LINK : warning LNK4098: defaultlib 'MSVCRT' conflicts with use of other libs; use /NODEFAULTLIB:library Next I tried to build the library myself with the /NODEFAULTLIB option set but still getting the same errors. What am I doing wrong?
Re: Getting all struct members and values with introspection avoiding string mixins
On Sunday, 1 May 2016 at 10:13:47 UTC, H. S. Teoh wrote: On Sun, May 01, 2016 at 09:42:37AM +, ParticlePeter via Digitalmars-d-learn wrote: I am logging arbitrary POD struct types with member names and data: void printStructInfo( T )( T info ) { foreach( i, A; typeof( T.tupleof )) { enum attribName = T.tupleof[i].stringof; writefln( "%s : %s", attribName, mixin( "info." ~ attribName )); } } Is there is some other way to evaluate info.attribName without using string mixins? [...] Using typeof(T.tupleof) seems a bit circuitous. Here's how I'd do it: void printStructInfo( T )( T info ) { import std.stdio : writefln; foreach (memb; __traits(allMembers, T)) { writefln("%s: %s", memb, __traits(getMember, info, memb)); } } (For structs that have members other than data fields, you'll need a static if to filter out non-value members, but this should get you started.) T Thanks, I was searching for that! The given example is a simplification of my code. I do examine each member separately and treat accordingly, but eventually used the mixin version to get the build-in type values.
Getting all struct members and values with introspection avoiding string mixins
I am logging arbitrary POD struct types with member names and data: void printStructInfo( T )( T info ) { foreach( i, A; typeof( T.tupleof )) { enum attribName = T.tupleof[i].stringof; writefln( "%s : %s", attribName, mixin( "info." ~ attribName )); } } Is there is some other way to evaluate info.attribName without using string mixins? Cheers, PP
Re: std.format.formattedRead docs example does not work with a string literal as input, why?
On Thursday, 31 March 2016 at 18:25:45 UTC, H. S. Teoh wrote: On Thu, Mar 31, 2016 at 06:23:21PM +, ParticlePeter via Digitalmars-d-learn wrote: Example from docs: string s = "hello!124:34.5"; string a; int b; double c; formattedRead(s, "%s!%s:%s", , , ); assert(a == "hello" && b == 124 && c == 34.5); now changing the first formattedRead argument to a string literal: formattedRead("hello!124:34.5", "%s!%s:%s", , , ); results in this compiler error: Error: template std.format.formattedRead cannot deduce function from argument types !()(string, string, string*, int*, double*), candidates are: ..\..\src\phobos\std\format.d(588,6): std.format.formattedRead(R, Char, S...)(ref R r, const(Char)[] fmt, S args) I am not getting the point that in both cases the argument is a string, but in the first case it is interpreted as a Range, and in the second case not. Why? Because in the second case the string is an rvalue, whereas in the first case it gets stored in a variable first, so it's an lvalue. The first parameter of formattedRead is 'ref', meaning that it requires an lvalue. (Arguably, it should be `auto ref` instead, then literals would work, but that belongs in an enhancement request.) T Ok, thanks, that makes sense. I would add that the compiler should mention that a ref value is required, this would have helped to understand the issue.
std.format.formattedRead docs example does not work with a string literal as input, why?
Example from docs: string s = "hello!124:34.5"; string a; int b; double c; formattedRead(s, "%s!%s:%s", , , ); assert(a == "hello" && b == 124 && c == 34.5); now changing the first formattedRead argument to a string literal: formattedRead("hello!124:34.5", "%s!%s:%s", , , ); results in this compiler error: Error: template std.format.formattedRead cannot deduce function from argument types !()(string, string, string*, int*, double*), candidates are: ..\..\src\phobos\std\format.d(588,6): std.format.formattedRead(R, Char, S...)(ref R r, const(Char)[] fmt, S args) I am not getting the point that in both cases the argument is a string, but in the first case it is interpreted as a Range, and in the second case not. Why?
Re: Does something like std.algorithm.iteration:splitter with multiple seperators exist?
On Wednesday, 23 March 2016 at 20:00:55 UTC, wobbles wrote: Again, totally untested, but I think logically it should work. ( No D compiler on this machine so it mightn't even compile :] ) Thanks Wobbles, I took your approach. There were some minor issues, here is a working version: auto multiSlice(string data, string[] delims) { import std.algorithm : canFind; import std.string : indexOf; struct MultiSliceRange { string m_str; string[] m_delims; bool empty(){ return m_str.length == 0; } void popFront(){ auto idx = findNextIndex; m_str = m_str[idx..$]; return; } string front(){ auto idx = findNextIndex; return m_str[0..idx]; } private size_t findNextIndex() { auto index = size_t.max; foreach(delim; m_delims) { if(m_str.canFind(delim)) { auto foundIndex = m_str.indexOf(delim); if(index > foundIndex && foundIndex > 0) { index = foundIndex; } } } return index; } } return MultiSliceRange(data, delims); }
Re: Does something like std.algorithm.iteration:splitter with multiple seperators exist?
On Wednesday, 23 March 2016 at 15:23:38 UTC, Simen Kjaeraas wrote: Without a bit more detail, it's a bit hard to help. std.algorithm.splitter has an overload that takes a function instead of a separator: import std.algorithm; auto a = "a,b;c"; auto b = a.splitter!(e => e == ';' || e == ','); assert(equal(b, ["a", "b", "c"])); However, not only are the separators lost in the process, it only allows single-element separators. This might be good enough given the information you've divulged, but I'll hazard a guess it isn't. My next stop is std.algorithm.chunkBy: auto a = ["a","b","c", "d", "e"]; auto b = a.chunkBy!(e => e == "a" || e == "d"); auto result = [ tuple(true, ["a"]), tuple(false, ["b", "c"]), tuple(true, ["d"]), tuple(false, ["e"]) ]; No assert here, since the ranges in the tuples are not arrays. My immediate concern is that two consecutive tokens with no intervening values will mess it up. Also, the result looks a bit messy. A little more involved, and according to documentation not guaranteed to work: bool isToken(string s) { return s == "a" || s == "d"; } bool tokenCounter(string s) { static string oldToken; static bool counter = true; if (s.isToken && s != oldToken) { oldToken = s; counter = !counter; } return counter; } unittest { import std.algorithm; import std.stdio; import std.typecons; import std.array; auto a = ["a","b","c", "d", "e", "a", "d"]; auto b = a.chunkBy!tokenCounter.map!(e=>e[1]); auto result = [ ["a", "b", "c"], ["d", "e"], ["a"], ["d"] ]; writeln(b); writeln(result); } Again no assert, but b and result have basically the same contents. Also handles consecutive tokens neatly (but consecutive identical tokens will be grouped together). Hope this helps. -- Simen Thanks Simen, your tokenCounter is inspirational, for the rest I'll take some time for testing. But some additional thoughts from my sided: I get all the lines of the file into one range. Calling array on it should give me an array, but how would I use find to get an index into this array? With the indices I could slice up the array into four slices, no allocation required. If there is no easy way to just get an index instead of an range, I would try to use something like the tokenCounter to find all the indices.
Re: Does something like std.algorithm.iteration:splitter with multiple seperators exist?
On Wednesday, 23 March 2016 at 14:20:12 UTC, Andrea Fontana wrote: Any input => output example? Sure, it is ensight gold case file format: FORMAT type: ensight gold GEOMETRY model: 1exgold2.geo** VARIABLE scalar per node: 1 Stress exgold2.scl** vector per node: 1 Displacement exgold2.dis** TIME time set: 1 number of steps: 3 filename start number: 0 filename increment:1 time values: 1.0 2.0 3.0 The separators would be ["FORMAT", "TIME", "VARIABLE", "GEOMETRY"]. The blank lines between the blocks and the order of the separators in the file is not known. I would expect a range of four ranges of lines: one for each text-block above.
Re: Does something like std.algorithm.iteration:splitter with multiple seperators exist?
On Wednesday, 23 March 2016 at 11:57:49 UTC, ParticlePeter wrote: Stupid typos: I need to parse an ascii file with multiple tokens. ... ... to do this with a lazy result range and without new allocations.
Does something like std.algorithm.iteration:splitter with multiple seperators exist?
I need to parse an ascii with multiple tokens. The tokens can be seen as keys. After every token there is a bunch of lines belonging to that token, the values. The order of tokens is unknown. I would like to read the file in as a whole string, and split the string with: splitter(fileString, [token1, token2, ... tokenN]); And would like to get a range of strings each starting with tokenX and ending before the next token. Does something like this exist? I know how to parse the string line by line and create new strings and append the appropriate lines, but I don't know how to do this with a lazy result range and new allocations.
Re: How to return a const handle (view) to a mutable member of an agregate
On Sunday, 13 March 2016 at 20:28:33 UTC, JR wrote: On Sunday, 13 March 2016 at 20:13:03 UTC, Basile B. wrote: On Sunday, 13 March 2016 at 20:10:57 UTC, Basile B. wrote: [...] Basile beat me to it. Yes, ref const(Array!T) accessor. http://dpaste.dzfl.pl/cb2bc5cf9917 Thank you very much, both of you. JR, that's excellent (additional) information :-) but my struct is not supposed to work as array, "wrapper" was a wrong expression. ref const(Array!T) accessor() will still do :-)
How to return a const handle (view) to a mutable member of an agregate
I have a struct that privately warps an std.container.array. I would like to return a read-only reference of this array, it should not be duplicated. How can I do this? Cheers, ParticlePeter
Re: Anyone using glad?
On Monday, 11 January 2016 at 00:46:38 UTC, Jason Jeffory wrote: ... OK, I'll give it a try. What about GLUT and WGL? Whats the difference between them all and glfw? Are all these just OS helpers to reduce the boilerplate code? These kind of questions are best clarified on the OpenGL wiki. https://www.opengl.org/wiki/Main_Page Especially these (Glad is explained there as well): https://www.opengl.org/wiki/Getting_Started https://www.opengl.org/wiki/OpenGL_Loading_Library https://www.opengl.org/wiki/Related_toolkits_and_APIs
How to declare an alias to a function literal type
I have a function type and variable and assign a function to it: void function( int i ) myFunc; myFunc = void function( int i ) { myCode; } How would I declare an alias for void function( int i ) such that the case above would work like this: // alias MF = void function( int i ); // not working // alias void function( int i ) MF; // not working MF myFunc; myFunc = MF { myCode }; Please, if possible, also show me where I should have found the answer (D Reference, Alis book, etc. )
Re: How to declare an alias to a function literal type
On Tuesday, 12 January 2016 at 16:22:48 UTC, ParticlePeter wrote: Actually, I do use only one param, and not int as well, hence I would like the parameter list to be part of the alias. Your example works though. This was confusing, lets start fresh: I have a function "otherFunc" which takes a function with lots of parameters as argument: void otherFunc( void function( ref int p1, float p2, ubyte p3, ... ) mf ); Side-note, I use the keyword function to signal that it is a function and not a delegate, thought it is a delegate when not specified. When I pass a parameter to otherFunc I use this syntax for an anonymous function parameter: otherFunc( void function( ref int p1, float p2, ubyte p3 ) { myCode; } ); I would like to alias the function signature above: alias MF = void function( ref int p1, float p2, ubyte p3 ); I can rewrite the definition of otherFunc like this: void otherFunc( MF mf ); But I cannot pass an anonymous function to otherFunc like this: otherFunc( MF { myCode; } ); Thats what I want. Any working example? Ali, I do not pass an existing named function as a pointer. I am also not sure about the lambdas, as I do not return anything, I just want to process data, would that work?
Re: How to declare an alias to a function literal type
On Tuesday, 12 January 2016 at 16:00:37 UTC, Daniel Kozak wrote: V Tue, 12 Jan 2016 15:41:02 + ParticlePeter via Digitalmars-d-learn <digitalmars-d-learn@puremagic.com> napsáno: I have a function type and variable and assign a function to it: void function( int i ) myFunc; myFunc = void function( int i ) { myCode; } How would I declare an alias for void function( int i ) such that the case above would work like this: // alias MF = void function( int i ); // not working // alias void function( int i ) MF; // not working MF myFunc; myFunc = MF { myCode }; Please, if possible, also show me where I should have found the answer (D Reference, Alis book, etc. ) alias void MF(int i); That does not work: alias void MF(int i); MF mf; // Error: variable mf cannot be declared to be a function
Re: How to declare an alias to a function literal type
On Tuesday, 12 January 2016 at 15:57:03 UTC, Marc Schütz wrote: On Tuesday, 12 January 2016 at 15:41:02 UTC, ParticlePeter wrote: I have a function type and variable and assign a function to it: void function( int i ) myFunc; myFunc = void function( int i ) { myCode; } How would I declare an alias for void function( int i ) such that the case above would work like this: // alias MF = void function( int i ); // not working // alias void function( int i ) MF; // not working MF myFunc; myFunc = MF { myCode }; Please, if possible, also show me where I should have found the answer (D Reference, Alis book, etc. ) This works for me: alias MF = void function(int i); // works fine - what was your error? void main() { import std.stdio; MF myFunc; // you can also use the full `function(int i) { ... }` in the next line myFunc = (i) { writeln("i = ", i); }; myFunc(42); } Not what I wanted, I wanted the parameter to be part of the alias: myFunc = MF { ... } I want to pass such a function to another function: alias MF = void function(int i); void otherFunc( void function( int ) mf ); otherFunc( MF { ... } ); // Getting Error: found '{' when expecting ',' Actually, I do use only one param, and not int as well, hence I would like the parameter list to be part of the alias. Your example works though.
Re: How to declare an alias to a function literal type
On Tuesday, 12 January 2016 at 17:03:49 UTC, Ali Çehreli wrote: On 01/12/2016 08:55 AM, ParticlePeter wrote: > I have a function "otherFunc" which takes a function with lots of > parameters as argument: > > void otherFunc( void function( ref int p1, float p2, ubyte p3, ... ) mf ); Ok. > otherFunc( void function( ref int p1, float p2, ubyte p3 ) { myCode; } ); Ok. > alias MF = void function( ref int p1, float p2, ubyte p3 ); Ok. > I can rewrite the definition of otherFunc like this: > void otherFunc( MF mf ); That has the same problem of trying to do this for int: void foo(int i) { } void main() { foo(int 42); // <-- ERROR } But you can do this: foo(int(42));// (Relatively new syntax in D.) > But I cannot pass an anonymous function to otherFunc like this: > otherFunc( MF { myCode; } ); It works with the parentheses as it does for int: alias MF = void function( ref int p1, float p2, ubyte p3 ); void otherFunc( MF mf ) { } void main() { otherFunc(MF((ref int, float, ubyte){ }));// <-- Parens } O.K. so I conclude that writing: void main() { otherFunc(MF { }); } is not possible. At least not with alias, maybe with templates or mixins? In essence something like C #define as in: #define MF function( ref int p1, float p2, ubyte p3 ) Is there some such way?
Re: How to declare an alias to a function literal type
On Tuesday, 12 January 2016 at 17:28:35 UTC, Marc Schütz wrote: On Tuesday, 12 January 2016 at 16:55:48 UTC, ParticlePeter wrote: [...] If I understand you correctly (not sure), you would like to write `MF` so that you don't need to specify the parameters in the lambda? That's not possible, because the code inside the lambda needs names for them if it wants to access them, but parameter names are _not_ part of the function type, and therefore the alias doesn't know about them. However, you don't need to specify the full parameter list in the lambda, the names and `ref` are enough: otherFunc( (ref a, ref b, ref c) { /* use a, b, c */ } ); This is already quite useful, thanks.
Re: Confusion about dynamically and lexically scoped closures
On Sunday, 8 November 2015 at 23:17:06 UTC, Jakob Ovrum wrote: The closures for delegates in D1 are never automatically copied to the heap, while in D2 this is done when it's determined that the delegate might outlive one of its upvalues. So, I think it's safe to say we have lexical closures in D2 but only dynamic closures in D1 and the language specification is out of date. Thanks, makes sens, I assumed a typo in the docs.
Confusion about dynamically and lexically scoped closures
Hi, the confusion starts here: http://dlang.org/function.html#closures End of paragraph bellow the last delegate example: "This combining of the environment and the function is called a dynamic closure." While according to https://en.wikipedia.org/wiki/Scope_%28computer_science%29 "Lexical scope vs. dynamic scope" I would call D delegates lexical closures, as the scope of the callee (scope where callee is defined) is used for free variable lookup, isn't that right? Confusion is enhanced with this Dlang wiki: http://wiki.dlang.org/Function_literals "This has brought up the specter of Dynamic Closures. The nested and/or anonymous functions can only access dynamic scope, which means scope that exists on the stack at the time of execution. This differs from lexical scope, which refers to the scope as indicated by the program text structure." So what's what now? Cheers, ParticlePeter
How to partially forward properties of struct array member to struct (disable length property) ?
I am working on a struct vector. The data is stored in a member static array and I want to be able to forward all array properties except length to vector. Reason is I have free functions f that take vector(s) as arguments, such that f(vector) and vector.f via UFCS is possible. Using alias array this in the case of length function/array property is problematic, as length(vector) obviously uses the free function but vector.length the array property. What would be the simplest way to disable the array.length property for the vector struct? I would prefer not to implement length as a vector member function and call it inside the free function as this is inconsistent with the other free funcs.
Re: How to partially forward properties of struct array member to struct (disable length property) ?
On Sunday, 6 September 2015 at 08:48:32 UTC, bioinfornatics wrote: On Sunday, 6 September 2015 at 07:34:36 UTC, ParticlePeter wrote: I am working on a struct vector. The data is stored in a member static array and I want to be able to forward all array properties except length to vector. Reason is I have free functions f that take vector(s) as arguments, such that f(vector) and vector.f via UFCS is possible. Using alias array this in the case of length function/array property is problematic, as length(vector) obviously uses the free function but vector.length the array property. What would be the simplest way to disable the array.length property for the vector struct? I would prefer not to implement length as a vector member function and call it inside the free function as this is inconsistent with the other free funcs. Hi, If you are looking for somethin like delegator from ruby: http://ruby-doc.org/stdlib-2.0.0/libdoc/forwardable/rdoc/Forwardable.html No, not this one. It is O.k. for vector to be implicitly converted to an array, and in such a case array property length should be used. Or by using mixin delegates: http://forum.dlang.org/post/jitn9v$20u4$1...@digitalmars.com I think this approach (in particular Jacobs suggestion) would be useful if I would like to forward array member properties for lot of different struct/classes but for now it is sufficient for the vector struct. I took a look at opIndex, opSlice, opIndexAssign and opIndexOpAssign but find the examples very confusing. Also its not clear for me which of these operators I have to implement to have full array functionality on the vector struct. In the end all that I want is "just" to disable access to array.length through vector and alias this array.
Convert std.container.array to void[] and/or pass to OpenGL functions like glBuffer(Sub)Data
I use wrapper functions taking void[] arrays to forward them comfortably to mentioned OpenGL functions. This works with static and dynamic build in arrays, but I don't see a way how I could access (cast) the raw data of a std.container.array to forward it to these wrapper functions. std.array(Range)(Range r) does a copy which I would like to avoid. Any advice ?
Re: Convert std.container.array to void[] and/or pass to OpenGL functions like glBuffer(Sub)Data
On Wednesday, 17 June 2015 at 13:07:11 UTC, Alex Parrill wrote: On Wednesday, 17 June 2015 at 13:04:28 UTC, ParticlePeter wrote: I use wrapper functions taking void[] arrays to forward them comfortably to mentioned OpenGL functions. This works with static and dynamic build in arrays, but I don't see a way how I could access (cast) the raw data of a std.container.array to forward it to these wrapper functions. std.array(Range)(Range r) does a copy which I would like to avoid. Any advice ? Try slicing it: `array[]` That gives me a range, which I could convert to an array with std.array(Range)(Range r) which I want to avoid.
Re: Convert std.container.array to void[] and/or pass to OpenGL functions like glBuffer(Sub)Data
On Wednesday, 17 June 2015 at 13:31:21 UTC, Marc Schütz wrote: On Wednesday, 17 June 2015 at 13:04:28 UTC, ParticlePeter wrote: I use wrapper functions taking void[] arrays to forward them comfortably to mentioned OpenGL functions. This works with static and dynamic build in arrays, but I don't see a way how I could access (cast) the raw data of a std.container.array to forward it to these wrapper functions. std.array(Range)(Range r) does a copy which I would like to avoid. Any advice ? Would this work? (arr.front)[0 .. arr.length] Unfortunately not: Error: Vector!(float, 3) delegate() pure nothrow @property ref @safe cannot be sliced with [] Fyi, its an std.container.array!( gl3n.Vector!(float, 3) ) array.
Re: Convert std.container.array to void[] and/or pass to OpenGL functions like glBuffer(Sub)Data
On Wednesday, 17 June 2015 at 13:58:09 UTC, Kagamin wrote: (arr.front())[0 .. arr.length] ? Yes, this works, nice, thanks :-)
Re: Convert C array pointer to a D slice without data copy
On Monday, 18 May 2015 at 09:23:26 UTC, tcak wrote: On Monday, 18 May 2015 at 09:18:33 UTC, ParticlePeter wrote: I get the point to an array from a c function, the data size from another function. The data should be only readable at the D side, but I would like to use it as a D slice without copying the data. Is this possible ? char* dataPtr; size_t dataLen; auto data = dataPtr[0 .. dataLen]; This doesn't do any copying. BUT I am not sure what GC would be doing about it. After you use it, you might want to set `data` to null in case of a problem. Thanks, works. Should be in the Interfacing to C Reference Article.
Convert C array pointer to a D slice without data copy
I get the point to an array from a c function, the data size from another function. The data should be only readable at the D side, but I would like to use it as a D slice without copying the data. Is this possible ?
How to translate this to D: const char *const* someConstPtr;
Hi, const char *const* someConstPtr; Error: no identifier for declarator char* Error: declaration expected, not '*' How would I translate this properly to d? Cheers, PP
[DerelictOrg] Forum down ?
Hi, I think I have a bug report for DerelictGL3, but cannot find the related Forum ( http://dblog.aldacron.net/forum/index.php ), is it still in the process of being moved ? Regards, ParticlePeter
Re: [DerelictOrg] Forum down ?
Done On Tuesday, 7 April 2015 at 10:50:35 UTC, Namespace wrote: On Tuesday, 7 April 2015 at 10:48:38 UTC, ParticlePeter wrote: Hi, I think I have a bug report for DerelictGL3, but cannot find the related Forum ( http://dblog.aldacron.net/forum/index.php ), is it still in the process of being moved ? Regards, ParticlePeter Post it there: https://github.com/DerelictOrg/DerelictGL3/issues
Re: [dimgui] building results in 16 warnings, no error BUT: Building .dub\lib\imgui_d.lib failed!
On Saturday, 4 April 2015 at 21:29:57 UTC, Jacques Müller wrote: On Saturday, 4 April 2015 at 18:11:32 UTC, ParticlePeter wrote: Hi, am still searching for the right place to ask library related questions, and was advised to ask them here. The dimgui library looks interesting for my projects ( https://github.com/d-gamedev-team/dimgui ), but I don't manage to get it built or run the examples. I have no clue what's going wrong, as I just get a FAIL message. I use Win 8.1, dmd 2.067 ( and 2.066.1 before that ). I tried to build with dub: FAIL .dub\build\library-debug-windows-x86-dmd_2067-C976DEDDFC09960A5E012C28B5036DF0\ imgui staticLibrary Error executing command run: dmd failed with exit code 1. as well as created visualD project files and build with VS2013: Building .dub\lib\imgui_d.lib failed! How to debug this ? Or anyone with dimgui experience ? Regards, ParticlePeter By default DUB calls the compiler with the command line argument -w, which aborts the compilation if a warning is printed. Add the following line to your dub.json: buildRequirements: [allowWarnings] http://code.dlang.org/package-format#build-requirements Thank you very much, that did the trick!