Re: Cannot spawn process: npm start
On Tuesday, 4 October 2016 at 18:41:16 UTC, FreeSlave wrote: On Tuesday, 4 October 2016 at 17:02:34 UTC, Adam D. Ruppe wrote: On Tuesday, 4 October 2016 at 16:55:22 UTC, Andre Pany wrote: Spawn process is working fine on linux, only on windows it doesn't work. I will create a bug report. This isn't really a bug if it is a cmd file like the other poster said... cmd files are scripts that need to be run through the interpreter. shellExec probably handles it, or you could spawnProcess "cmd" with the npm being an argument to it. There's no shellExec, but executeShell. spawnShell would fit better since author used spawnProcess in original post. Whether spawnProcess should handle .bat and .cmd is a matter of function design really. Actually I would like to treat spawnProcess more like double-click on application and double-click works for scripts on windows. So there will be no special code for phobos user to handle this case. I found the trick. If I change args to ["npm.cmd", "start"] it will work. I do not know whether spawnProcess should handle npm vs npm.cmd automatically. Should I close the bug report? In the beginning I used executeShell, but had some issue to stop the started server applications. Somehow the server applications weren't stopped although kill and wait were executed. The same scenario is working fine with spawnProcess. Kind regards André
Re: Why can't static arrays be sorted?
On Tuesday, October 04, 2016 20:05:15 TheGag96 via Digitalmars-d-learn wrote: > I was writing some code today and ran into this oddity that I'd > never come across before: > > import std.algorithm : sort; > int[10] arr = [0, 3, 4, 6, 2, 1, 1, 4, 6, 9]; > thing.sort(); > > This doesn't compile. Obviously the .sort property works, but > what about static arrays makes them unable to be sorted by > std.algorithm.sort? Thanks. The problem is that static arrays aren't ranges (calling popFront on them can't work, because their length isn't mutable). However, you can slice a static array to get a dynamic array which _is_ a range. e.g. thing[].sort(); Just make sure that such a dynamic array does not outlive the static array, or it will refer to invalid memory (which would not be a problem in this case). - Jonathan M Davis
Re: Why can't static arrays be sorted?
On Tuesday, 4 October 2016 at 20:05:15 UTC, TheGag96 wrote: I was writing some code today and ran into this oddity that I'd never come across before: import std.algorithm : sort; int[10] arr = [0, 3, 4, 6, 2, 1, 1, 4, 6, 9]; thing.sort(); This doesn't compile. Obviously the .sort property works, but what about static arrays makes them unable to be sorted by std.algorithm.sort? Thanks. Try: arr[].sort();
Re: Shared an non-shared
On 10/04/2016 09:22 PM, Begah wrote: I seem to be missing something. It seems that if you want to create a shared object of a structure ( or class ), then I have to copy every functions and add "shared" to it. This seems way more work than it should. For example why can't this simply work : class Image { string name; int contents; this(string name, int contents) { this.name = name; this.contents = contents; } void printContents() { writeln(name, " : ", contents); } void changeContents(int newContents) { this.contents = newContents; } } void main() { Image im = new Image("Test", 15); im.printContents(); im.changeContents(45); im.printContents(); shared Image imShared = new shared Image("Test2", 80); imShared.printContents(); imShared.changeContents(6); imShared.printContents(); } Non-`shared` methods are not required to be somehow thread-safe at all. So they can't be allowed to be called on `shared` objects. The compiler can't automatically ensure thread-safety, because it can't know what can run in parallel and what can't. How can I make a method that accepts being called by both a shared and non-shared object, to prevent having to copy methods and adding a "shared"? I would have thought that you can call a shared method on an unshared object. Apparently not. There's probably a reason for that, but I don't see it at the moment. I am not looking for an explanation for how to handle multi-threading ( synchronization and so on ). I am looking to use pre-coded classes and structures ( without using __gshared ) with non-shared and shared objects. Ensure thread-safety and cast `shared` away.
Re: Why can't static arrays be sorted?
On Tuesday, 4 October 2016 at 20:05:15 UTC, TheGag96 wrote: I was writing some code today and ran into this oddity that I'd never come across before: import std.algorithm : sort; int[10] arr = [0, 3, 4, 6, 2, 1, 1, 4, 6, 9]; thing.sort(); This doesn't compile. Obviously the .sort property works, but what about static arrays makes them unable to be sorted by std.algorithm.sort? Thanks. Static arrays in D are value types. Try: thing[].sort(); This will pass a slice of the array to sort, holding a reference to the static array's data.
Why can't static arrays be sorted?
I was writing some code today and ran into this oddity that I'd never come across before: import std.algorithm : sort; int[10] arr = [0, 3, 4, 6, 2, 1, 1, 4, 6, 9]; thing.sort(); This doesn't compile. Obviously the .sort property works, but what about static arrays makes them unable to be sorted by std.algorithm.sort? Thanks.
Shared an non-shared
I seem to be missing something. It seems that if you want to create a shared object of a structure ( or class ), then I have to copy every functions and add "shared" to it. This seems way more work than it should. For example why can't this simply work : class Image { string name; int contents; this(string name, int contents) { this.name = name; this.contents = contents; } void printContents() { writeln(name, " : ", contents); } void changeContents(int newContents) { this.contents = newContents; } } void main() { Image im = new Image("Test", 15); im.printContents(); im.changeContents(45); im.printContents(); shared Image imShared = new shared Image("Test2", 80); imShared.printContents(); imShared.changeContents(6); imShared.printContents(); } How can I make a method that accepts being called by both a shared and non-shared object, to prevent having to copy methods and adding a "shared"? I am not looking for an explanation for how to handle multi-threading ( synchronization and so on ). I am looking to use pre-coded classes and structures ( without using __gshared ) with non-shared and shared objects.
Re: Cannot spawn process: npm start
On Tuesday, 4 October 2016 at 17:02:34 UTC, Adam D. Ruppe wrote: On Tuesday, 4 October 2016 at 16:55:22 UTC, Andre Pany wrote: Spawn process is working fine on linux, only on windows it doesn't work. I will create a bug report. This isn't really a bug if it is a cmd file like the other poster said... cmd files are scripts that need to be run through the interpreter. shellExec probably handles it, or you could spawnProcess "cmd" with the npm being an argument to it. There's no shellExec, but executeShell. spawnShell would fit better since author used spawnProcess in original post. Whether spawnProcess should handle .bat and .cmd is a matter of function design really. Actually I would like to treat spawnProcess more like double-click on application and double-click works for scripts on windows. So there will be no special code for phobos user to handle this case.
Re: Cannot spawn process: npm start
On Tuesday, 4 October 2016 at 16:55:22 UTC, Andre Pany wrote: Spawn process is working fine on linux, only on windows it doesn't work. I will create a bug report. This isn't really a bug if it is a cmd file like the other poster said... cmd files are scripts that need to be run through the interpreter. shellExec probably handles it, or you could spawnProcess "cmd" with the npm being an argument to it.
Re: Getting GtkD working with OpenGL
On 10/03/2016 11:46 PM, Chalix wrote: On Monday, 3 October 2016 at 18:00:53 UTC, Mike Wey wrote: The signal functions can be found in the gobject.Signals module. But you should use the GLArea.addOnCreateContext / addOnRender / addOnResize functions to attach a D delegate to the signal. You will still need to link with the OpenGL libraries or use someting like Derelict. Hi Mike, thanks for your fast answer again! I just read about this delegates and I liked the concept. I experimented with it for a while and read a bit on the Internet, but I still don't get it working... My minimal example looks like this: import gtk.Main; import gtk.MainWindow; import gtk.GLArea; import glgdk.GLContext; void main(string[] args) { bool render(GLContext context, GLArea area) { return true; } Main.init(args); MainWindow win = new MainWindow("Hello World"); GLArea area = new GLArea(); area.addOnRender(&render,cast(GConnectFlags)0); win.add(area); win.showAll(); Main.run(); } If I compile it, I get this error: $ dmd main.d -I/usr/local/include/d/gtkd-3 -L-lgtkd-3 main.d(27): Error: function gtk.GLArea.GLArea.addOnRender (bool delegate(GLContext, GLArea) dlg, GConnectFlags connectFlags = cast(GConnectFlags)0) is not callable using argument types (bool delegate(GLContext context, GLArea area), GConnectFlags) I cant see, what I am doing wrong... Someone else sees the error? Tomorrow I try to subclass the GLArea, if this works I am happy :) But I'd like to use the handler stuff. Ah, and I know now, that I have to link against the GL and GLU library, but which module do I have to import, to make the functions visible for the compiler? Or do I need another binding therefore? Replace "import glgdk.GLContext;" with "import gdk.GLContext;" The error is a bit confusing without the fully qualified names of the types, but GLArea depends on the OpenGL functionality build in to GDK, and doesn't depend on gtkglext. -- Mike Wey
Re: Cannot spawn process: npm start
On Tuesday, 4 October 2016 at 13:52:23 UTC, FreeSlave wrote: On Tuesday, 4 October 2016 at 12:58:19 UTC, Andre Pany wrote: Hi, I need to call a Node application. node and npm are in windows path variable. I have following folder structure: ./app.d ./js/helloworld.js ./js/package.json [...] npm is .cmd file on Windows. Maybe this is issue. Looks like cmd.exe knows how to deal with them, while CreateProcess does not. I just tried the D coding on Ubuntu Sub System for windows. Spawn process is working fine on linux, only on windows it doesn't work. I will create a bug report. Kind regards André
Re: Cannot spawn process: npm start
On Tuesday, 4 October 2016 at 13:18:45 UTC, Adam D. Ruppe wrote: Are you sure npm is in the path? From your shell, do `which npm` and see where it is coming from, you might want to use the full path to spawn process. Yes, npm is in path. From all directories I can execute npm/node (--version) and receive a valid result. I can execute npm start within folder "js" in both consoles, git bash and windows cmd. There it works fine. On windows cmd which is not a known command. On git bash I receive as result: /c/Program Files/nodejs/npm Kind regards André
Re: Using OpenGL
Back again with another little problem that isn't specifically OpenGL related, but is a result of getting such code to work. Code I'm working on: https://dfcode.wordpress.com/2016/10/04/linker-problem/ What I'm learning from: http://www.learnopengl.com/#!Getting-started/Camera, http://www.learnopengl.com/code_viewer.php?type=header&code=camera The problem is I'm trying to move camera code into a module and import it, but when I try to build I'm getting the following error messages: source\app.d(256,30): Error: function 'fpscamera.fpsCamera.processMouseMovement' is not nothrow source\app.d(243,7): Error: function 'app.mouse_callback' is nothrow yet may throw If I add nothrow to processMouseMovement, like I did for some other functions, I get the following: .dub\build\application-debug-windows-x86-dmd_2071-3EF635850CA47CC4E927BFC9336E0233\ogl.obj(ogl) Error 42: Symbol Undefined _D9fpscamera9fpsCamera13getViewMatrixMxFNdZS4gl3n6linalg21__T6MatrixTfVii4Vii4Z6Matrix .dub\build\application-debug-windows-x86-dmd_2071-3EF635850CA47CC4E927BFC9336E0233\ogl.obj(ogl) Error 42: Symbol Undefined _D9fpscamera9fpsCamera20processMouseMovementMFNbffhZv .dub\build\application-debug-windows-x86-dmd_2071-3EF635850CA47CC4E927BFC9336E0233\ogl.obj(ogl) Error 42: Symbol Undefined _D9fpscamera9fpsCamera18processMouseScrollMFNbfZv .dub\build\application-debug-windows-x86-dmd_2071-3EF635850CA47CC4E927BFC9336E0233\ogl.obj(ogl) Error 42: Symbol Undefined _D9fpscamera9fpsCamera15processKeyboardMFE9fpscamera14CameraMovementfZv .dub\build\application-debug-windows-x86-dmd_2071-3EF635850CA47CC4E927BFC9336E0233\ogl.obj(ogl) Error 42: Symbol Undefined _D9fpscamera12__ModuleInfoZ --- errorlevel 5 It seems to happen if I make both processMouseMovement and processMouseScroll nothrow to get rid of the error messages. If one or the other is nothrow, I get the nothrow message for that function.
artistic and boost licenses compatibility
Could somebody answer the following question: may I port a project that has artistic license to D and relicense it under boost one? Artistic license allows relicensing in total but I'm not sure it's possible in case of Boost license. Thanks
Re: Cannot spawn process: npm start
On Tuesday, 4 October 2016 at 12:58:19 UTC, Andre Pany wrote: Hi, I need to call a Node application. node and npm are in windows path variable. I have following folder structure: ./app.d ./js/helloworld.js ./js/package.json [...] npm is .cmd file on Windows. Maybe this is issue. Looks like cmd.exe knows how to deal with them, while CreateProcess does not.
Re: bug, or is this also intended?
On Monday, 3 October 2016 at 11:40:00 UTC, deed wrote: Unexpected auto-concatenation of string elements: string[] arr = ["a", "b" "c"];// ["a", "bc"], length==2 int[] arr2 = [[1], [2] [3]];// Error: array index 3 is out of bounds [2][0 .. 1] // Error: array index 3 is out of bounds [0..1] dmd 2.071.2-b2 It comes from C. In C you can write stuff like: char* foo = "Foo is good but... " "... bar is better!"; Eg static string concatenation for multiline/macros etc. Think it was implemented this way to provide better support for converting c codebases.
Re: Simple Function Parameter question...
On Tuesday, 4 October 2016 at 13:16:35 UTC, Adam D. Ruppe wrote: I'd put your repeated variables together in a struct, then pass it around to the functions. At least then you pass just one param at a time, without losing the info. That's not a bad idea. I have been creating "ids" to point to my structs and passing that around where needed, but in places it's still getting ugly, as they are sometimes more complicated than single vars, but it does the trick. I might just get it to work the ugly way, and try pretty it up later. :P
Re: Cannot spawn process: npm start
Are you sure npm is in the path? From your shell, do `which npm` and see where it is coming from, you might want to use the full path to spawn process.
Re: Simple Function Parameter question...
I'd put your repeated variables together in a struct, then pass it around to the functions. At least then you pass just one param at a time, without losing the info.
Simple Function Parameter question...
Howdy folks This might be a really stupid question, but ya know, if you don't ask ... So, anytime I am calling a function, I have to include everything that the function needs all the time. My simplistic example is: #!/usr/bin/rdmd import std.stdio; void test(string firstinput, string secondinput) { if(secondinput=="world") printoutput(firstinput, secondinput); } void printoutput(string thisIsJustGreeting, string secondinput) { writeln(thisIsJustGreeting, " ", secondinput); } void main() { string greeting = "hello"; // I really don't want to bring this through every function string thisthing = "world"; test(greeting, thisthing); } For this, I don't really want to keep bringing "greeting" around with me. Now, I know if I call `printoutput` from somewhere where that variable hasn't been declared it'll go nuts, but at the moment my code is ugly because I have to keep carrying variables around everywhere ... But when I have a whole heap of things which are quasi-global I don't want to keep having to include the same things over and over again, especially functions within functions. For a tedious example: Maybe my program design just needs rethinking (I'm not from a CS background, so I struggle with the easy stuff sometimes), but a simple/better way of doing this would really help. :) TIA
Cannot spawn process: npm start
Hi, I need to call a Node application. node and npm are in windows path variable. I have following folder structure: ./app.d ./js/helloworld.js ./js/package.json content of helloworld.js: console.log('hello world'); content of package.json: { "name": "test", "version": "1.0.0", "scripts": { "start": "node helloworld.js" } } content of app.d import std.process, std.path, std.file, std.stdio; void main() { string workDir = buildPath(thisExePath.dirName, "js"); string[] args = ["npm", "start"]; spawnProcess(args, std.stdio.stdin, std.stdio.stdout, std.stdio.stderr, null, std.process.Config.none, workDir); } I compile with dmd and then start the application. I always receive an error "Failed to spawn new process". As I specify the work directory, this should work, or? Kind regards André
Re: How to debug (potential) GC bugs?
On Sunday, 25 September 2016 at 16:23:11 UTC, Matthias Klumpp wrote: Hello! I am working together with others on the D-based appstream-generator[1] project, which is generating software metadata for "software centers" and other package-manager functionality on Linux distributions, and is used by default on Debian, Ubuntu and Arch Linux. [...] Probably related issue: https://issues.dlang.org/show_bug.cgi?id=15939