Re: GTKD - CSS class color "flash" delay
On Saturday, 25 June 2016 at 21:57:35 UTC, TheDGuy wrote: But i want to flash (e.g. change the CSS class) the buttons one by one and not all at the sime time? How am i going to do that? Okay, i tried it with a new private int-variable which contains the current index of the for-loop, like this: private void letButtonsFlash(){ foreach(Button btn;bArr){ btn.setSensitive(false); } for(int i = 0; i < level; i++){ index = i; //index is public Button currentButton = bArr[rndButtonBlink[i]]; ListG list = currentButton.getStyleContext().listClasses(); string CSSClassName = to!string(cast(char*)list.next().data); currentButton.getStyleContext().addClass(CSSClassName ~ "-flash"); Timeout t = new Timeout(&timeout_delay,1,false); } foreach(Button btn;bArr){ btn.setSensitive(true); } } bool timeout_delay(){ Button currentButton = bArr[rndButtonBlink[index]]; ListG list = currentButton.getStyleContext().listClasses(); string CSSClassName = to!string(cast(char*)list.next().data); currentButton.getStyleContext().removeClass(CSSClassName ~ "-flash"); return false; } But now the strange thing happens, that the first button lights up as expected but the second button remains at its "flash color" and doesn't go back to normal color, i don't understand why this happens? Any ideas?
Re: GTKD - CSS class color "flash" delay
On Saturday, 25 June 2016 at 20:39:53 UTC, Mike Wey wrote: The constructor accepts an delegate, witch can access it's context so it has access to some of the data. The functions from GTK are also available like Timeout.add from the linked tutorial: http://api.gtkd.org/src/glib/Timeout.html#Timeout.add You may want to do something like this: ``` private void letButtonsFlash() { foreach(Button btn;bArr){ btn.setSensitive(false); } Timeout t = new Timeout(&timeout_delay,5,false); } private bool timeout_delay() { for(int i = 0; i < level; i++){ Button currentButton = bArr[rndButtonBlink[i]]; ListG list = currentButton.getStyleContext().listClasses(); string CSSClassName = to!string(cast(char*)list.next().data); currentButton.getStyleContext().addClass(CSSClassName ~ "-flash"); } return false; } ``` Thanks a lot for your answer, i tried it like this and it works: private void letButtonsFlash(){ foreach(Button btn;bArr){ btn.setSensitive(false); } for(int i = 0; i < level; i++){ Button currentButton = bArr[rndButtonBlink[i]]; ListG list = currentButton.getStyleContext().listClasses(); string CSSClassName = to!string(cast(char*)list.next().data); currentButton.getStyleContext().addClass(CSSClassName ~ "-flash"); } Timeout t = new Timeout(&timeout_delay,1,false); foreach(Button btn;bArr){ btn.setSensitive(true); } } bool timeout_delay(){ for(int i = 0; i < level; i++){ Button currentButton = bArr[rndButtonBlink[i]]; ListG list = currentButton.getStyleContext().listClasses(); string CSSClassName = to!string(cast(char*)list.next().data); currentButton.getStyleContext().removeClass(CSSClassName ~ "-flash"); } return false; } But i want to flash (e.g. change the CSS class) the buttons one by one and not all at the sime time? How am i going to do that?
Re: GTKD - CSS class color "flash" delay
On 06/25/2016 05:26 PM, TheDGuy wrote: On Saturday, 25 June 2016 at 13:01:09 UTC, TheDGuy wrote: Thanks for your answer. I have to pass the Button object to my timeout function to change the CSS class. But how do i do that within the Timeout constructor? I mean: I have to pass my function and delay time to the constructor, but i can't pass any data to the function here, also only functions are allowed (at least it looks like that to me) who don't have parameters. If i want to add a new function i have to use the function .add(), with this function i can pass 'userData' (so my button for example). But why am i unable to do that in the constructor? Do i have 2 different functions for the same thing, one with the other one without parameter? My current approach: private void letButtonsFlash(){ foreach(Button btn;bArr){ btn.setSensitive(false); } for(int i = 0; i < level; i++){ Button currentButton = bArr[rndButtonBlink[i]]; ListG list = currentButton.getStyleContext().listClasses(); string CSSClassName = to!string(cast(char*)list.next().data); currentButton.getStyleContext().addClass(CSSClassName ~ "-flash"); //writeln(CSSClassName); Timeout t = new Timeout(&timeout_delay,5,false); //error appears here t.add(5,&timeout_delay,currentButton); } foreach(Button btn;bArr){ btn.setSensitive(true); } } bool timeout_delay(Button currentButton){ ListG list = currentButton.getStyleContext().listClasses(); string CSSClassName = to!string(cast(char*)list.next().data); currentButton.getStyleContext().removeClass(CSSClassName ~ "-flash"); return false; } But i get the error: Error: none of the overloads of '__ctor' are callable using argument types (bool delegate(void* userData), int, bool), candidates are: glib.Timeout.Timeout.this(uint interval, bool delegate() dlg, bool fireNow = false) glib.Timeout.Timeout.this(uint interval, bool delegate() dlg, GPriority priority, bool fireNow = false) glib.Timeout.Timeout.this(bool delegate() dlg, uint seconds, bool fireNow = false) glib.Timeout.Timeout.this(bool delegate() dlg, uint seconds, GPriority priority, bool fireNow = false) If i take a look at GTK for C it looks like there is a function for that: http://www.gtk.org/tutorial1.2/gtk_tut-17.html Why is this so confusing? The constructor accepts an delegate, witch can access it's context so it has access to some of the data. The functions from GTK are also available like Timeout.add from the linked tutorial: http://api.gtkd.org/src/glib/Timeout.html#Timeout.add You may want to do something like this: ``` private void letButtonsFlash() { foreach(Button btn;bArr){ btn.setSensitive(false); } Timeout t = new Timeout(&timeout_delay,5,false); } private bool timeout_delay() { for(int i = 0; i < level; i++){ Button currentButton = bArr[rndButtonBlink[i]]; ListG list = currentButton.getStyleContext().listClasses(); string CSSClassName = to!string(cast(char*)list.next().data); currentButton.getStyleContext().addClass(CSSClassName ~ "-flash"); } return false; } ``` -- Mike Wey
Re: Does D has any support for thunks?
On Saturday, 25 June 2016 at 17:26:03 UTC, Andre Pany wrote: On Saturday, 25 June 2016 at 16:05:30 UTC, Vladimir Panteleev wrote: On Saturday, 25 June 2016 at 13:44:48 UTC, Andre Pany wrote: Does D/Phobos has any support for thunks? Made this a while ago: http://stackoverflow.com/a/8656294/21501 Thanks, I had a look. Unfortunately it doesn't compile for my use case. SetWindowsHookEx expects an "extern(windows)" and "nothrow" function. delegate2function does not accept a delegate with If it is possible to make this coding generic, it would fit into std.functional. Kind regards André ... does not accept a delegate with extern(windows).
Re: Does D has any support for thunks?
On Saturday, 25 June 2016 at 16:05:30 UTC, Vladimir Panteleev wrote: On Saturday, 25 June 2016 at 13:44:48 UTC, Andre Pany wrote: Does D/Phobos has any support for thunks? Made this a while ago: http://stackoverflow.com/a/8656294/21501 Thanks, I had a look. Unfortunately it doesn't compile for my use case. SetWindowsHookEx expects an "extern(windows)" and "nothrow" function. delegate2function does not accept a delegate with If it is possible to make this coding generic, it would fit into std.functional. Kind regards André
Re: Does D has any support for thunks?
On Saturday, 25 June 2016 at 13:44:48 UTC, Andre Pany wrote: Does D/Phobos has any support for thunks? Made this a while ago: http://stackoverflow.com/a/8656294/21501
Re: GTKD - CSS class color "flash" delay
On Saturday, 25 June 2016 at 15:26:00 UTC, TheDGuy wrote: } But i get the error: Error: none of the overloads of '__ctor' are callable using argument types (bool delegate(void* userData), int, bool), candidates are: This is the correct error message: Error: none of the overloads of '__ctor' are callable using argument types (bool delegate(Button currentButton), int, bool), candidates are:
Re: GTKD - CSS class color "flash" delay
On Saturday, 25 June 2016 at 13:01:09 UTC, TheDGuy wrote: Thanks for your answer. I have to pass the Button object to my timeout function to change the CSS class. But how do i do that within the Timeout constructor? I mean: I have to pass my function and delay time to the constructor, but i can't pass any data to the function here, also only functions are allowed (at least it looks like that to me) who don't have parameters. If i want to add a new function i have to use the function .add(), with this function i can pass 'userData' (so my button for example). But why am i unable to do that in the constructor? Do i have 2 different functions for the same thing, one with the other one without parameter? My current approach: private void letButtonsFlash(){ foreach(Button btn;bArr){ btn.setSensitive(false); } for(int i = 0; i < level; i++){ Button currentButton = bArr[rndButtonBlink[i]]; ListG list = currentButton.getStyleContext().listClasses(); string CSSClassName = to!string(cast(char*)list.next().data); currentButton.getStyleContext().addClass(CSSClassName ~ "-flash"); //writeln(CSSClassName); Timeout t = new Timeout(&timeout_delay,5,false); //error appears here t.add(5,&timeout_delay,currentButton); } foreach(Button btn;bArr){ btn.setSensitive(true); } } bool timeout_delay(Button currentButton){ ListG list = currentButton.getStyleContext().listClasses(); string CSSClassName = to!string(cast(char*)list.next().data); currentButton.getStyleContext().removeClass(CSSClassName ~ "-flash"); return false; } But i get the error: Error: none of the overloads of '__ctor' are callable using argument types (bool delegate(void* userData), int, bool), candidates are: glib.Timeout.Timeout.this(uint interval, bool delegate() dlg, bool fireNow = false) glib.Timeout.Timeout.this(uint interval, bool delegate() dlg, GPriority priority, bool fireNow = false) glib.Timeout.Timeout.this(bool delegate() dlg, uint seconds, bool fireNow = false) glib.Timeout.Timeout.this(bool delegate() dlg, uint seconds, GPriority priority, bool fireNow = false) If i take a look at GTK for C it looks like there is a function for that: http://www.gtk.org/tutorial1.2/gtk_tut-17.html Why is this so confusing?
Re: static switch/pattern matching
On Saturday, 25 June 2016 at 12:35:39 UTC, Lodovico Giaretta wrote: On Saturday, 25 June 2016 at 12:30:22 UTC, Lodovico Giaretta wrote: If you want this to work, you need your lambdas to take the casted value as a parameter: Thanks.
Re: Does D has any support for thunks?
On Saturday, 25 June 2016 at 14:06:51 UTC, John wrote: On Saturday, 25 June 2016 at 13:44:48 UTC, Andre Pany wrote: [...] This will only work on X86: version(X86) struct FunctionPtr(TDelegate) if (is(TDelegate == delegate)) { [...] Thanks a lot John, that's fantastic. Kind regards André
Re: Does D has any support for thunks?
On Saturday, 25 June 2016 at 13:44:48 UTC, Andre Pany wrote: Hi everyone, I have some issue with win32 function SetWindowsHookEx. For this specific funtion there is no possibility to pass extra data (pointer to a class instance to be called) to the callback function. The general solution seems to use thunks. I found s.th. for c++: http://www.codeproject.com/Articles/16785/Thunking-in-Win-Simplifying-Callbacks-to-Non-sta Does D/Phobos has any support for thunks? Kind regards André This will only work on X86: version(X86) struct FunctionPtr(TDelegate) if (is(TDelegate == delegate)) { import std.traits; alias TResult = ReturnType!TDelegate; alias TParameters = Parameters!TDelegate; private struct ThunkCode { align(1): ubyte mov_eax; void* this_ptr; ubyte mov_ecx; void* func_ptr; ubyte mov_edx; void* cb_ptr; ushort jmp_edx; } this(TDelegate method) { this = method; } auto ref opAssign(TDelegate method) { extern(Windows) TResult callback(TParameters parameters) { TDelegate dg = void; asm { mov [dg], EAX; mov [dg + 4], ECX; } return dg(parameters); } if (auto thunk = cast(ThunkCode*)VirtualAlloc(null, ThunkCode.sizeof, MEM_COMMIT, PAGE_EXECUTE_READWRITE)) { with (thunk) { mov_eax = 0xB8; this_ptr = method.ptr; mov_ecx = 0xB9; func_ptr = method.funcptr; mov_edx = 0xBA; cb_ptr = &callback; jmp_edx = 0xE2FF; } FlushInstructionCache(GetCurrentProcess(), thunk, ThunkCode.sizeof); ptr = cast(typeof(ptr))thunk; } else { assert(false); } return this; } ~this() { if (ptr) { VirtualFree(ptr, ThunkCode.sizeof, MEM_DECOMMIT); ptr = null; } } extern(Windows) TResult function(TParameters) nothrow ptr; alias ptr this; } alias HookProc = FunctionPtr!(LRESULT delegate(int, WPARAM, LPARAM)); LRESULT hookProc(int code, WPARAM wparam, LPARAM lparam) { return 0; } HookProc hook = &hookProc; SetWindowsHookEx(WH_KEYBOARD, hook, GetModuleHandle(null), 0);
Re: Does D has any support for thunks?
On Saturday, 25 June 2016 at 13:44:48 UTC, Andre Pany wrote: Does D/Phobos has any support for thunks? It isn't included in the stdlib, but you can use the same C++ they describe in the link in D.
Does D has any support for thunks?
Hi everyone, I have some issue with win32 function SetWindowsHookEx. For this specific funtion there is no possibility to pass extra data (pointer to a class instance to be called) to the callback function. The general solution seems to use thunks. I found s.th. for c++: http://www.codeproject.com/Articles/16785/Thunking-in-Win-Simplifying-Callbacks-to-Non-sta Does D/Phobos has any support for thunks? Kind regards André
Re: GTKD - CSS class color "flash" delay
On Saturday, 25 June 2016 at 11:45:40 UTC, Mike Wey wrote: You should change the css class in the timeout_delay function. It's called by the GTK main loop every time the amount of seconds passed to the constructor has passed. And return true if you want to continue to flash the button, and false to stop. Also don't sleep in the timeout function, the main loop should take care of that, currently you are blocking the main thread for 5 seconds. Thanks for your answer. I have to pass the Button object to my timeout function to change the CSS class. But how do i do that within the Timeout constructor?
Re: static switch/pattern matching
On Saturday, 25 June 2016 at 12:30:22 UTC, Lodovico Giaretta wrote: If you want this to work, you need your lambdas to take the casted value as a parameter: void test(T)(T value) { int i; string s; match!(value, int, (val) => i = val, string, (val) => s = val ); } And of course you need to modify match! for this to work. Something like this: void match(alias t, cases...)() { static if (cases.length == 1) cases[0](); else static if (cases.length > 2) { static if (is(typeof(cases[0]) == bool)) { static if (cases[0]) cases[1](t); else match!(t, cases[2 .. $]); } else static if (is(typeof(t) == cases[0])) cases[1](t); else match!(t, cases[2 .. $]); } } void test(T)(T value) { int i; string s; match!(value, int, (val) => i = val, string, (val) => s = val ); } void main() { test(1); test("A string"); }
Re: static switch/pattern matching
On Saturday, 25 June 2016 at 10:39:09 UTC, John wrote: Thanks for the help, both. This appeared to work, until I realised the lambda isn't static: void match(T, cases...)() { static if (cases.length == 1) cases[0](); else static if (cases.length > 2) { static if (is(typeof(cases[0]) == bool)) { static if (cases[0]) cases[1](); else match!(T, cases[2 .. $]); } else static if (is(T == cases[0])) cases[1](); else match!(T, cases[2 .. $]); } } void test(T)(T value) { int i; string s; match!(T, int, () => i = value, string, () => s = value ); } test(1); test("A string"); The compiler complains about not being able convert an int to a string and vice versa. If you want this to work, you need your lambdas to take the casted value as a parameter: void test(T)(T value) { int i; string s; match!(value, int, (val) => i = val, string, (val) => s = val ); } And of course you need to modify match! for this to work.
Re: GTKD - CSS class color "flash" delay
On 06/24/2016 10:03 PM, TheDGuy wrote: On Friday, 24 June 2016 at 16:44:59 UTC, Gerald wrote: Other then the obvious multi-threaded, using glib.Timeout to trigger the reversion of the color change could be an option. http://api.gtkd.org/src/glib/Timeout.html Thanks! I tried this so far: private void letButtonsFlash(){ foreach(Button btn;bArr){ btn.setSensitive(false); } for(int i = 0; i < level; i++){ Button currentButton = bArr[rndButtonBlink[i]]; ListG list = currentButton.getStyleContext().listClasses(); string CSSClassName = to!string(cast(char*)list.next().data); currentButton.getStyleContext().addClass(CSSClassName ~ "-flash"); writeln(CSSClassName); Timeout t = new Timeout(&timeout_delay,1,true); currentButton.getStyleContext().removeClass(CSSClassName ~ "-flash"); } foreach(Button btn;bArr){ btn.setSensitive(true); } } bool timeout_delay(){ Thread.sleep(dur!("seconds")(5)); return false; } and it is "working" to the extend that at least the CSSClassName gets written in the console but the UI again just pops up after 5 sec. Could you give me a tip? You should change the css class in the timeout_delay function. It's called by the GTK main loop every time the amount of seconds passed to the constructor has passed. And return true if you want to continue to flash the button, and false to stop. Also don't sleep in the timeout function, the main loop should take care of that, currently you are blocking the main thread for 5 seconds. -- Mike Wey
Re: Is there a dmd.exe x86_64 out there?
On 25/06/2016 10:25 PM, Dlangofile wrote: On Saturday, 25 June 2016 at 09:39:21 UTC, rikki cattermole wrote: On 25/06/2016 9:03 PM, Dlangofile wrote: On Saturday, 25 June 2016 at 03:29:02 UTC, rikki cattermole wrote: On 25/06/2016 5:57 AM, Dlangofile wrote: Hi all, I'm building a Docker Alpine linux image with wine, for being able to forge Windows executable from my laptop, without having to dual boot. With my disappointment, I'm not able to run 32bit executable from the container right now, so the easy way is running a win64 dmd.exe: someone can point me to a pre-build executable, based on the latest version? Thanks Umm, x86_64 is backwards compatible with x86. So if 32bit build of dmd doesn't work, you have bigger problems. Well, frankly speaking I don't know! PE32+ executable (console) x86-64, for MS Windows -> working well PE32 executable (console) Intel 80386, for MS Windows -> not working at all I tried also to use a WINEARCH=win32, without success: I'm attaching the Dockerfile at the end, if someone wants to help more on that. In the meantime, any x86-64 DMD executable? What's the problem in having it available by default in the Windows distribution? Thanks /D FROM alpine:3.4 RUN apk --no-cache add wine freetype ncurses file ENV WINEARCH=win64 RUN wineboot ADD dmd2 /dmd2 CMD ["sh"] We need to see any errors produced from Wine. It is known that dmd does run under it. Which means something is wrong with your setup. with WINEARCH=win64 /dmd2/windows/bin # wineconsole dmd.exe err:winediag:nulldrv_CreateWindow Application tried to create a window, but no driver could be loaded. err:winediag:nulldrv_CreateWindow Make sure that your X server is running and that $DISPLAY is set correctly. wineconsole: Starting program "dmd.exe" failed. The command is invalid. with WINEARCH=win32 /dmd2/windows/bin # wineconsole dmd.exe wine: '/root/.wine' is a 32-bit installation, it cannot support 64-bit applications. As I said about x86_64 being backwards compatible with x86 (you can even run old 386 programs on a modern day cpu, go figure) so that isn't the problem. Maybe the Alpine Linux package for Wine has only 64-bit support... Maybe, Linux is finicky here library wise. Usually both arch binaries are required library wise and since Alpine is minimal.. easy to assume. The reason why we do not provide a dmd compiled for 64bit is simply, 32bit works in pretty much all cases. The cases it doesn't involve very large code bases being compiled. I understand, but what's exactly the problem in providing a 64bit version of the executable? Not providing it has just complicated my experience with D... :-) You're the first in over six months to bring up this issue, so not a common requirement ;) I just had a look into Wine, I'm not sure if this helps[0]. Right now you're not creating a new Wine environment or configuring it. I think that the 'wineboot' command in the Dockerfile just do it: I can run Win64 console application... Based on what I read, wineboot handles an instance lifetime e.g. restart. So killing of processes and getting mounts in for example. The link I gave has an example of a program that configures a new instance of Wine that is 32bit (since you can't change a 64bit one to 32bit) which is not the same thing. Otherwise, can you change over to a 32bit image instead of 64bit alpine? That probably will also fix it. Probably yes, maybe with an Ubuntu image as a base. The point is that everyone in docker is switching to Alpine distributions, as an alpine based image is far smaller that the other options, and the official Docker image of Alpine is 64bit only Given this information, yeah it might be worthwhile to distribute a build of dmd that is 64bit for Windows. But this won't allow you to execute the produced programs under Wine. Since you can't execute 32bit programs and since you can't really install MSVC or the required programs/libraries from Microsoft your stuck there. So really you want to get this sorted out.
Re: static switch/pattern matching
On Saturday, 25 June 2016 at 09:12:12 UTC, Lodovico Giaretta wrote: On Saturday, 25 June 2016 at 09:07:19 UTC, Lodovico Giaretta wrote: Instead of passing functions to match!, pass pairs of arguments, like this: match!(T, int, writeln("Matched int"), is(T : SomeObject), writeln("Derives from SomeObject"); ); Now, in the implementation, foreach pair of arguments, if the first member is a type that matches your target, perform that branch; otherwise, if the first member is a boolean value, and it is true, perform the branch. Of course I meant: match!(T, int, () {writeln("Matched int");}, is(T : SomeObject), () {writeln("Derives from SomeObject");} ); Thanks for the help, both. This appeared to work, until I realised the lambda isn't static: void match(T, cases...)() { static if (cases.length == 1) cases[0](); else static if (cases.length > 2) { static if (is(typeof(cases[0]) == bool)) { static if (cases[0]) cases[1](); else match!(T, cases[2 .. $]); } else static if (is(T == cases[0])) cases[1](); else match!(T, cases[2 .. $]); } } void test(T)(T value) { int i; string s; match!(T, int, () => i = value, string, () => s = value ); } test(1); test("A string"); The compiler complains about not being able convert an int to a string and vice versa.
Re: Is there a dmd.exe x86_64 out there?
On Saturday, 25 June 2016 at 09:39:21 UTC, rikki cattermole wrote: On 25/06/2016 9:03 PM, Dlangofile wrote: On Saturday, 25 June 2016 at 03:29:02 UTC, rikki cattermole wrote: On 25/06/2016 5:57 AM, Dlangofile wrote: Hi all, I'm building a Docker Alpine linux image with wine, for being able to forge Windows executable from my laptop, without having to dual boot. With my disappointment, I'm not able to run 32bit executable from the container right now, so the easy way is running a win64 dmd.exe: someone can point me to a pre-build executable, based on the latest version? Thanks Umm, x86_64 is backwards compatible with x86. So if 32bit build of dmd doesn't work, you have bigger problems. Well, frankly speaking I don't know! PE32+ executable (console) x86-64, for MS Windows -> working well PE32 executable (console) Intel 80386, for MS Windows -> not working at all I tried also to use a WINEARCH=win32, without success: I'm attaching the Dockerfile at the end, if someone wants to help more on that. In the meantime, any x86-64 DMD executable? What's the problem in having it available by default in the Windows distribution? Thanks /D FROM alpine:3.4 RUN apk --no-cache add wine freetype ncurses file ENV WINEARCH=win64 RUN wineboot ADD dmd2 /dmd2 CMD ["sh"] We need to see any errors produced from Wine. It is known that dmd does run under it. Which means something is wrong with your setup. with WINEARCH=win64 /dmd2/windows/bin # wineconsole dmd.exe err:winediag:nulldrv_CreateWindow Application tried to create a window, but no driver could be loaded. err:winediag:nulldrv_CreateWindow Make sure that your X server is running and that $DISPLAY is set correctly. wineconsole: Starting program "dmd.exe" failed. The command is invalid. with WINEARCH=win32 /dmd2/windows/bin # wineconsole dmd.exe wine: '/root/.wine' is a 32-bit installation, it cannot support 64-bit applications. As I said about x86_64 being backwards compatible with x86 (you can even run old 386 programs on a modern day cpu, go figure) so that isn't the problem. Maybe the Alpine Linux package for Wine has only 64-bit support... The reason why we do not provide a dmd compiled for 64bit is simply, 32bit works in pretty much all cases. The cases it doesn't involve very large code bases being compiled. I understand, but what's exactly the problem in providing a 64bit version of the executable? Not providing it has just complicated my experience with D... :-) I just had a look into Wine, I'm not sure if this helps[0]. Right now you're not creating a new Wine environment or configuring it. I think that the 'wineboot' command in the Dockerfile just do it: I can run Win64 console application... Otherwise, can you change over to a 32bit image instead of 64bit alpine? That probably will also fix it. Probably yes, maybe with an Ubuntu image as a base. The point is that everyone in docker is switching to Alpine distributions, as an alpine based image is far smaller that the other options, and the official Docker image of Alpine is 64bit only
Re: Is there a dmd.exe x86_64 out there?
On 25/06/2016 9:03 PM, Dlangofile wrote: On Saturday, 25 June 2016 at 03:29:02 UTC, rikki cattermole wrote: On 25/06/2016 5:57 AM, Dlangofile wrote: Hi all, I'm building a Docker Alpine linux image with wine, for being able to forge Windows executable from my laptop, without having to dual boot. With my disappointment, I'm not able to run 32bit executable from the container right now, so the easy way is running a win64 dmd.exe: someone can point me to a pre-build executable, based on the latest version? Thanks Umm, x86_64 is backwards compatible with x86. So if 32bit build of dmd doesn't work, you have bigger problems. Well, frankly speaking I don't know! PE32+ executable (console) x86-64, for MS Windows -> working well PE32 executable (console) Intel 80386, for MS Windows -> not working at all I tried also to use a WINEARCH=win32, without success: I'm attaching the Dockerfile at the end, if someone wants to help more on that. In the meantime, any x86-64 DMD executable? What's the problem in having it available by default in the Windows distribution? Thanks /D FROM alpine:3.4 RUN apk --no-cache add wine freetype ncurses file ENV WINEARCH=win64 RUN wineboot ADD dmd2 /dmd2 CMD ["sh"] We need to see any errors produced from Wine. It is known that dmd does run under it. Which means something is wrong with your setup. As I said about x86_64 being backwards compatible with x86 (you can even run old 386 programs on a modern day cpu, go figure) so that isn't the problem. The reason why we do not provide a dmd compiled for 64bit is simply, 32bit works in pretty much all cases. The cases it doesn't involve very large code bases being compiled. The only platform this may not be true for is OSX where 32bit is long dead globally and 64bit is the only option. Sadly Windows and Linux still have 32bit cpus common in the last 10 years. I just had a look into Wine, I'm not sure if this helps[0]. Right now you're not creating a new Wine environment or configuring it. Otherwise, can you change over to a 32bit image instead of 64bit alpine? That probably will also fix it. [0] https://wiki.winehq.org/FAQ#How_do_I_create_a_32_bit_wineprefix_on_a_64_bit_system.3F
Re: static switch/pattern matching
On Saturday, 25 June 2016 at 09:07:19 UTC, Lodovico Giaretta wrote: Instead of passing functions to match!, pass pairs of arguments, like this: match!(T, int, writeln("Matched int"), is(T : SomeObject), writeln("Derives from SomeObject"); ); Now, in the implementation, foreach pair of arguments, if the first member is a type that matches your target, perform that branch; otherwise, if the first member is a boolean value, and it is true, perform the branch. Of course I meant: match!(T, int, () {writeln("Matched int");}, is(T : SomeObject), () {writeln("Derives from SomeObject");} ); You could probably even match on the actual value (instead of its type) and pass it (correctly casted) to the functions: match!(t, int, (int t) {writeln("Matched int ", t);}, is(T : SomeObject), (SomeObject t) {writeln(t, " derives from SomeObject");} ); I don't have time to implement it now, but I think it's not too difficult.
Re: static switch/pattern matching
also, there is a subtle bug in matcher. sorry. ;-)
Re: static switch/pattern matching
On Saturday, 25 June 2016 at 08:46:05 UTC, John wrote: Anyone able to improve on it? q&d hack: template tyma(T, Cases...) { import std.traits; template GetFunc(size_t idx) { static if (idx >= Cases.length) { static assert(0, "no delegate for match"); } else static if (isCallable!(Cases[idx])) { enum GetFunc = Cases[idx]; } else { enum GetFunc = GetFunc!(idx+1); } } template Matcher(size_t idx) { //pragma(msg, "T=", T, "; idx=", idx, "; Cases[idx]=", Cases[idx], "; is=", is(typeof(T) == Cases[idx])); static if (idx >= Cases.length) { static assert(0, "no match, consider adding `void` branch"); } else static if (isCallable!(Cases[idx])) { enum Matcher = Matcher!(idx+1); } else static if (is(Cases[idx] == void)) { enum Matcher = GetFunc!(idx+1); } else static if (is(typeof(Cases[idx]) == string)) { mixin("static if (is(T:"~Cases[idx]~")) enum Matcher = GetFunc!(idx+1); else enum Matcher = Matcher!(idx+1);"); } else static if (is(typeof(Cases[idx]))) { static assert(0, "unexpected something in cases: "~Cases[idx].stringof); } else static if (is(T == Cases[idx])) { enum Matcher = GetFunc!(idx+1); } else { enum Matcher = Matcher!(idx+1); } } enum tyma = Matcher!0; } void main () { import std.stdio; auto res = tyma!(int, string, () => "string", "long", () => "integral", void, () => "anything", )(); writeln(res); } note that you should separate type names from labdas with "," instead of doing `int => "integral`, and have to add `()` at the end to actually call the delegate.
Re: static switch/pattern matching
On Saturday, 25 June 2016 at 08:46:05 UTC, John wrote: Writing a long series of "static if ... else" statements can be tedious and I'm prone to leaving out the crucial "static" after "else", so I was wondered if it was possible to write a template that would resemble the switch statement, but for types. Closest I came up to was this: void match(T, Fs...)() { foreach (F; Fs) { static if (isFunctionPointer!F) { alias Ps = Parameters!F; static if (Ps.length == 1) { static if (is(Ps[0] == T)) F(Ps[0].init); } } } } void test(T)(T t) { match!(T, (int _) => writeln("Matched int"), (string _) => writeln("Matched string") ); } But that's pretty limited and I'd like to be able to match on whether a type derives from T as well. I just can't figure it out. Something like this would be ideal... match!(T, int => writeln("Matched int"), is(T : SomeObject) => writeln("Derives from SomeObject") ); Anyone able to improve on it? Instead of passing functions to match!, pass pairs of arguments, like this: match!(T, int, writeln("Matched int"), is(T : SomeObject), writeln("Derives from SomeObject"); ); Now, in the implementation, foreach pair of arguments, if the first member is a type that matches your target, perform that branch; otherwise, if the first member is a boolean value, and it is true, perform the branch.
Re: Is there a dmd.exe x86_64 out there?
On Saturday, 25 June 2016 at 03:29:02 UTC, rikki cattermole wrote: On 25/06/2016 5:57 AM, Dlangofile wrote: Hi all, I'm building a Docker Alpine linux image with wine, for being able to forge Windows executable from my laptop, without having to dual boot. With my disappointment, I'm not able to run 32bit executable from the container right now, so the easy way is running a win64 dmd.exe: someone can point me to a pre-build executable, based on the latest version? Thanks Umm, x86_64 is backwards compatible with x86. So if 32bit build of dmd doesn't work, you have bigger problems. Well, frankly speaking I don't know! PE32+ executable (console) x86-64, for MS Windows -> working well PE32 executable (console) Intel 80386, for MS Windows -> not working at all I tried also to use a WINEARCH=win32, without success: I'm attaching the Dockerfile at the end, if someone wants to help more on that. In the meantime, any x86-64 DMD executable? What's the problem in having it available by default in the Windows distribution? Thanks /D FROM alpine:3.4 RUN apk --no-cache add wine freetype ncurses file ENV WINEARCH=win64 RUN wineboot ADD dmd2 /dmd2 CMD ["sh"]
static switch/pattern matching
Writing a long series of "static if ... else" statements can be tedious and I'm prone to leaving out the crucial "static" after "else", so I was wondered if it was possible to write a template that would resemble the switch statement, but for types. Closest I came up to was this: void match(T, Fs...)() { foreach (F; Fs) { static if (isFunctionPointer!F) { alias Ps = Parameters!F; static if (Ps.length == 1) { static if (is(Ps[0] == T)) F(Ps[0].init); } } } } void test(T)(T t) { match!(T, (int _) => writeln("Matched int"), (string _) => writeln("Matched string") ); } But that's pretty limited and I'd like to be able to match on whether a type derives from T as well. I just can't figure it out. Something like this would be ideal... match!(T, int => writeln("Matched int"), is(T : SomeObject) => writeln("Derives from SomeObject") ); Anyone able to improve on it?