Re: Accessing COM Objects
On Monday, 13 June 2016 at 01:22:33 UTC, Incognito wrote: I've been reading over D's com and can't find anything useful. It seems there are different ways: http://www.lunesu.com/uploads/ModernCOMProgramminginD.pdf which is of no help and requires an idl file, which I don't have. Then theres this http://wiki.dlang.org/COM_Programming There is also: https://github.com/JesseKPhillips/Juno-Windows-Class-Library It kind of provides similar highlevel options as the "Modern COM Programming in D." But I don't use it and have only be somewhat keeping it alive (I had some hiccups in supporting 64bit), so I haven't been working to improve the simplicity of interfacing to COM objects. It also includes definitions for accessing Windows COM objects which aren't needed when interfacing with your own or other COM objects. I'd like to have two libraries, Juno Library and Juno Windows Class Library.
Re: ndslice: convert a sliced object to T[]
On Wednesday, 15 June 2016 at 14:14:23 UTC, Seb wrote: On Wednesday, 15 June 2016 at 13:13:05 UTC, data pulverizer And where can I find more cool tricks like that? Browse the source code and the unittests. Phobos is an amazing resource :) Very true! That's great many thanks!
Re: ndslice: convert a sliced object to T[]
On Wednesday, 15 June 2016 at 08:25:35 UTC, data pulverizer wrote: I guess foreach would not copy the elements? for example: foreach(el; slice.byElement) x ~= el; But it feels wrong to be doing work pulling elements that already exists by using foreach. I feel as if I am missing something obvious but can't get it. The question is: why you need to put them inside an array? If you can, leave them in the lazy range and work on it.
Re: ndslice: convert a sliced object to T[]
On Wednesday, 15 June 2016 at 08:53:22 UTC, Andrea Fontana wrote: On Wednesday, 15 June 2016 at 08:25:35 UTC, data pulverizer wrote: I guess foreach would not copy the elements? for example: foreach(el; slice.byElement) x ~= el; But it feels wrong to be doing work pulling elements that already exists by using foreach. I feel as if I am missing something obvious but can't get it. The question is: why you need to put them inside an array? If you can, leave them in the lazy range and work on it. I need this to work with external libraries that only deal with one dimensional arrays.
Re: ndslice: convert a sliced object to T[]
On Wednesday, 15 June 2016 at 08:56:15 UTC, data pulverizer wrote: On Wednesday, 15 June 2016 at 08:53:22 UTC, Andrea Fontana wrote: On Wednesday, 15 June 2016 at 08:25:35 UTC, data pulverizer wrote: I guess foreach would not copy the elements? for example: foreach(el; slice.byElement) x ~= el; But it feels wrong to be doing work pulling elements that already exists by using foreach. I feel as if I am missing something obvious but can't get it. The question is: why you need to put them inside an array? If you can, leave them in the lazy range and work on it. I need this to work with external libraries that only deal with one dimensional arrays. Then I think the slice.byElement.array is the right solution.
GTKD - Application crashes - or not? [Coedit]
Hi, this is my app: import gtk.Main; import gtk.MainWindow; import gtk.CssProvider; import gdk.Display; import gdk.Screen; import gtk.StyleContext; import glib.GException; class Window : MainWindow{ this(int width, int height, string title){ super(title); setDefaultSize(width, height); string cssPath = "test.css"; CssProvider provider = new CssProvider(); provider.loadFromPath(cssPath); Display display = Display.getDefault(); Screen screen = display.getDefaultScreen(); StyleContext.addProviderForScreen(screen, provider, GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); showAll(); } } void main(string[] args){ Main.init(args); auto win = new Window(250,250,"Tutorial"); Main.run(); } I use Coedit to write and execute D apps. If i execute this app i get the error message (it compiles fine): glib.GException.GException@..\..\..\AppData\Roaming\dub\packages\gtk-d-3.3.1\gtk-d\src\glib\GException.d(40): Failed to import: No such file or directory 0x00430569 0x00402065 0x004020D8 0x0040275F 0x00402660 0x004020F7 0x740F38F4 in BaseThreadInitThunk 0x76F85DE3 in RtlUnicodeStringToInteger 0x76F85DAE in RtlUnicodeStringToInteger error: the process (C:\Users\Standardbenutzer\Documents\Dlang_Projects\GTKD_Test.exe) has returned the signal 1 But if i execute the app my hand (in the windows command window or my double click) it works as expected (so no error)? Why is that?
GTKD - overrideBackgroundColor of Button doesn't work
Hello, why does this code not work? RGBA rgb = new RGBA(1,0.5,0.5,1.0); Button btn_1 = new Button("Start"); btn_1.overrideBackgroundColor(StateFlags.NORMAL, rgb); The color of btn_1 just doesn't change.
Re: GTKD - Application crashes - or not? [Coedit]
On Wednesday, 15 June 2016 at 10:21:20 UTC, Rene Zwanenburg wrote: On Wednesday, 15 June 2016 at 09:48:19 UTC, TheDGuy wrote: But if i execute the app my hand (in the windows command window or my double click) it works as expected (so no error)? Why is that? My first guess would be that Coedit does not use the directory where the executable is located as working directory. You can check what getcwd returns: https://dlang.org/phobos/std_file.html#.getcwd Thanks a lot for your answer, getcwd() returns the path where coedit is located on my harddrive: C:\Program Files (x86)\Coedit_32\coedit.2update6.win32 How can i change that?
Re: short programme from "Programming in D" by Ali Cehreli.
On Tuesday, 14 June 2016 at 16:09:00 UTC, Steven Schveighoffer wrote: On 6/14/16 11:44 AM, Ali Çehreli wrote: On 06/14/2016 04:52 AM, Nick B wrote: Further, when the format string is a literal like the one used in the program, the compiler can in theory determine at compile time that the format string does not match the rest of the arguments: readf (" %s, "); // "No argument for %s" This is a desired feature but dmd does not have this yet. Since dmd provides the front end to gdc and ldc, they don't have this feature either. I will log a feature request with Walter. Nick
Re: GTKD - Application crashes - or not? [Coedit]
On Wednesday, 15 June 2016 at 09:48:19 UTC, TheDGuy wrote: But if i execute the app my hand (in the windows command window or my double click) it works as expected (so no error)? Why is that? My first guess would be that Coedit does not use the directory where the executable is located as working directory. You can check what getcwd returns: https://dlang.org/phobos/std_file.html#.getcwd
arr.ptr, @safe and void*
Hi, Walter's made a fix for arr[$..$].ptr being unsafe to dereference - .ptr will be @system: https://github.com/dlang/dmd/pull/5860 A referenced druntime pull mentioned having a safe wrapper for .ptr that allows comparison of the pointer value, but does not allow dereference. The wrapper would return uintptr_t (an integer guaranteed to be big enough to hold a pointer value). My question is: would returning void* instead really be unsafe, i.e. is there a way of dereferencing it in safe code? (I'm not thinking about holes in @safe, but ways by design).
Re: Accessing COM Objects P3
[in] long index, [out] long* value); [id(0x60020017)] HRESULT PutClass([in] long value); [id(0x60020018)] HRESULT GetGlobalClass( [in] long index, [out] long* value); [id(0x60020019)] HRESULT PutGlobalClass([in] long value); [id(0x6002001a)] HRESULT GetPath( [in] long index, [out] BSTR* pathString); [id(0x6002001b)] HRESULT PutPath([in] BSTR pathString); [id(0x6002001c)] HRESULT GetDataLength( [in] long index, [out] long* value); [id(0x6002001d)] HRESULT GetData( [in] long index, [out] BSTR* value); [id(0x6002001e)] HRESULT PutData( [in] long length, [in] BSTR value); }; [ odl, uuid(7CA9DE40-9EB3-11D1-B033-00C04FD7EC47), helpstring("Container class for actions system parameters."), dual, oleautomation ] interface IActionDescriptor : IDispatch { [id(0x6002)] HRESULT GetType( [in] long key, [out] long* type); [id(0x60020001)] HRESULT GetKey( [in] long index, [out] long* key); [id(0x60020002)] HRESULT HasKey( [in] long key, [out] long* HasKey); [id(0x60020003)] HRESULT GetCount([out] long* count); [id(0x60020004)] HRESULT IsEqual( [in] IActionDescriptor* otherDesc, [out] long* IsEqual); [id(0x60020005)] HRESULT Erase([in] long key); [id(0x60020006)] HRESULT Clear(); [id(0x60020007)] HRESULT GetInteger( [in] long key, [out] long* retval); [id(0x60020008)] HRESULT PutInteger( [in] long key, [in] long value); [id(0x60020009)] HRESULT GetDouble( [in] long key, [out] double* retval); [id(0x6002000a)] HRESULT PutDouble( [in] long key, [in] double value); [id(0x6002000b)] HRESULT GetUnitDouble( [in] long key, [out] long* unitID, [out] double* retval); [id(0x6002000c)] HRESULT PutUnitDouble( [in] long key, [in] long unitID, [in] double value); [id(0x6002000d)] HRESULT GetString( [in] long key, [out] BSTR* retval); [id(0x6002000e)] HRESULT PutString( [in] long key, [in] BSTR value); [id(0x6002000f)] HRESULT GetBoolean( [in] long key, [out] long* retval); [id(0x60020010)] HRESULT PutBoolean( [in] long key, [in] long value); [id(0x60020011)] HRESULT GetList( [in] long key, [out] IActionList** list); [id(0x60020012)] HRESULT PutList( [in] long key, [in] IActionList* list); [id(0x60020013)] HRESULT GetObject( [in] long key, [out] long* classID, [out] IActionDescriptor** retval); [id(0x60020014)] HRESULT PutObject( [in] long key, [in] long classID, [in] IActionDescriptor* value); [id(0x60020015)] HRESULT GetGlobalObject( [in] long key, [out] long* classID, [out] IActionDescriptor** retval); [id(0x60020016)] HRESULT PutGlobalObject( [in] long key, [in] long classID, [in] IActionDescriptor* value); [id(0x60020017)] HRESULT GetEnumerated( [in] long key, [out] long* enumType, [out] long* value); [id(0x60020018)] HRESULT PutEnumerated( [in] long key, [in] long enumType, [in] long value); [id(0x60020019)] HRESULT GetReference( [in] long key, [out] IActionReference** reference);
Re: Accessing COM Objects
On Wednesday, 15 June 2016 at 06:09:33 UTC, thedeemon wrote: On Monday, 13 June 2016 at 17:38:41 UTC, Incognito wrote: Cool. Oleview gives me the idl files. How to convert the idl files to d or possibly c? There are ready tools idl2d: https://github.com/dlang/visuald/tree/master/c2d and tlb2idl: https://github.com/dlang/visuald/tree/master/tools I've used this idl2d and it works pretty well (although not perfect, sometimes manual editing still required). Example of real-world DirectShow interfaces translated: https://gist.github.com/thedeemon/46748f91afdbcf339f55da9b355a6b56 Would I just use them in place of IUnknown once I have the interface? If you have the interface defined AND you know its IID, you can request it from CoCreateInstance and then use as ordinary D object. You might want to look at this wrapper that takes most of COM machinery: https://gist.github.com/thedeemon/3c2989b76004fafe9aa0 Then you just write almost as in C#, something like auto pGraph = ComPtr!IGraphBuilder(CLSID_FilterGraph, "pGraph").require; ComPtr!ICaptureGraphBuilder2 pBuilder = ComPtr!ICaptureGraphBuilder2(CLSID_CaptureGraphBuilder2).require; pBuilder.SetFiltergraph(pGraph); ... auto CLSID_NullRenderer = Guid!("C1F400A4-3F08-11D3-9F0B-006008039E37"); //qedit.dll auto pNullRendr = ComPtr!IBaseFilter(CLSID_NullRenderer, "nulrend"); pGraph.AddFilter(pNullRendr, "Null Renderer"w.ptr); ... auto imf = ComPtr!IMediaFilter(pGraph); imf.SetSyncSource(null); All the CreateInstance, QueryInterface, AddRef/Release etc. is taken care of. And even HRESULT return codes are automatically checked. Thanks, if I can get the idl converted I'll test it out. It seems idl2d from VD is not easily compilable?
Re: Accessing COM Objects
On Wednesday, 15 June 2016 at 08:21:06 UTC, John wrote: OK, adding the return type to the signature should fix that. So: private static Parameter getParameters(MethodImpl method) Sorry, I meant the getParameter methods should return be: private static Parameter[] getParameters(MethodImpl method) and private static Parameter[] getParameters(MethodImpl method, out Parameter returnParameter, bool getReturnParameter)
Re: Strange Issues regarding aliases
On Tuesday, 14 June 2016 at 17:37:40 UTC, Joerg Joergonson wrote: On Tuesday, 14 June 2016 at 17:34:42 UTC, Joerg Joergonson wrote: This is how derelict does it, I simply moved them in to the class for simplicity. I mean glad: http://glad.dav1d.de/ It seems that a loader is required for some reason and that possibly could be one or both of the problems. Yes, Derelict and glad both work this way. A loader is required because you are using function pointers, which means you need the memory addresses of the functions in the library, which are only known at runtime when the library is loaded into memory. There's no way around it. You are doing manually what the system loader does when you declare a normal function and link with an import library (on Windows) or directly with a dynamic library (on Posix systems). You should be declaring your functions something like this: // Most functions in C libraries should be extern(C), but OpenGL needs to // be extern(Windows) on Windows and extern(C) everywhere else. extern(System) // handles that for you. Making them nothrow and @nogc is very handy for D // code that needs those attributes. extern(System) @nogc nothrow { alias aClear = void function(int); } struct GL { aClear clear; } void loadFuncs(ref GL gl) { // This is system specific. You can see the possibilities in // the module derelict.opengl3.gl3 version(Windows) ennum libName = "OpenGL32.dll" // loadSharedLibrary should wrap OS-specific LoadLibrary/dlopen auto lib = loadSharedLibrary(libName); // loadFunc should wrap OS-specific GetProcAdress/dlsysm gl.clear = cast(aClear)lib.loadFunc("glClear"); }
Re: ndslice: convert a sliced object to T[]
On Wednesday, 15 June 2016 at 07:45:12 UTC, Andrea Fontana wrote: On Wednesday, 15 June 2016 at 07:24:23 UTC, data pulverizer wrote: On Wednesday, 15 June 2016 at 03:17:39 UTC, Seb wrote: On Wednesday, 15 June 2016 at 03:11:23 UTC, data pulverizer wrote: in that case: import std.array : array; int[] x = slice.byElement.array; Are you sure you want to create a _copy_ of your data? In most cases you don't need that ;-) thanks, now I can go to bed! You are welcome. Sleep tight! Thanks, I did. I definitely don't want to create a copy! I thought .byElement would provide a range which I assume is a reference am I forcing it to copy by using .array? Yes. You're forcing it to read all elements and copy them in a new array. I guess foreach would not copy the elements? for example: foreach(el; slice.byElement) x ~= el; But it feels wrong to be doing work pulling elements that already exists by using foreach. I feel as if I am missing something obvious but can't get it.
Re: ndslice: convert a sliced object to T[]
On Wednesday, 15 June 2016 at 03:17:39 UTC, Seb wrote: On Wednesday, 15 June 2016 at 03:11:23 UTC, data pulverizer wrote: in that case: import std.array : array; int[] x = slice.byElement.array; Are you sure you want to create a _copy_ of your data? In most cases you don't need that ;-) thanks, now I can go to bed! You are welcome. Sleep tight! Thanks, I did. I definitely don't want to create a copy! I thought .byElement would provide a range which I assume is a reference am I forcing it to copy by using .array?
Re: Accessing COM Objects
On Monday, 13 June 2016 at 17:38:41 UTC, Incognito wrote: Cool. Oleview gives me the idl files. How to convert the idl files to d or possibly c? There are ready tools idl2d: https://github.com/dlang/visuald/tree/master/c2d and tlb2idl: https://github.com/dlang/visuald/tree/master/tools I've used this idl2d and it works pretty well (although not perfect, sometimes manual editing still required). Example of real-world DirectShow interfaces translated: https://gist.github.com/thedeemon/46748f91afdbcf339f55da9b355a6b56 Would I just use them in place of IUnknown once I have the interface? If you have the interface defined AND you know its IID, you can request it from CoCreateInstance and then use as ordinary D object. You might want to look at this wrapper that takes most of COM machinery: https://gist.github.com/thedeemon/3c2989b76004fafe9aa0 Then you just write almost as in C#, something like auto pGraph = ComPtr!IGraphBuilder(CLSID_FilterGraph, "pGraph").require; ComPtr!ICaptureGraphBuilder2 pBuilder = ComPtr!ICaptureGraphBuilder2(CLSID_CaptureGraphBuilder2).require; pBuilder.SetFiltergraph(pGraph); ... auto CLSID_NullRenderer = Guid!("C1F400A4-3F08-11D3-9F0B-006008039E37"); //qedit.dll auto pNullRendr = ComPtr!IBaseFilter(CLSID_NullRenderer, "nulrend"); pGraph.AddFilter(pNullRendr, "Null Renderer"w.ptr); ... auto imf = ComPtr!IMediaFilter(pGraph); imf.SetSyncSource(null); All the CreateInstance, QueryInterface, AddRef/Release etc. is taken care of. And even HRESULT return codes are automatically checked.
Re: ndslice: convert a sliced object to T[]
On Wednesday, 15 June 2016 at 07:24:23 UTC, data pulverizer wrote: On Wednesday, 15 June 2016 at 03:17:39 UTC, Seb wrote: On Wednesday, 15 June 2016 at 03:11:23 UTC, data pulverizer wrote: in that case: import std.array : array; int[] x = slice.byElement.array; Are you sure you want to create a _copy_ of your data? In most cases you don't need that ;-) thanks, now I can go to bed! You are welcome. Sleep tight! Thanks, I did. I definitely don't want to create a copy! I thought .byElement would provide a range which I assume is a reference am I forcing it to copy by using .array? Yes. You're forcing it to read all elements and copy them in a new array.
Re: Accessing COM Objects
On Wednesday, 15 June 2016 at 06:56:59 UTC, Joerg Joergonson wrote: When I try to compile your code I get the following errors: main.d(953): Error: function core.sys.windows.objbase.CoTaskMemAlloc (uint) is not callable using argument types (immutable(ulong)) main.d(970): Error: can only slice tuple types, not _error_ main.d(974): Error: can only slice tuple types, not _error_ coTaskMemAlloc is defined with ULONG in the objbase.d file... so I have no idea what's going on there. immutable bufferSize = (funcDesc.cParams + 1) * (wchar*).sizeof; auto names = cast(wchar**)CoTaskMemAlloc(bufferSize); Looks like bufferSize just needs to be cast to uint. Didn't get that error in DMD. The other two I also don't know: params ~= new Parameter(method, (name[0 .. SysStringLen(name)]).toUTF8(), If I run it in ldc I get the error Error: forward reference to inferred return type of function call 'getParameters' private static getParameters(MethodImpl method) { Parameter dummy; return getParameters(method, dummy, false); } It does compile in DMD though. OK, adding the return type to the signature should fix that. So: private static Parameter getParameters(MethodImpl method) When running I get the error Error loading type library/DLL. The IDL file is in the same directory Did you try to pass it an IDL file? No wonder it didn't work - you pass in the type library instead, which is a binary file such as a DLL, EXE or TLB file. You can get the file's path from OleView by highlighting the library on the left (eg Photoshop) and on the right it will show a tree with the path beside "win32".
Re: ndslice: convert a sliced object to T[]
On Wednesday, 15 June 2016 at 11:19:20 UTC, data pulverizer wrote: On Wednesday, 15 June 2016 at 09:32:21 UTC, Andrea Fontana wrote: Then I think the slice.byElement.array is the right solution. The problem with that is that it slows down the code. I compared matrix multiplication between R and D's cblas adaptor and ndslice. n = 4000 Matrices: A, B Sizes: both n by n Engine: both call openblas R Elapsed Time: 2.709 s D's cblas and ndslice: 3.593 s The R code: n = 4000; A = matrix(runif(n*n), nr = n); B = matrix(runif(n*n), nr = n) system.time(C <- A%*%B) The D code: import std.stdio : writeln; import std.experimental.ndslice; import std.random : Random, uniform; import std.conv : to; import std.array : array; import cblas; import std.datetime : StopWatch; T[] runif(T)(ulong len, T min, T max){ T[] arr = new T[len]; Random gen; for(ulong i = 0; i < len; ++i) arr[i] = uniform(min, max, gen); return arr; } // Random matrix auto rmat(T)(ulong nrow, ulong ncol, T min, T max){ return runif(nrow*ncol, min, max).sliced(nrow, ncol); } auto matrix_mult(T)(Slice!(2, T*) a, Slice!(2, T*) b){ int M = to!int(a.shape[0]); int K = to!int(a.shape[1]); int N = to!int(b.shape[1]); int n_el = to!int(a.elementsCount); T[] A = a.byElement.array; T[] B = b.byElement.array; T[] C = new T[M*N]; gemm(Order.ColMajor, Transpose.NoTrans, Transpose.NoTrans, M, N, K, 1., A.ptr, K, B.ptr, N, 0, C.ptr, N); return C.sliced(M, N); } void main() { int n = 4000; auto A = rmat(n, n, 0., 1.); auto B = rmat(n, n, 0., 1. ); StopWatch sw; sw.start(); auto C = matrix_mult(A, B); sw.stop(); writeln("Time taken: \n\t", sw.peek().msecs, " [ms]"); } In my system monitor I can see the copy phase in the D process as as single core process. There should be a way to do go from ndslice to T[] without copying. Using a foreach loop is even slower As said you can avoid the copy (see below). I also profiled it a bit and it was interesting to see that 50% of the runtime are spent on generating the random matrix. On my machine now both scripts take 1.5s when compiled with DFLAGS="-release -O3 -boundscheck=off" dub foo2.d --compiler=ldc (`-b release` would also work) #!/usr/bin/env dub /+ dub.sdl: name "matrix_mult" dependency "cblas" version="~master" dependency "mir" version="~>0.15" +/ import std.stdio : writeln; import mir.ndslice; import std.random : Random, uniform; import std.conv : to; import std.array : array; import cblas; import std.datetime : StopWatch; T[] runif(T)(ulong len, T min, T max){ T[] arr = new T[len]; Random gen; for(ulong i = 0; i < len; ++i) arr[i] = uniform(min, max, gen); return arr; } // Random matrix auto rmat(T)(ulong nrow, ulong ncol, T min, T max){ import std.typecons : tuple; auto arr = runif(nrow*ncol, min, max); return tuple(arr, arr.sliced(nrow, ncol)); } auto matrix_mult(T)(T[] A, T[] B, Slice!(2, T*) a, Slice!(2, T*) b){ int M = to!int(a.shape[0]); int K = to!int(a.shape[1]); int N = to!int(b.shape[1]); int n_el = to!int(a.elementsCount); T[] C = new T[M*N]; gemm(Order.ColMajor, Transpose.NoTrans, Transpose.NoTrans, M, N, K, 1., A.ptr, K, B.ptr, N, 0, C.ptr, N); return C.sliced(M, N); } void main() { int n = 4000; auto ta = rmat(n, n, 0., 1.); auto tb = rmat(n, n, 0., 1. ); StopWatch sw; sw.start(); auto C = matrix_mult(ta[0], tb[0], ta[1], tb[1]); sw.stop(); writeln("Time taken: \n\t", sw.peek().msecs, " [ms]"); } For performance issues, you should definitely open an issue at mir (the development library of ndslice): https://github.com/libmir/mir
Re: ndslice: convert a sliced object to T[]
On Wednesday, 15 June 2016 at 09:32:21 UTC, Andrea Fontana wrote: Then I think the slice.byElement.array is the right solution. The problem with that is that it slows down the code. I compared matrix multiplication between R and D's cblas adaptor and ndslice. n = 4000 Matrices: A, B Sizes: both n by n Engine: both call openblas R Elapsed Time: 2.709 s D's cblas and ndslice: 3.593 s The R code: n = 4000; A = matrix(runif(n*n), nr = n); B = matrix(runif(n*n), nr = n) system.time(C <- A%*%B) The D code: import std.stdio : writeln; import std.experimental.ndslice; import std.random : Random, uniform; import std.conv : to; import std.array : array; import cblas; import std.datetime : StopWatch; T[] runif(T)(ulong len, T min, T max){ T[] arr = new T[len]; Random gen; for(ulong i = 0; i < len; ++i) arr[i] = uniform(min, max, gen); return arr; } // Random matrix auto rmat(T)(ulong nrow, ulong ncol, T min, T max){ return runif(nrow*ncol, min, max).sliced(nrow, ncol); } auto matrix_mult(T)(Slice!(2, T*) a, Slice!(2, T*) b){ int M = to!int(a.shape[0]); int K = to!int(a.shape[1]); int N = to!int(b.shape[1]); int n_el = to!int(a.elementsCount); T[] A = a.byElement.array; T[] B = b.byElement.array; T[] C = new T[M*N]; gemm(Order.ColMajor, Transpose.NoTrans, Transpose.NoTrans, M, N, K, 1., A.ptr, K, B.ptr, N, 0, C.ptr, N); return C.sliced(M, N); } void main() { int n = 4000; auto A = rmat(n, n, 0., 1.); auto B = rmat(n, n, 0., 1. ); StopWatch sw; sw.start(); auto C = matrix_mult(A, B); sw.stop(); writeln("Time taken: \n\t", sw.peek().msecs, " [ms]"); } In my system monitor I can see the copy phase in the D process as as single core process. There should be a way to do go from ndslice to T[] without copying. Using a foreach loop is even slower
Re: Accessing COM Objects
On Wednesday, 15 June 2016 at 07:01:30 UTC, Joerg Joergonson wrote: It seems idl2d from VD is not easily compilable? I don't remember problems with that, anyway here's the binary I used: http://stuff.thedeemon.com/idl2d.exe
Re: ndslice: convert a sliced object to T[]
Oh, I didn't see that runif now returns a tuple.
Re: ndslice: convert a sliced object to T[]
On Wednesday, 15 June 2016 at 13:13:05 UTC, data pulverizer wrote: On Wednesday, 15 June 2016 at 12:10:32 UTC, Seb wrote: As said you can avoid the copy (see below). I also profiled it a bit and it was interesting to see that 50% of the runtime are spent on generating the random matrix. On my machine now both scripts take 1.5s when compiled with I didn't benchmark the RNG but I did notice it took a lot of time to generate the matrix but for now I am focused on the BLAS side of things. I am puzzled about how your code works: Firstly: I didn't know that you could substitute an array for its first element in D though I am aware that a pointer to an array's first element is equivalent to passing the array in C. auto matrix_mult(T)(T[] A, T[] B, Slice!(2, T*) a, Slice!(2, T*) b){ ... gemm(Order.ColMajor, Transpose.NoTrans, Transpose.NoTrans, M, N, K, 1., A.ptr, K, B.ptr, N, 0, C.ptr, N); return C.sliced(M, N); } You wrote that too :-) For more infos see: https://dlang.org/spec/arrays.html However that's very dangerous, so use just slices wherever you can. Secondly: I am especially puzzled about using the second element to stand in for the slice itself. How does that work? And where can I find more cool tricks like that? void main() { ... auto C = matrix_mult(ta[0], tb[0], ta[1], tb[1]); sw.stop(); writeln("Time taken: \n\t", sw.peek().msecs, " [ms]"); } Many thanks! Btw you don't even need to save tuples, the pointer is already saved in the slice ;-) N.b: afaik you need the latest version of mir, because std.experimental.ndslice in 2.071 doesn't expose the `.ptr` (yet). // Random matrix auto rmat(T)(ulong nrow, ulong ncol, T min, T max){ return runif(nrow*ncol, min, max).sliced(nrow, ncol); } auto matrix_mult(T)(Slice!(2, T*) a, Slice!(2, T*) b){ int M = to!int(a.shape[0]); int K = to!int(a.shape[1]); int N = to!int(b.shape[1]); int n_el = to!int(a.elementsCount); T[] C = new T[M*N]; gemm(Order.ColMajor, Transpose.NoTrans, Transpose.NoTrans, M, N, K, 1., a.ptr, K, b.ptr, N, 0, C.ptr, N); return C.sliced(M, N); } void main() { int n = 4000; auto A = rmat(n, n, 0., 1.); auto B = rmat(n, n, 0., 1. ); StopWatch sw; sw.start(); auto C = matrix_mult(A, B); sw.stop(); writeln("Time taken: \n\t", sw.peek().msecs, " [ms]"); } If you really want to get the original T[] back, you could use something like ``` T[] a = slice.ptr[0.. slice.elementsCount]; ``` but for most cases `byElement` would be a lot better, because all transformations etc are of course only applied to your view. And where can I find more cool tricks like that? Browse the source code and the unittests. Phobos is an amazing resource :)
Re: Accessing COM Objects
On Wednesday, 15 June 2016 at 16:03:04 UTC, Jesse Phillips wrote: On Monday, 13 June 2016 at 01:22:33 UTC, Incognito wrote: [...] There is also: https://github.com/JesseKPhillips/Juno-Windows-Class-Library It kind of provides similar highlevel options as the "Modern COM Programming in D." But I don't use it and have only be somewhat keeping it alive (I had some hiccups in supporting 64bit), so I haven't been working to improve the simplicity of interfacing to COM objects. It also includes definitions for accessing Windows COM objects which aren't needed when interfacing with your own or other COM objects. I'd like to have two libraries, Juno Library and Juno Windows Class Library. I'll check it it out...
Re: Accessing COM Objects
On Wednesday, 15 June 2016 at 08:24:41 UTC, John wrote: On Wednesday, 15 June 2016 at 08:21:06 UTC, John wrote: OK, adding the return type to the signature should fix that. So: private static Parameter getParameters(MethodImpl method) Sorry, I meant the getParameter methods should return be: private static Parameter[] getParameters(MethodImpl method) and private static Parameter[] getParameters(MethodImpl method, out Parameter returnParameter, bool getReturnParameter) Thanks. When I ran it I got a d file! when I tried to use that d file I get undefined IID and IDispatch. I imagine these interfaces come from somewhere, probably built in? Any ideas?
Re: Accessing COM Objects
On Wednesday, 15 June 2016 at 15:12:06 UTC, thedeemon wrote: On Wednesday, 15 June 2016 at 07:01:30 UTC, Joerg Joergonson wrote: It seems idl2d from VD is not easily compilable? I don't remember problems with that, anyway here's the binary I used: http://stuff.thedeemon.com/idl2d.exe It crashes when I use it ;/ core.exception.UnicodeException@src\rt\util\utf.d(290): invalid UTF-8 sequence tbl2d did work and gave me a d file but I need to figure out what IID and IDispatch are.
Re: Accessing COM Objects
On Wednesday, 15 June 2016 at 16:45:39 UTC, Joerg Joergonson wrote: Thanks. When I ran it I got a d file! when I tried to use that d file I get undefined IID and IDispatch. I imagine these interfaces come from somewhere, probably built in? Any ideas? Add the following after the module name: import core.sys.windows.com, core.sys.windows.oaidl;
Re: arr.ptr, @safe and void*
On 6/15/16 6:32 AM, Nick Treleaven wrote: Hi, Walter's made a fix for arr[$..$].ptr being unsafe to dereference - .ptr will be @system: https://github.com/dlang/dmd/pull/5860 A referenced druntime pull mentioned having a safe wrapper for ..ptr that allows comparison of the pointer value, but does not allow dereference. The wrapper would return uintptr_t (an integer guaranteed to be big enough to hold a pointer value). My question is: would returning void* instead really be unsafe, i.e. is there a way of dereferencing it in safe code? (I'm not thinking about holes in @safe, but ways by design). Yes. If the meaning of this expression is different in @safe vs. @system, then compiler inference can affect code drastically: auto d = arr1.ptr - arr2.ptr; The PR I think you are referring to is mine: https://github.com/dlang/druntime/pull/1592 And this would be able to solve the problem, but I don't know if it's ready for prime time (proposed to be in core.internal). -Steve
Re: GTKD - Application crashes - or not? [Coedit]
On Wednesday, 15 June 2016 at 13:15:56 UTC, Rene Zwanenburg wrote: I'm not familiar with Coedit, but the run options seem to contain a field for setting it: https://github.com/BBasile/Coedit/wiki#run-options You may be able to use the symbolic strings there: https://github.com/BBasile/Coedit/wiki#symbolic-strings I changed the working directory in the native project configuration in "Pre-build process", "Post-build process" and in "Run options" in "default", "debug" and "release" to: C:\Users\Standardbenutzer\Documents\Dlang_Projects but i still get: glib.GException.GException@..\..\..\AppData\Roaming\dub\packages\gtk-d-3.3.1\gtk-d\src\glib\GException.d(40): Failed to import: No such file or directory 0x0045C39D 0x00402094 0x00402120 0x00403FC7 0x00403EC8 0x00402557 0x740F38F4 in BaseThreadInitThunk 0x76F85DE3 in RtlUnicodeStringToInteger 0x76F85DAE in RtlUnicodeStringToInteger error: the process (C:\Users\Standardbenutzer\Documents\Dlang_Projects\GTKD_Test.exe) has returned the signal 1
Re: ndslice: convert a sliced object to T[]
On Wednesday, 15 June 2016 at 12:10:32 UTC, Seb wrote: As said you can avoid the copy (see below). I also profiled it a bit and it was interesting to see that 50% of the runtime are spent on generating the random matrix. On my machine now both scripts take 1.5s when compiled with I didn't benchmark the RNG but I did notice it took a lot of time to generate the matrix but for now I am focused on the BLAS side of things. I am puzzled about how your code works: Firstly: I didn't know that you could substitute an array for its first element in D though I am aware that a pointer to an array's first element is equivalent to passing the array in C. auto matrix_mult(T)(T[] A, T[] B, Slice!(2, T*) a, Slice!(2, T*) b){ ... gemm(Order.ColMajor, Transpose.NoTrans, Transpose.NoTrans, M, N, K, 1., A.ptr, K, B.ptr, N, 0, C.ptr, N); return C.sliced(M, N); } Secondly: I am especially puzzled about using the second element to stand in for the slice itself. How does that work? And where can I find more cool tricks like that? void main() { ... auto C = matrix_mult(ta[0], tb[0], ta[1], tb[1]); sw.stop(); writeln("Time taken: \n\t", sw.peek().msecs, " [ms]"); } Many thanks!
Re: GTKD - Application crashes - or not? [Coedit]
On Wednesday, 15 June 2016 at 10:31:18 UTC, TheDGuy wrote: Thanks a lot for your answer, getcwd() returns the path where coedit is located on my harddrive: C:\Program Files (x86)\Coedit_32\coedit.2update6.win32 How can i change that? I'm not familiar with Coedit, but the run options seem to contain a field for setting it: https://github.com/BBasile/Coedit/wiki#run-options You may be able to use the symbolic strings there: https://github.com/BBasile/Coedit/wiki#symbolic-strings
Re: Accessing COM Objects
On Wednesday, 15 June 2016 at 17:20:31 UTC, John wrote: On Wednesday, 15 June 2016 at 16:45:39 UTC, Joerg Joergonson wrote: Thanks. When I ran it I got a d file! when I tried to use that d file I get undefined IID and IDispatch. I imagine these interfaces come from somewhere, probably built in? Any ideas? Add the following after the module name: import core.sys.windows.com, core.sys.windows.oaidl; Thanks. Should these not be added to the generated file? Also, could you add to it the following: const static GUID iid = Guid!("5DE90358-4D0B-4FA1-BA3E-C91BBA863F32"); inside the interface (Replace the string with the correct guid)? This allows it to work with ComPtr which looks for the iid inside the interface, shouldn't hurt anything. In any case, I haven't got ComPtr to work so... GUID Guid(string str)() { static assert(str.length==36, "Guid string must be 36 chars long"); enum GUIDstring = "GUID(0x" ~ str[0..8] ~ ", 0x" ~ str[9..13] ~ ", 0x" ~ str[14..18] ~ ", [0x" ~ str[19..21] ~ ", 0x" ~ str[21..23] ~ ", 0x" ~ str[24..26] ~ ", 0x" ~ str[26..28] ~ ", 0x" ~ str[28..30] ~ ", 0x" ~ str[30..32] ~ ", 0x" ~ str[32..34] ~ ", 0x" ~ str[34..36] ~ "])"; return mixin(GUIDstring); } also tried CoCreateInstance and getting error 80040154 Not sure if it works. Changed the GUID to another one found in the registry(not the one at the top of the generated file) and it works. Both load photoshop int main(string[] argv) { //auto ps = ComPtr!_Application(CLSID_PS).require; //const auto CLSID_PS = Guid!("6DECC242-87EF-11cf-86B4-44455354"); // PS 90.1 fails because of interface issue const auto CLSID_PS = Guid!("c09f153e-dff7-4eff-a570-af82c1a5a2a8"); // PS 90.0 works. auto hr = CoInitialize(null); auto iid = IID__Application; _Application* pUnk; hr = CoCreateInstance(_PS, null, CLSCTX_ALL, , cast(void**)); if (FAILED(hr)) throw new Exception("ASDF"); } The photoshop.d file http://www.filedropper.com/photoshop_1 So, I guess it works but how to access the methods? The photoshop file looks to have them listed but they are all commented out. I suppose this is what ComPtr and other methods are used to help create the interface but none seem to work.
Re: Accessing COM Objects
On Wednesday, 15 June 2016 at 18:35:42 UTC, Joerg Joergonson wrote: On Wednesday, 15 June 2016 at 06:09:33 UTC, thedeemon wrote: On Monday, 13 June 2016 at 17:38:41 UTC, Incognito wrote: [...] There are ready tools idl2d: https://github.com/dlang/visuald/tree/master/c2d [...] I can't seem to get ComPtr to work. auto ps = ComPtr!_Application(CLSID_PS).require; Where CLSID_PS is the Guid from the registry that seems to work with CoCreate. _Application was generated from tbl2d. See my other post for a more(not much) complete description of the issues files. Ensure you are calling CoInitialize before anything else.
Re: Accessing COM Objects
On Wednesday, 15 June 2016 at 06:09:33 UTC, thedeemon wrote: On Monday, 13 June 2016 at 17:38:41 UTC, Incognito wrote: [...] There are ready tools idl2d: https://github.com/dlang/visuald/tree/master/c2d [...] I can't seem to get ComPtr to work. auto ps = ComPtr!_Application(CLSID_PS).require; Where CLSID_PS is the Guid from the registry that seems to work with CoCreate. _Application was generated from tbl2d. See my other post for a more(not much) complete description of the issues files.
Re: Accessing COM Objects
On Wednesday, 15 June 2016 at 18:32:28 UTC, Joerg Joergonson wrote: import core.sys.windows.com, core.sys.windows.oaidl; Thanks. Should these not be added to the generated file? The problem is that other type libraries will probably require other headers to be imported, and there's no way to work out which, so I've left that up to the user for now. Also, could you add to it the following: const static GUID iid = Guid!("5DE90358-4D0B-4FA1-BA3E-C91BBA863F32"); inside the interface (Replace the string with the correct guid)? This allows it to work with ComPtr which looks for the iid inside the interface, shouldn't hurt anything. I could add that as an option. In any case, I haven't got ComPtr to work so... GUID Guid(string str)() { static assert(str.length==36, "Guid string must be 36 chars long"); enum GUIDstring = "GUID(0x" ~ str[0..8] ~ ", 0x" ~ str[9..13] ~ ", 0x" ~ str[14..18] ~ ", [0x" ~ str[19..21] ~ ", 0x" ~ str[21..23] ~ ", 0x" ~ str[24..26] ~ ", 0x" ~ str[26..28] ~ ", 0x" ~ str[28..30] ~ ", 0x" ~ str[30..32] ~ ", 0x" ~ str[32..34] ~ ", 0x" ~ str[34..36] ~ "])"; return mixin(GUIDstring); } also tried CoCreateInstance and getting error 80040154 Not sure if it works. Changed the GUID to another one found in the registry(not the one at the top of the generated file) and it works. Both load photoshop Oops. The one at the top of the file is the type library's ID, not the class ID. I should just omit it if it causes confusion. int main(string[] argv) { //auto ps = ComPtr!_Application(CLSID_PS).require; //const auto CLSID_PS = Guid!("6DECC242-87EF-11cf-86B4-44455354"); // PS 90.1 fails because of interface issue const auto CLSID_PS = Guid!("c09f153e-dff7-4eff-a570-af82c1a5a2a8"); // PS 90.0 works. auto hr = CoInitialize(null); auto iid = IID__Application; _Application* pUnk; hr = CoCreateInstance(_PS, null, CLSCTX_ALL, , cast(void**)); if (FAILED(hr)) throw new Exception("ASDF"); } The photoshop.d file http://www.filedropper.com/photoshop_1 So, I guess it works but how to access the methods? The photoshop file looks to have them listed but they are all commented out. They're commented out because Photoshop seems to have only provided a late-binding interface and you have to call them by name through IDispatch.Invoke. It's possible to wrap all that in normal D methods, and I'm working on it, but it won't be ready for a while.
Re: arr.ptr, @safe and void*
On Wednesday, 15 June 2016 at 17:35:49 UTC, Steven Schveighoffer wrote: On 6/15/16 6:32 AM, Nick Treleaven wrote: My question is: would returning void* instead really be unsafe, i.e. is there a way of dereferencing it in safe code? (I'm not thinking about holes in @safe, but ways by design). Yes. If the meaning of this expression is different in @safe vs. @system, then compiler inference can affect code drastically: auto d = arr1.ptr - arr2.ptr; I probably wasn't clear - I'm not suggesting .ptr returns void*, I agree with you. But I don't get why arr.ptrValue can't be safe and return void* instead of uintptr_t. The PR I think you are referring to is mine: https://github.com/dlang/druntime/pull/1592 And this would be able to solve the problem, but I don't know if it's ready for prime time (proposed to be in core.internal). I did see this, it's interesting. I suppose the advantage over ptrValue would be type safety.
Re: ndslice: convert a sliced object to T[]
On Wednesday, 15 June 2016 at 14:14:23 UTC, Seb wrote: ``` T[] a = slice.ptr[0.. slice.elementsCount]; ``` This would work only for slices with continuous memory representation and positive strides. -- Ilya
Re: Accessing COM Objects
On Wednesday, 15 June 2016 at 19:21:51 UTC, John wrote: On Wednesday, 15 June 2016 at 18:32:28 UTC, Joerg Joergonson wrote: import core.sys.windows.com, core.sys.windows.oaidl; Thanks. Should these not be added to the generated file? The problem is that other type libraries will probably require other headers to be imported, and there's no way to work out which, so I've left that up to the user for now. Also, could you add to it the following: const static GUID iid = Guid!("5DE90358-4D0B-4FA1-BA3E-C91BBA863F32"); inside the interface (Replace the string with the correct guid)? This allows it to work with ComPtr which looks for the iid inside the interface, shouldn't hurt anything. I could add that as an option. In any case, I haven't got ComPtr to work so... GUID Guid(string str)() { static assert(str.length==36, "Guid string must be 36 chars long"); enum GUIDstring = "GUID(0x" ~ str[0..8] ~ ", 0x" ~ str[9..13] ~ ", 0x" ~ str[14..18] ~ ", [0x" ~ str[19..21] ~ ", 0x" ~ str[21..23] ~ ", 0x" ~ str[24..26] ~ ", 0x" ~ str[26..28] ~ ", 0x" ~ str[28..30] ~ ", 0x" ~ str[30..32] ~ ", 0x" ~ str[32..34] ~ ", 0x" ~ str[34..36] ~ "])"; return mixin(GUIDstring); } also tried CoCreateInstance and getting error 80040154 Not sure if it works. Changed the GUID to another one found in the registry(not the one at the top of the generated file) and it works. Both load photoshop Oops. The one at the top of the file is the type library's ID, not the class ID. I should just omit it if it causes confusion. int main(string[] argv) { //auto ps = ComPtr!_Application(CLSID_PS).require; //const auto CLSID_PS = Guid!("6DECC242-87EF-11cf-86B4-44455354"); // PS 90.1 fails because of interface issue const auto CLSID_PS = Guid!("c09f153e-dff7-4eff-a570-af82c1a5a2a8"); // PS 90.0 works. auto hr = CoInitialize(null); auto iid = IID__Application; _Application* pUnk; hr = CoCreateInstance(_PS, null, CLSCTX_ALL, , cast(void**)); if (FAILED(hr)) throw new Exception("ASDF"); } The photoshop.d file http://www.filedropper.com/photoshop_1 So, I guess it works but how to access the methods? The photoshop file looks to have them listed but they are all commented out. They're commented out because Photoshop seems to have only provided a late-binding interface and you have to call them by name through IDispatch.Invoke. It's possible to wrap all that in normal D methods, and I'm working on it, but it won't be ready for a while. Ok, I've tried things like uncommenting Document Open(BSTR Document, VARIANT As, VARIANT AsSmartObject); void Load(BSTR Document); /*[id(0x70537673)]*/ BSTR get_ScriptingVersion(); /*[id(0x70464D4D)]*/ double get_FreeMemory(); /*[id(0x76657273)]*/ BSTR get_Version(); and everything crashes with bad reference. If I try ComPtr, same thing const auto CLSID_PS = Guid!("c09f153e-dff7-4eff-a570-af82c1a5a2a8"); // PS 90.0 works. auto hr = CoInitialize(null); auto iid = IID__Application; auto ps = cast(_Application)(ComPtr!_Application(CLSID_PS).require); _Application pUnk; hr = CoCreateInstance(_PS, null, CLSCTX_ALL, , cast(void**)); if (FAILED(hr)) throw new Exception("ASDF"); auto ptr = cast(wchar*)alloca(wchar.sizeof * 1000); auto fn = `ps.psd`; for(auto i = 0; i < fn.length; i++) { ptr[i] = fn[i]; } writeln(ps.get_FreeMemory()); pUnk.Load(ptr); My thinking is that CoCreateinstance is suppose to give us a pointer to the interface so we can use it, if all this stuff is crashing does that mean the interface is invalid or not being assigned properly or is there far more to it than this? (
Re: get number of columns and rows in an ndarray.
On Wednesday, 15 June 2016 at 21:51:25 UTC, learner wrote: Hi, How can i get the number of cols and rows in and ndarray that has already been created? learner how about `shape`? http://dlang.org/phobos/std_experimental_ndslice_slice.html#.Slice.shape
get number of columns and rows in an ndarray.
Hi, How can i get the number of cols and rows in and ndarray that has already been created? learner
Re: GTKD - overrideBackgroundColor of Button doesn't work
On Wednesday, 15 June 2016 at 09:03:45 UTC, TheDGuy wrote: Hello, why does this code not work? RGBA rgb = new RGBA(1,0.5,0.5,1.0); Button btn_1 = new Button("Start"); btn_1.overrideBackgroundColor(StateFlags.NORMAL, rgb); The color of btn_1 just doesn't change. https://developer.gnome.org/gtk3/stable/GtkWidget.html#gtk-widget-override-background-color
Re: Passing anonymous templated functions as template parameters
On Wednesday, 15 June 2016 at 23:52:56 UTC, Basile B. wrote: On Wednesday, 15 June 2016 at 22:27:38 UTC, pineapple wrote: Here's a simple code example to illustrate what I expected to work and didn't - is this a mistake in my syntax or a limitation of the language? template SomeTemplate(alias func){ auto templatefunc(T)(int x){ return func!T(x); } } // Valid auto somefunc(T)(int x){ return cast(T) x; } alias fn1 = SomeTemplate!somefunc; // Not valid alias fn2 = SomeTemplate!( (T)(int x){return cast(T) x;} ); This syntax passes: alias fn2(T) = SomeTemplate!((int x){return cast(T) x;}); I didn't try to instanciate previously. It works a bit with a lambda to the extent that the alias has the template parameter list. import std.stdio; template A(alias func) { auto a(T)(int x) { return func!T(x); } } alias spec(T) = A!(x => (cast(T) x)); void main(string[] args) { writeln((spec!byte).a!int(257)); // 1 }
Re: GTKD - Application crashes - or not? [Coedit]
On Wednesday, 15 June 2016 at 23:41:51 UTC, Basile B. wrote: On Wednesday, 15 June 2016 at 17:35:32 UTC, TheDGuy wrote: I'm gonna check on Windows today but in the meantime you can try I've checked on windows and here is what I can say about the problem. - Symbolic strings won't work on the "CurrentDirectoy" parameter. This is not handled at all. (you would get an error 267). I'll add the translation code for this parameter but this is for version 3 so not soon. - I had to verify but the cwd should really be set to the path where the application is output. I mean that it's written so. I don't know what's happening on your system right now. My windows is still win 7 and my dev directory is not in ProgramFiles. And I've tested using this simple project: https://gist.github.com/BBasile/2e110ed48989b53e2a53b57977a81736. You can DL it as a zip, open the .ce file as a project and click "compile project and run" you should see the right CWD written in the messages. - You can create a launcher in the custom tools, excluding the double quote: - as executable type "" - as CurrentDirectory type "" - as alias put something like "Run this project" This will work if the binary is compiled in the same directory as the binary that's produced. Otherwise you can adjust by adding directories after the symbol. (e.g "bin\release").
Out of order execution
Suppose I have a loop where I execute two functions: for(...) { if (x) Do1(x); if (y) Do2(y); } The problem is, I really always want to execute all the Do2's first then the Do1's. As is, we could get any order of calls. Suppose I can't run the loop twice for performance reasons(there is other stuff in it) and I don't want to store the state and call info then sort them out afterwards. Is there an efficient lazy way to make this happen?
Re: GTKD - overrideBackgroundColor of Button doesn't work
string cssPath = "test.css"; CssProvider provider = new CssProvider(); provider.loadFromPath(cssPath); unfortunately i don't know anything about yr specific problem. but i just wanted to mention (in case you are not aware of it) that the CSS can be embedded into the D source. this is what i did to fix GTKs terrible design mistake for the background of Notebook: ``` enum myCSS = q{ GtkNotebook { background-color: #e9e9e9; } GtkNotebook tab { background-color: #d6d6d6; } }; ... int main(string[] args){ ... import gtk.CssProvider; auto styleProvider = new CssProvider; styleProvider.loadFromData(myCSS); import gdk.Screen; import gtk.StyleContext; StyleContext.addProviderForScreen( Screen.getDefault(), styleProvider, 800); ```
Passing anonymous templated functions as template parameters
Here's a simple code example to illustrate what I expected to work and didn't - is this a mistake in my syntax or a limitation of the language? template SomeTemplate(alias func){ auto templatefunc(T)(int x){ return func!T(x); } } // Valid auto somefunc(T)(int x){ return cast(T) x; } alias fn1 = SomeTemplate!somefunc; // Not valid alias fn2 = SomeTemplate!( (T)(int x){return cast(T) x;} );
Re: get number of columns and rows in an ndarray.
On Wednesday, 15 June 2016 at 21:54:22 UTC, Seb wrote: On Wednesday, 15 June 2016 at 21:51:25 UTC, learner wrote: Hi, How can i get the number of cols and rows in and ndarray that has already been created? learner how about `shape`? http://dlang.org/phobos/std_experimental_ndslice_slice.html#.Slice.shape Thanks
Re: arr.ptr, @safe and void*
On 6/15/16 4:08 PM, Nick Treleaven wrote: On Wednesday, 15 June 2016 at 17:35:49 UTC, Steven Schveighoffer wrote: On 6/15/16 6:32 AM, Nick Treleaven wrote: My question is: would returning void* instead really be unsafe, i.e. is there a way of dereferencing it in safe code? (I'm not thinking about holes in @safe, but ways by design). Yes. If the meaning of this expression is different in @safe vs. @system, then compiler inference can affect code drastically: auto d = arr1.ptr - arr2.ptr; I probably wasn't clear - I'm not suggesting .ptr returns void*, I agree with you. But I don't get why arr.ptrValue can't be safe and return void* instead of uintptr_t. It could probably do this. Dereferencing a void * isn't valid, so it kind of has the same effect. However, there are many functions which take void * and do write to/read from the data pointing at it (e.g. memcpy). These aren't @safe, so they should be off-limits. The original fix proposed by Walter was to return const(void)*. This probably would have been fine, Daniel objected to it, but he may have been thrown off by the comment in the code which said "Ok because the user will never dereference the pointer", hinting the user may have a choice to do so. Hard to tell. But the nice thing about returning a non-pointer is that you can't accidentally use it in cases where your code is @system or @trusted. It states clearly "I only care about the location of this memory, not what's in it". There is some value in that. -Steve
Re: GTKD - overrideBackgroundColor of Button doesn't work
On Wednesday, 15 June 2016 at 20:49:02 UTC, Gerald wrote: On Wednesday, 15 June 2016 at 09:03:45 UTC, TheDGuy wrote: Hello, why does this code not work? RGBA rgb = new RGBA(1,0.5,0.5,1.0); Button btn_1 = new Button("Start"); btn_1.overrideBackgroundColor(StateFlags.NORMAL, rgb); The color of btn_1 just doesn't change. https://developer.gnome.org/gtk3/stable/GtkWidget.html#gtk-widget-override-background-color Thanks for your reply, i now tried to use CSS instead: import std.stdio; import std.file; import gtk.Main; import gtk.MainWindow; import gtk.CssProvider; import gtk.Button; import gdk.Display; import gdk.Screen; import gtk.StyleContext; class Window : MainWindow{ this(int width, int height, string title){ super(title); setDefaultSize(width, height); Button btn = new Button("Test"); btn.setName("CssName"); string cssPath = "test.css"; CssProvider provider = new CssProvider(); provider.loadFromPath(cssPath); Display display = Display.getDefault(); Screen screen = display.getDefaultScreen(); StyleContext.addProviderForScreen(screen, provider, GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); add(btn); showAll(); } } void main(string[] args){ writeln(getcwd()); Main.init(args); auto win = new Window(250,250,"Tutorial"); Main.run(); } This is my CSS: GtkWindow{ background-color:blue; } #CssName{ -GtkWidget-focus-line-width:0; background-color:green; color:green; } The text color is green but the button background color is still default-gray! I am also wondering how it is possible to change the button color at runtime? In my opinion i don't think that CSS-based style has alot of advantages over the commonly used object functions.
Re: GTKD - overrideBackgroundColor of Button doesn't work
On Wednesday, 15 June 2016 at 21:39:37 UTC, TheDGuy wrote: On Wednesday, 15 June 2016 at 20:49:02 UTC, Gerald wrote: On Wednesday, 15 June 2016 at 09:03:45 UTC, TheDGuy wrote: Hello, why does this code not work? RGBA rgb = new RGBA(1,0.5,0.5,1.0); Button btn_1 = new Button("Start"); btn_1.overrideBackgroundColor(StateFlags.NORMAL, rgb); The color of btn_1 just doesn't change. https://developer.gnome.org/gtk3/stable/GtkWidget.html#gtk-widget-override-background-color snip... The text color is green but the button background color is still default-gray! I don't see an obvious issue with your code, I usually use CSS classes personally and I know that works fine because I use this technique all over terminix. I would suggest using the GTK Inspector to debug the CSS issue, it's an awesome tool for figuring out GTK CSS issues as it let's you change CSS on the fly, see what CSS is being applied to an object, etc. You can see how to use it at the link below: https://wiki.gnome.org/Projects/GTK%2B/Inspector I am also wondering how it is possible to change the button color at runtime? In my opinion i don't think that CSS-based style has alot of advantages over the commonly used object functions. Personally I just add and remove classes as needed: getStyleContext().addClass() getStyleContext().removeClass()
Re: Passing anonymous templated functions as template parameters
On Wednesday, 15 June 2016 at 22:27:38 UTC, pineapple wrote: Here's a simple code example to illustrate what I expected to work and didn't - is this a mistake in my syntax or a limitation of the language? template SomeTemplate(alias func){ auto templatefunc(T)(int x){ return func!T(x); } } // Valid auto somefunc(T)(int x){ return cast(T) x; } alias fn1 = SomeTemplate!somefunc; // Not valid alias fn2 = SomeTemplate!( (T)(int x){return cast(T) x;} ); This syntax passes: alias fn2(T) = SomeTemplate!((int x){return cast(T) x;});
Re: GTKD - Application crashes - or not? [Coedit]
On Wednesday, 15 June 2016 at 17:35:32 UTC, TheDGuy wrote: On Wednesday, 15 June 2016 at 13:15:56 UTC, Rene Zwanenburg wrote: I'm not familiar with Coedit, but the run options seem to contain a field for setting it: https://github.com/BBasile/Coedit/wiki#run-options You may be able to use the symbolic strings there: https://github.com/BBasile/Coedit/wiki#symbolic-strings I changed the working directory in the native project configuration in "Pre-build process", "Post-build process" and in "Run options" in "default", "debug" and "release" to: You just need to change "CurrentDirectory" in the "Run options". The two others are for the process that's executed before and after compiling. I'm gonna check on Windows today but in the meantime you can try - sets the output path to to a value that's different from the project file location, e.g bin/name.exe and remove completly the value you've set in "Run Options"\"CurrentDirectory" - add a trailing back slash to the value in the "Run Options"\"CurrentDirectory"
Re: Passing anonymous templated functions as template parameters
On 6/15/16 7:52 PM, Basile B. wrote: On Wednesday, 15 June 2016 at 22:27:38 UTC, pineapple wrote: Here's a simple code example to illustrate what I expected to work and didn't - is this a mistake in my syntax or a limitation of the language? template SomeTemplate(alias func){ auto templatefunc(T)(int x){ return func!T(x); } } // Valid auto somefunc(T)(int x){ return cast(T) x; } alias fn1 = SomeTemplate!somefunc; // Not valid alias fn2 = SomeTemplate!( (T)(int x){return cast(T) x;} This isn't valid syntax. I don't think you can create anonymous templates. I could be wrong. -Steve
Why don't we write configuration files in D instead of JSON?
It would seem that by running the file through mixin, you can simply create the vars you want in scope. The drawback being random code execution. Is there any way to sanitize mixin code from user-configurable file? Once that's shot down, does anyone know a .json to .sdl converter program