Re: mixed-in ctor not on par with explicit one?

2016-01-13 Thread Jacob Carlborg via Digitalmars-d-learn

On 2016-01-13 04:32, Shriramana Sharma wrote:

Hello. Compiling the following code:

mixin template intCtor() { this(int i) {} }
struct Test { mixin intCtor; this(string s) {} }
void main()
{
 auto a = Test("hello");
 auto b = Test(1);
}

...gives the error:

(6): Error: constructor .Test.this (string s) is not callable
using argument types (int)

What is the problem in calling the mixed-in ctor?


Mixed in functions are in a different overload set from the context 
where they're mixed in [1].


[1] http://dlang.org/spec/template-mixin.html - search for "Alias 
declarations can be used to overload together functions declared in 
different mixins"


--
/Jacob Carlborg


Re: mixed-in ctor not on par with explicit one?

2016-01-13 Thread Shriramana Sharma via Digitalmars-d-learn
Hello and thanks for your reply.

Jacob Carlborg wrote:

> [1] http://dlang.org/spec/template-mixin.html - search for "Alias
> declarations can be used to overload together functions declared in
> different mixins"

But I'm not able to do that with `this`:

mixin template myCtors()
{
this(int i) {}
this(char c) {}
}
struct Test
{
mixin myCtors;
alias this = myCtors.this;
this(string s) {}
}
void main()
{
auto a = Test("hello");
auto b = Test(1);
auto c = Test('c');
}

But I get the error:

(9): Error: identifier expected following '.', not 'this'
(9): Error: cannot use syntax 'alias this = myCtors', use 'alias 
myCtors this' instead

Even actually giving the mixin instance an identifier doesn't help:

mixin myCtors!() myCtorsInst;
alias this = myCtorsInst.this;

(9): Error: identifier expected following '.', not 'this'
(9): Error: cannot use syntax 'alias this = myCtorsInst', use 'alias 
myCtorsInst this' instead

This is not what alias <> this is supposed to do, right? So how am I 
supposed to get the mixed in ctors work?

-- 
Shriramana Sharma, Penguin #395953



Re: cast fails for classes from windows dll

2016-01-13 Thread Benjamin Thaut via Digitalmars-d-learn

On Tuesday, 12 January 2016 at 19:00:26 UTC, Andre wrote:

Hi,

I am not sure, whether this is a current limitation of the 
windows dll functionality of D

or I am doing s.th. which will not work.

I have developed in D a windows DLL which creates class 
instances by passing the name (using object.factory method).


In another D application I am using this DLL. My issue is, that 
the cast fails, although

typeid(bar).name shows the correct name .


module main;

// these classes are in a seperate module
// used for the dll & for this application
export class Foo {}
export class Bar : Foo {}
class Baz : Bar {}

void main()
{
// this method calls the dll and returns Foo
Foo c = dllCreateClass("main.Baz");

// no failure
assert( typeid(c).name == "main.Baz");

// > fails
if (auto myBar = cast(Bar) c){}
}

Kind regards
André


Thats a limitation of the current dll functionality. The type 
info of the class gets duplciated into both your executable and 
the dll and thus the cast fails. Until D properly supports Dlls 
on windows this is going to stay this way. Currently only a C 
like interface across dll boundaries is possible.


Re: Declaring extern(C) declarations with template mixins

2016-01-13 Thread Jacob Carlborg via Digitalmars-d-learn

On 2016-01-12 22:27, Mathias Lang wrote:


https://issues.dlang.org/show_bug.cgi?id=12575


Thanks.

--
/Jacob Carlborg


Re: Scale-Hierarchy on ndslice

2016-01-13 Thread Ilya Yaroshenko via Digitalmars-d-learn

On Tuesday, 12 January 2016 at 21:48:39 UTC, Per Nordlöw wrote:
Have anybody been thinking about adding a scale-hierarchy 
structure on top of ndslice?


I need this to implementing some cool signal/image processing 
algorithms in D.


When processing an image this structure is called a Mipmap.


If you describe additional required features for ndslice, I will 
think how they can be implemented in the Mir/Phobos. --Ilya


Re: mixed-in ctor not on par with explicit one?

2016-01-13 Thread Shriramana Sharma via Digitalmars-d-learn
Jacob Carlborg wrote:

> Looks like a limitation in the language.

Apparently already reported as well: 
https://issues.dlang.org/show_bug.cgi?id=11500

-- 
Shriramana Sharma, Penguin #395953


Re: mixed-in ctor not on par with explicit one?

2016-01-13 Thread Adam D. Ruppe via Digitalmars-d-learn

On Wednesday, 13 January 2016 at 13:53:01 UTC, Daniel N wrote:

This works:


Indeed... but interestingly, it does not work if you define the 
mixin before the new constructor:


 struct Test
 {
 mixin myCtors  mixed;
 alias __ctor = mixed.__ctor;

 this(string s) {}
 }

l.d(10): Error: alias l.Test.__ctor is not a constructor; 
identifiers starting with __ are reserved for the implementation



So yeah, you can make it work, but there do appear to be a few 
bugs with it anyway.


Re: mixed-in ctor not on par with explicit one?

2016-01-13 Thread Daniel N via Digitalmars-d-learn
On Wednesday, 13 January 2016 at 12:39:36 UTC, Jacob Carlborg 
wrote:

On 2016-01-13 10:48, Shriramana Sharma wrote:


This is not what alias <> this is supposed to do, right?


No.


So how am I supposed to get the mixed in ctors work?


Looks like a limitation in the language.


This works:

mixin template myCtors()
{
this(int i) {}
this(char c) {}
}
struct Test
{
this(string s) {}

mixin myCtors  mixed;
alias __ctor = mixed.__ctor;
}
void main()
{
auto a = Test("hello");
auto b = Test(1);
auto c = Test('c');
}



Re: mixed-in ctor not on par with explicit one?

2016-01-13 Thread Jacob Carlborg via Digitalmars-d-learn

On 2016-01-13 10:48, Shriramana Sharma wrote:


This is not what alias <> this is supposed to do, right?


No.


So how am I supposed to get the mixed in ctors work?


Looks like a limitation in the language.

--
/Jacob Carlborg


Re: Scale-Hierarchy on ndslice

2016-01-13 Thread Per Nordlöw via Digitalmars-d-learn
On Wednesday, 13 January 2016 at 08:31:58 UTC, Ilya Yaroshenko 
wrote:
If you describe additional required features for ndslice, I 
will think how they can be implemented in the Mir/Phobos. --Ilya


Ok, great. BTW: What is Mir?


Re: Scale-Hierarchy on ndslice

2016-01-13 Thread jmh530 via Digitalmars-d-learn

On Tuesday, 12 January 2016 at 21:48:39 UTC, Per Nordlöw wrote:
Have anybody been thinking about adding a scale-hierarchy 
structure on top of ndslice?


What is a scale-hierarchy structure?


Re: Anyone using glad?

2016-01-13 Thread Jason Jeffory via Digitalmars-d-learn

On Wednesday, 13 January 2016 at 18:40:39 UTC, Dav1d wrote:
On Wednesday, 13 January 2016 at 17:43:54 UTC, Jason Jeffory 
wrote:

On Wednesday, 13 January 2016 at 16:04:32 UTC, Dav1d wrote:
On Wednesday, 13 January 2016 at 06:30:44 UTC, Jason Jeffory 
wrote:

[...]


That's not correct.
Build a debug build and check the stacktrace which should be 
printed, if not open gdb or any other debugger and set a 
breakpoint on the exception. Iirc you can break on _d_throw 
and check the stacktrace, then you know where it actually is 
coming from.


Either I don't get what you are talking about, or VS doesn't 
do what you think it does.


When I run the program, this is the stack trace. VS pops up 
with an "Exception has been thrown" window and it highlights 
the "import derelict.glfw3.glfw3;" line. I can't get any 
further than that. It is a debug build. But the except is not 
coming directly from the test.d code.


user32.dll!74d94790 
user32.dll!74d94527 
opengl32.dll!5946caa3   
user32.dll!74db4923 
user32.dll!74d94790 
user32.dll!74d94091 
user32.dll!74d93e50 
glfw3.dll!59525797  
glfw3.dll!5952792c  
 
	test.exe!_D2rt6dmain211_d_run_mainUiPPaPUAAaZiZ6runAllMFZ9__lambda1MFZv() + 0x1b bytes	D
 	test.exe!_D2rt6dmain211_d_run_mainUiPPaPUAAaZiZ6runAllMFZv() 
+ 0x23 bytes	D

test.exe!__d_run_main() + 0x20c bytes   D

test.exe!__entrypoint.main() Line 7 + 0x11 bytesD

test.exe!_mainCRTStartup() + 0xa9 bytes D


I'm not sure what you are expecting to happen. I can't step in 
to anything to see more detail and the lines that VS is 
showing where the problem is, is not steppable. It maybe a 
weird issue with VisualD. I will try gbd for windows, but have 
to install it and learn how to use it.


Yup that trace looks like a glfw issue not sure what causes 
it... that stacktrace on the other hand isn't really that 
helpful, it doesn't show what function call caused it only that 
it happens somewhere in glfw then possibly the driver.


I never used the VS debugger .. so no idea if you're doing it 
wrong or VS is simply not capable of debugging it.


Psudeo gdb session:


r

/* crashes here */

bt full


Or if an exception is thrown


b _d_throw
r
bt full



I don't know ;/ The SIGSEGV happens when I hit a key to exit the 
program.




This binary was built by Equation Solution 
...
Reading symbols from test.exe...(no debugging symbols 
found)...done.

(gdb) r
Starting program: B:\Software\test\test.exe
[New Thread 8660.0x1310]
warning: `C:\Windows\SYSTEM32\ntdll.dll': Shared library 
architecture i386:x86-64 is not compatible with target 
architecture i386.
warning: `C:\Windows\system32\wow64.dll': Shared library 
architecture i386:x86-64 is not compatible with target 
architecture i386.
warning: `C:\Windows\system32\wow64win.dll': Shared library 
architecture i386:x86-64 is not compatible with target 
architecture i386.
warning: Could not load shared library symbols for 
WOW64_IMAGE_SECTION.

Do you need "set solib-search-path" or "set sysroot"?
warning: Could not load shared library symbols for 
WOW64_IMAGE_SECTION.

Do you need "set solib-search-path" or "set sysroot"?
warning: Could not load shared library symbols for NOT_AN_IMAGE.
Do you need "set solib-search-path" or "set sysroot"?
warning: Could not load shared library symbols for NOT_AN_IMAGE.
Do you need "set solib-search-path" or "set sysroot"?
warning: `C:\Windows\system32\wow64cpu.dll': Shared library 
architecture i386:x86-64 is not compatible with target 
architecture i386.

[New Thread 8660.0x1160]
[New Thread 8660.0xe00]
[New Thread 8660.0x2068]
[New Thread 8660.0xb58]
[New Thread 8660.0x231c]
[New Thread 8660.0x1b3c]
[New Thread 8660.0x21bc]
[Thread 8660.0xb58 exited with code 0]
[New Thread 8660.0x2488]
[Thread 8660.0x1b3c exited with code 0]
[New Thread 8660.0x27cc]
[New Thread 8660.0x237c]
[Thread 8660.0x237c exited with code 0]
[Thread 8660.0x27cc exited with code 0]
[New Thread 8660.0x2088]
[New Thread 8660.0x241c]
OpenGL Version 3.3 loaded
Key Pressed = 32 <-- I hit a key to exit and the 
SIGSEGV happens


Program received signal SIGSEGV, Segmentation fault.
0x002b in ?? ()
(gdb) bt full
#0  0x002b in ?? ()
No symbol table info available.
Cannot access memory at address 0x44
(gdb) b _d_throw
Function "_d_throw" not defined.
Make breakpoint pending on future shared library load? (y or [n]) 
y

Breakpoint 1 (_d_throw) pending.
(gdb) r
The program being debugged has been started already.
Start it from the beginning? (y or n) y
Starting program: B:\Software\test\test.exe
[New Thread 8408.0x1a5c]
warning: `C:\Windows\SYSTEM32\ntdll.dll': Shared library 
architecture i386:x86-64 is not compatible with target 
architecture i386.
warning: `C:\Windows\system32\wow64.dll': Shared library 
architecture i386:x86-64 is not compatible with target 
architecture i386.
warning: 

Re: Anyone using glad?

2016-01-13 Thread Dav1d via Digitalmars-d-learn
On Wednesday, 13 January 2016 at 19:20:40 UTC, Jason Jeffory 
wrote:

What I can't seem to figure out why

try { loop }
catch
{

}

catches the exception but

try { loop }
catch (Throwable t) // Only diff
{

}

doesn't ;/ Probably my ignorance about D, but I was hoping to 
get some info about the exception this way(line number, etc...)


This is not an exception you should catch at all. Also pretty 
sure this wont work with 64bit binaries.
D does realize a segmentation fault, access to invalid memory, 
that's nothing a program should simply catch and then silently 
ignore, the issue causing it needs to be addressed.


Also why doesn't your key_callback not to be extern(C), I thought 
that was required.


'Reading symbols from test.exe...(no debugging symbols 
found)...done.', you arent gonna get any useful information 
without debug symbols. Also additionally use a glfw debug build.


Glad and WGL

2016-01-13 Thread Josh Phillips via Digitalmars-d-learn
So I started using Glad but I can't get WGL to work with it, 
though I think this is more of a Win32 issue than WGL.


wndclass.lpfnWndProc   = 

Gives me an error no matter what:
Error: cannot implicitly convert expression (& WndProc) of type 
int function(void* hWnd, uint message, uint wParam, int lParam) 
to extern (Windows) int function(void*, uint, uint, int) nothrow


I think the error has to do with the nothrow but I tried making 
the function empty


extern(Windows)
LRESULT WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM 
lParam)

{
   return 0;
}

And still got the same exact error. Any ideas/help?


Re: Glad and WGL

2016-01-13 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 13 January 2016 at 18:34:14 UTC, Josh Phillips 
wrote:

extern(Windows)
LRESULT WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM 
lParam)


You just need to explicitly mark it nothrow in the signature. Add 
`nothrow` to the end of the param list:


extern(Windows)
LRESULT WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM 
lParam) nothrow


and then you'll be cool


Re: Glad and WGL

2016-01-13 Thread Dav1d via Digitalmars-d-learn
On Wednesday, 13 January 2016 at 18:34:14 UTC, Josh Phillips 
wrote:
So I started using Glad but I can't get WGL to work with it, 
though I think this is more of a Win32 issue than WGL.


wndclass.lpfnWndProc   = 

Gives me an error no matter what:
Error: cannot implicitly convert expression (& WndProc) of type 
int function(void* hWnd, uint message, uint wParam, int lParam) 
to extern (Windows) int function(void*, uint, uint, int) nothrow


I think the error has to do with the nothrow but I tried making 
the function empty


extern(Windows)
LRESULT WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM 
lParam)

{
   return 0;
}

And still got the same exact error. Any ideas/help?


Your function isnt marked nothrow.


Re: Anyone using glad?

2016-01-13 Thread Dav1d via Digitalmars-d-learn
On Wednesday, 13 January 2016 at 17:43:54 UTC, Jason Jeffory 
wrote:

On Wednesday, 13 January 2016 at 16:04:32 UTC, Dav1d wrote:
On Wednesday, 13 January 2016 at 06:30:44 UTC, Jason Jeffory 
wrote:

[...]


That's not correct.
Build a debug build and check the stacktrace which should be 
printed, if not open gdb or any other debugger and set a 
breakpoint on the exception. Iirc you can break on _d_throw 
and check the stacktrace, then you know where it actually is 
coming from.


Either I don't get what you are talking about, or VS doesn't do 
what you think it does.


When I run the program, this is the stack trace. VS pops up 
with an "Exception has been thrown" window and it highlights 
the "import derelict.glfw3.glfw3;" line. I can't get any 
further than that. It is a debug build. But the except is not 
coming directly from the test.d code.


user32.dll!74d94790 
user32.dll!74d94527 
opengl32.dll!5946caa3   
user32.dll!74db4923 
user32.dll!74d94790 
user32.dll!74d94091 
user32.dll!74d93e50 
glfw3.dll!59525797  
glfw3.dll!5952792c  
 
	test.exe!_D2rt6dmain211_d_run_mainUiPPaPUAAaZiZ6runAllMFZ9__lambda1MFZv() + 0x1b bytes	D
 	test.exe!_D2rt6dmain211_d_run_mainUiPPaPUAAaZiZ6runAllMFZv() 
+ 0x23 bytes	D

test.exe!__d_run_main() + 0x20c bytes   D

test.exe!__entrypoint.main() Line 7 + 0x11 bytesD

test.exe!_mainCRTStartup() + 0xa9 bytes D


I'm not sure what you are expecting to happen. I can't step in 
to anything to see more detail and the lines that VS is showing 
where the problem is, is not steppable. It maybe a weird issue 
with VisualD. I will try gbd for windows, but have to install 
it and learn how to use it.


Yup that trace looks like a glfw issue not sure what causes it... 
that stacktrace on the other hand isn't really that helpful, it 
doesn't show what function call caused it only that it happens 
somewhere in glfw then possibly the driver.


I never used the VS debugger .. so no idea if you're doing it 
wrong or VS is simply not capable of debugging it.


Psudeo gdb session:


r

/* crashes here */

bt full


Or if an exception is thrown


b _d_throw
r
bt full


Re: Linking a DLL to a DLL with packages

2016-01-13 Thread Thalamus via Digitalmars-d-learn

On Sunday, 10 January 2016 at 15:58:55 UTC, Benjamin Thaut wrote:

Am 09.01.2016 um 16:45 schrieb Thalamus:


Hi Benjamin,

I wouldn't say I need DLLs to work fully _really_ badly. The 
only
non-negligible issue with single very large binaries that's 
crossed my
mind is patching, but we're years away from having to worry 
about that
too much. That being said, I'm definitely willing to do some 
testing,
especially for something that helps us down the road. I'll 
follow up

with you offline. Thanks!



Great, some help with bugfixing and testing would be greatly 
apreciated. I didn't get any e-mail from you yet, I assume you 
didn't send one?


Kind Regards
Benjamin Thaut


Hi Benjamin. Sorry for the delay. It's been a very busy week. I 
just hit Send on a mail to you.




Re: Scale-Hierarchy on ndslice

2016-01-13 Thread Timothee Cour via Digitalmars-d-learn
On Wed, Jan 13, 2016 at 10:13 AM, jmh530 via Digitalmars-d-learn <
digitalmars-d-learn@puremagic.com> wrote:

> On Tuesday, 12 January 2016 at 21:48:39 UTC, Per Nordlöw wrote:
>
>> Have anybody been thinking about adding a scale-hierarchy structure on
>> top of ndslice?
>>
>
> What is a scale-hierarchy structure?
>

https://en.wikipedia.org/wiki/Mipmap

but isn't it out of scope?
Looks like it would belong more to an image processing library (building on
top of ndslice)


Re: Compiler complaining about ~ used on static array in @nogc fn

2016-01-13 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Jan 13, 2016 at 10:23:17PM +0530, Shriramana Sharma via 
Digitalmars-d-learn wrote:
> Referring to: 
> https://auto-tester.puremagic.com/show-run.ghtml?projectid=1=1915054=true,
>  the lines in question are 
> phobos/std/utf.d (66, 67):
> 
> UnsignedStringBuf buf = void;
> msg ~= " (at index " ~ unsignedToTempString(index, buf, 10) ~ ")";
> 
> rgrepping through the druntime and phobos sources for this symbol
> UnsignedStringBuf I found:
> 
> ./druntime/src/core/internal/string.d:16:alias UnsignedStringBuf = char[20];
> 
> So if it's a static array, then it has nothing to do with the GC, and
> appending will not use the GC, right? So why is the compiler
> complaining that I cannot use ~ inside a @nogc function?
[...]

Even though unsignedToTempString() uses a static array, `msg` is a
string, so appending to it using ~ or ~= may cause reallocation. That
violates @nogc.


T

-- 
Computers shouldn't beep through the keyhole.


Re: Glad and WGL

2016-01-13 Thread Josh Phillips via Digitalmars-d-learn
On Wednesday, 13 January 2016 at 18:37:09 UTC, Adam D. Ruppe 
wrote:
You just need to explicitly mark it nothrow in the signature. 
Add `nothrow` to the end of the param list:


extern(Windows)
LRESULT WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM 
lParam) nothrow


and then you'll be cool


Oh wow that's easy. They should really make that more clear in 
the dlang reference. They way it sounds there made me think that 
if a function doesn't throw any errors it automatically is 
'nothrow'


@Dav1d do I need to implicitly link WGL to any dlls or anything? 
Now I'm getting linking errors


..\dlibgui\lib\dlibgui.lib(window)
 Error 42: Symbol Undefined _wglMakeCurrent@8
..\dlibgui\lib\dlibgui.lib(window)
 Error 42: Symbol Undefined _wglCreateContext@4
..\dlibgui\lib\dlibgui.lib(window)
 Error 42: Symbol Undefined _ChoosePixelFormat@8
..\dlibgui\lib\dlibgui.lib(window)
 Error 42: Symbol Undefined _SetPixelFormat@12
..\dlibgui\lib\dlibgui.lib(window)
 Error 42: Symbol Undefined _wglDeleteContext@4
--- errorlevel 5
dmd failed with exit code 5.


Re: Anyone using glad?

2016-01-13 Thread Jason Jeffory via Digitalmars-d-learn

What I can't seem to figure out why

try { loop }
catch
{

}

catches the exception but

try { loop }
catch (Throwable t) // Only diff
{

}

doesn't ;/ Probably my ignorance about D, but I was hoping to get 
some info about the exception this way(line number, etc...)







Output range of ranges to single buffer

2016-01-13 Thread Jacob Carlborg via Digitalmars-d-learn
Is it possible to somehow output a range of ranges to a single string 
buffer? For example, converting an array of integers to a string with 
the same representation as the source code.


import std.algorithm;
import std.conv;
import std.string;

void main()
{
auto a = [1, 2, 3, 4, 5];
auto b = '[' ~ a.map!(e => e.to!string).join(", ") ~ ']';
assert(b == "[1, 2, 3, 4, 5]");
}

The above code is straight forward. But I would like to avoid creating 
the intermediate strings, "e.to!string", and instead put the converted 
integer and the result of join directly in the same buffer.


A bit more complex example:

struct Foo
{
int a;
string b;
int c;

string toString()
{
auto values = [a.to!string, b, c.to!string].join(", ");
return "Foo(" ~ values ~ ')';
}
}

void main()
{
auto a = [
Foo(1, "foo", 2),
Foo(3, "bar", 4)
];

auto b = '[' ~ a.map!(e => e.to!string).join(", ") ~ ']';
assert(b == "[Foo(1, foo, 2), Foo(3, bar, 4)]");
}

--
/Jacob Carlborg


Re: Scale-Hierarchy on ndslice

2016-01-13 Thread Ilya Yaroshenko via Digitalmars-d-learn

On Wednesday, 13 January 2016 at 18:09:06 UTC, Per Nordlöw wrote:
On Wednesday, 13 January 2016 at 08:31:58 UTC, Ilya Yaroshenko 
wrote:
If you describe additional required features for ndslice, I 
will think how they can be implemented in the Mir/Phobos. 
--Ilya


Ok, great. BTW: What is Mir?


https://github.com/DlangScience/mir --Ilya


Re: Glad and WGL

2016-01-13 Thread Dav1d via Digitalmars-d-learn
On Wednesday, 13 January 2016 at 19:05:30 UTC, Josh Phillips 
wrote:
On Wednesday, 13 January 2016 at 18:37:09 UTC, Adam D. Ruppe 
wrote:

[...]


Oh wow that's easy. They should really make that more clear in 
the dlang reference. They way it sounds there made me think 
that if a function doesn't throw any errors it automatically is 
'nothrow'


[...]


Link with opengl32.lib


Re: Anyone using glad?

2016-01-13 Thread Jason Jeffory via Digitalmars-d-learn

On Wednesday, 13 January 2016 at 20:13:49 UTC, Dav1d wrote:
On Wednesday, 13 January 2016 at 19:20:40 UTC, Jason Jeffory 
wrote:

What I can't seem to figure out why

try { loop }
catch
{

}

catches the exception but

try { loop }
catch (Throwable t) // Only diff
{

}

doesn't ;/ Probably my ignorance about D, but I was hoping to 
get some info about the exception this way(line number, etc...)


This is not an exception you should catch at all. Also pretty 
sure this wont work with 64bit binaries.
D does realize a segmentation fault, access to invalid memory, 
that's nothing a program should simply catch and then silently 
ignore, the issue causing it needs to be addressed.




It was for testing purposes and to try and figure out what is 
going on.


Also why doesn't your key_callback not to be extern(C), I 
thought that was required.


The app never exits with extern(C), it doesn't crash though.

'Reading symbols from test.exe...(no debugging symbols 
found)...done.', you arent gonna get any useful information 
without debug symbols. Also additionally use a glfw debug build.


Why aren't the debug symbols added in a debug build? Makes no 
sense!


I don't have a debug build of glfw.

...

After an few hours of fucking with cmake, turns out it had a bug. 
Updated it and worked. Pretty much through with this crap. I'm 
not going to waste any more time screwing with the dysfunctional 
approach that software design is taking. I appreciate your help. 
See you on the flip side! Have fun crawling through the sewers of 
"modern" programming!






Re: Output range of ranges to single buffer

2016-01-13 Thread Jacob Carlborg via Digitalmars-d-learn

On 2016-01-13 22:20, H. S. Teoh via Digitalmars-d-learn wrote:


Isn't that just a matter of replacing each of the segments with their
range equivalents? Also, std.format.formattedWrite will do
writeln-formatting into a buffer (well, any output range, really) -- I'm
pretty sure it doesn't allocate, at least for the simplest cases like
converting an integer. So you should be able to do something like this:

auto data = [ 1, 2, 3, 4, 5 ];
char[] buf = ...;
formattedWrite(buf, "[%(%d, %)]", data);


Aha, interesting. I didn't know formattedWrite could format an 
array/range directly like that.


The more complex example works by defining "toString" which takes an 
output range (delegate). But what if I need to format a third party type 
that I cannot add methods to? UFCS does not seem to work.


--
/Jacob Carlborg


Re: Output range of ranges to single buffer

2016-01-13 Thread Dav1d via Digitalmars-d-learn
On Wednesday, 13 January 2016 at 21:15:03 UTC, Jacob Carlborg 
wrote:
Is it possible to somehow output a range of ranges to a single 
string buffer? For example, converting an array of integers to 
a string with the same representation as the source code.


[...]


std.format can do it. From the site:


import std.stdio;

void main()
{
writefln("My items are %(%s %).", [1,2,3]);
writefln("My items are %(%s, %).", [1,2,3]);
}


Re: Output range of ranges to single buffer

2016-01-13 Thread Ali Çehreli via Digitalmars-d-learn

On 01/13/2016 01:20 PM, H. S. Teoh via Digitalmars-d-learn wrote:


std.format.formattedWrite will do
writeln-formatting into a buffer (well, any output range, really) -- I'm
pretty sure it doesn't allocate, at least for the simplest cases like
converting an integer. So you should be able to do something like this:

auto data = [ 1, 2, 3, 4, 5 ];
char[] buf = ...;
formattedWrite(buf, "[%(%d, %)]", data);


And buf can be an Appender:

import std.stdio;
import std.format;
import std.array;

void main() {
auto data = [ 1, 2, 3, 4, 5 ];

auto buf = appender!string(); // Or appender!(char[]) if needed
formattedWrite(buf, "[%(%d, %)]", data);

assert(buf.data == "[1, 2, 3, 4, 5]");
}

Ali



Re: Output range of ranges to single buffer

2016-01-13 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Jan 13, 2016 at 10:15:03PM +0100, Jacob Carlborg via 
Digitalmars-d-learn wrote:
> Is it possible to somehow output a range of ranges to a single string
> buffer? For example, converting an array of integers to a string with
> the same representation as the source code.
> 
> import std.algorithm;
> import std.conv;
> import std.string;
> 
> void main()
> {
> auto a = [1, 2, 3, 4, 5];
> auto b = '[' ~ a.map!(e => e.to!string).join(", ") ~ ']';
> assert(b == "[1, 2, 3, 4, 5]");
> }
> 
> The above code is straight forward. But I would like to avoid creating
> the intermediate strings, "e.to!string", and instead put the converted
> integer and the result of join directly in the same buffer.

Isn't that just a matter of replacing each of the segments with their
range equivalents? Also, std.format.formattedWrite will do
writeln-formatting into a buffer (well, any output range, really) -- I'm
pretty sure it doesn't allocate, at least for the simplest cases like
converting an integer. So you should be able to do something like this:

auto data = [ 1, 2, 3, 4, 5 ];
char[] buf = ...;
formattedWrite(buf, "[%(%d, %)]", data);


T

-- 
Customer support: the art of getting your clients to pay for your own 
incompetence.


Re: Anyone using glad?

2016-01-13 Thread Dav1d via Digitalmars-d-learn
On Wednesday, 13 January 2016 at 22:51:45 UTC, Jason Jeffory 
wrote:
After an few hours of fucking with cmake, turns out it had a 
bug. Updated it and worked. Pretty much through with this crap. 
I'm not going to waste any more time screwing with the 
dysfunctional approach that software design is taking. I 
appreciate your help. See you on the flip side! Have fun 
crawling through the sewers of "modern" programming!


Welcome to Windows


Re: Scale-Hierarchy on ndslice

2016-01-13 Thread Ilya via Digitalmars-d-learn
On Wednesday, 13 January 2016 at 20:11:55 UTC, Timothee Cour 
wrote:
On Wed, Jan 13, 2016 at 10:13 AM, jmh530 via 
Digitalmars-d-learn < digitalmars-d-learn@puremagic.com> wrote:



On Tuesday, 12 January 2016 at 21:48:39 UTC, Per Nordlöw wrote:

Have anybody been thinking about adding a scale-hierarchy 
structure on top of ndslice?




What is a scale-hierarchy structure?



https://en.wikipedia.org/wiki/Mipmap

but isn't it out of scope?
Looks like it would belong more to an image processing library 
(building on

top of ndslice)


For example, interpolation algorithms like cubic can be 
generalized. They can be used in physics. In addition, 
interpolation can be lazy.


https://en.wikipedia.org/wiki/Bicubic_interpolation
https://en.wikipedia.org/wiki/Tricubic_interpolation

--Ilya


Re: Glad and WGL

2016-01-13 Thread userABCabc123 via Digitalmars-d-learn
On Wednesday, 13 January 2016 at 19:05:30 UTC, Josh Phillips 
wrote:
Oh wow that's easy. They should really make that more clear in 
the dlang reference. They way it sounds there made me think 
that if a function doesn't throw any errors it automatically is 
'nothrow'


No, because actually you can have a function that uses 
sub-functions that throw, but marked explicitly nothrow, because 
it hides the stuff under the carpet.


---
void bar()
{
throw new Exception("kaboom");
}

void foo() nothrow
{
  try {bar;}
  catch {/*under the carpet*/}
}
---

and that will compile.


Re: Glad and WGL

2016-01-13 Thread Josh Phillips via Digitalmars-d-learn

On Thursday, 14 January 2016 at 02:16:40 UTC, userABCabc123 wrote:
On Wednesday, 13 January 2016 at 19:05:30 UTC, Josh Phillips 
wrote:
Oh wow that's easy. They should really make that more clear in 
the dlang reference. They way it sounds there made me think 
that if a function doesn't throw any errors it automatically 
is 'nothrow'


No, because actually you can have a function that uses 
sub-functions that throw, but marked explicitly nothrow, 
because it hides the stuff under the carpet.


---
void bar()
{
throw new Exception("kaboom");
}

void foo() nothrow
{
  try {bar;}
  catch {/*under the carpet*/}
}
---

and that will compile.


Ok? I'm not sure what you are saying no to and I understand this. 
It makes sense because foo catches bar's error and doesn't throw 
it up and further. I was just saying that the reference here 
https://dlang.org/spec/function.html was not all that clear since 
the section entitled nothrow merely states:


"Nothrow functions do not throw any exceptions derived from class 
Exception.

Nothrow functions are covariant with throwing ones."

A deeper search on the page made me realize that there are more 
examples later which clarify how to declare a "nothrow" function 
however I didn't bother looking deeper at the time since the main 
section for nothrows gave no indication that I should.


Re: Glad and WGL

2016-01-13 Thread Josh Phillips via Digitalmars-d-learn

On Wednesday, 13 January 2016 at 20:08:55 UTC, Dav1d wrote:

Link with opengl32.lib


How? Everywhere I looked it says this cannot be done due to 
conflicting formats between the dmd compiler and the windows one.


Re: Anyone using glad?

2016-01-13 Thread Dav1d via Digitalmars-d-learn
On Wednesday, 13 January 2016 at 06:30:44 UTC, Jason Jeffory 
wrote:

On Tuesday, 12 January 2016 at 20:48:37 UTC, Dav1d wrote:
On Tuesday, 12 January 2016 at 19:16:51 UTC, Jason Jeffory 
wrote:

[...]


Yup, that's a little bit annoying on Windows (also as 
mentioned before the deimos bindings weren't updated in a 
while, might contribute to your issue).



[...]


What does a debugger say? Where is it coming from?



It doesn't I put a break point on the glfwTerminate() and what 
visual studio/d shows is something in the "import 
derelict.glfw3.glfw3;" statement.



Well, a BP on on glfwTerminate is never reached. Hence it must 
be before that. The loop should work fine because it works 
already. One would think it is the while 
(!glfwWindowShouldClose(window)), but using just a global 
variable still causes the exception.


Hence the logical place the except should be occurring is

glfwPollEvents();

If I remove it and just use a counter and exit after while, 
then there is no exception. Hence, it must be glfwPollEvents();


But what can I do about that? Must be an issue with Derelict or 
glfw! Since Derelict is just bindings, it suggests glfw. But 
what possibly could be wrong?


That's not correct.
Build a debug build and check the stacktrace which should be 
printed, if not open gdb or any other debugger and set a 
breakpoint on the exception. Iirc you can break on _d_throw and 
check the stacktrace, then you know where it actually is coming 
from.




Compiler complaining about ~ used on static array in @nogc fn

2016-01-13 Thread Shriramana Sharma via Digitalmars-d-learn
Referring to: 
https://auto-tester.puremagic.com/show-run.ghtml?projectid=1=1915054=true,
 the lines in question are 
phobos/std/utf.d (66, 67):

UnsignedStringBuf buf = void;
msg ~= " (at index " ~ unsignedToTempString(index, buf, 10) ~ ")";

rgrepping through the druntime and phobos sources for this symbol 
UnsignedStringBuf I found:

./druntime/src/core/internal/string.d:16:alias UnsignedStringBuf = char[20];

So if it's a static array, then it has nothing to do with the GC, and 
appending will not use the GC, right? So why is the compiler complaining 
that I cannot use ~ inside a @nogc function?

-- 
Shriramana Sharma, Penguin #395953


Re: Anyone using glad?

2016-01-13 Thread Jason Jeffory via Digitalmars-d-learn

On Wednesday, 13 January 2016 at 16:04:32 UTC, Dav1d wrote:
On Wednesday, 13 January 2016 at 06:30:44 UTC, Jason Jeffory 
wrote:

On Tuesday, 12 January 2016 at 20:48:37 UTC, Dav1d wrote:
On Tuesday, 12 January 2016 at 19:16:51 UTC, Jason Jeffory 
wrote:

[...]


Yup, that's a little bit annoying on Windows (also as 
mentioned before the deimos bindings weren't updated in a 
while, might contribute to your issue).



[...]


What does a debugger say? Where is it coming from?



It doesn't I put a break point on the glfwTerminate() and what 
visual studio/d shows is something in the "import 
derelict.glfw3.glfw3;" statement.



Well, a BP on on glfwTerminate is never reached. Hence it must 
be before that. The loop should work fine because it works 
already. One would think it is the while 
(!glfwWindowShouldClose(window)), but using just a global 
variable still causes the exception.


Hence the logical place the except should be occurring is

glfwPollEvents();

If I remove it and just use a counter and exit after while, 
then there is no exception. Hence, it must be glfwPollEvents();


But what can I do about that? Must be an issue with Derelict 
or glfw! Since Derelict is just bindings, it suggests glfw. 
But what possibly could be wrong?


That's not correct.
Build a debug build and check the stacktrace which should be 
printed, if not open gdb or any other debugger and set a 
breakpoint on the exception. Iirc you can break on _d_throw and 
check the stacktrace, then you know where it actually is coming 
from.


Either I don't get what you are talking about, or VS doesn't do 
what you think it does.


When I run the program, this is the stack trace. VS pops up with 
an "Exception has been thrown" window and it highlights the 
"import derelict.glfw3.glfw3;" line. I can't get any further than 
that. It is a debug build. But the except is not coming directly 
from the test.d code.


user32.dll!74d94790 
user32.dll!74d94527 
opengl32.dll!5946caa3   
user32.dll!74db4923 
user32.dll!74d94790 
user32.dll!74d94091 
user32.dll!74d93e50 
glfw3.dll!59525797  
glfw3.dll!5952792c  
 
	test.exe!_D2rt6dmain211_d_run_mainUiPPaPUAAaZiZ6runAllMFZ9__lambda1MFZv() + 0x1b bytes	D
 	test.exe!_D2rt6dmain211_d_run_mainUiPPaPUAAaZiZ6runAllMFZv() + 
0x23 bytes	D

test.exe!__d_run_main() + 0x20c bytes   D

test.exe!__entrypoint.main() Line 7 + 0x11 bytesD

test.exe!_mainCRTStartup() + 0xa9 bytes D


I'm not sure what you are expecting to happen. I can't step in to 
anything to see more detail and the lines that VS is showing 
where the problem is, is not steppable. It maybe a weird issue 
with VisualD. I will try gbd for windows, but have to install it 
and learn how to use it.