Re: Is there any bettter solution to Windows wide string

2021-05-09 Thread FreeSlave via Digitalmars-d-learn
On Saturday, 8 May 2021 at 20:50:10 UTC, Vinod K Chandran wrote: Hi all, I am planning some win32 hobby projects. Now I have this function to tackle the LPCWSTR data type in win32. ```d private import std.utf; auto toWString(S)(S s) { return toUTFz!(const(wchar)*)(s); } ``` Is there any better

Remove routes from URLRouter in vibe.d

2021-03-17 Thread FreeSlave via Digitalmars-d-learn
I want to be able to dynamically remove some routes in my Vibe.d application. URLRouter accounts for newly added routes, but I can't find a way to clear routes unless I create the new URLRouter object, in which case I also need to re-create HTTP listener. Also, is it safe to replace already

Re: Getting the source text of an expression

2020-12-17 Thread FreeSlave via Digitalmars-d-learn
On Thursday, 17 December 2020 at 19:45:38 UTC, Dave P. wrote: In C, you can use a macro to get the source text of an expression as a string. For example #include #define PRINT_INT(x) printf(#x " = %d\n", x) int main(){ // prints "3 = 3" PRINT_INT(3); int x = 4; // prints "x =

Re: How can I set Timeout of Socket?

2020-11-14 Thread FreeSlave via Digitalmars-d-learn
On Sunday, 15 November 2020 at 00:05:08 UTC, Marcone wrote: Socket s = new Socket(AddressFamily.INET, SocketType.STREAM); s.connect(new InternetAddress("domain.com", 80)); I want that program raise an error if reach for example 30 seconds of timeout. Perhaps using Socket.select and

Re: Renaming Flag!"" in API

2020-10-12 Thread FreeSlave via Digitalmars-d-learn
On Monday, 12 October 2020 at 16:44:52 UTC, Ali Çehreli wrote: It's amazing how things come together before each conference. Flag appears among my slides for an upcoming conference as well! :) But I don't think there is any solution to your problem. On 10/12/20 3:24 AM, FreeSlave wrote: >

Re: Renaming Flag!"" in API

2020-10-12 Thread FreeSlave via Digitalmars-d-learn
On Monday, 12 October 2020 at 11:34:25 UTC, Vladimir Panteleev wrote: On Monday, 12 October 2020 at 10:24:44 UTC, FreeSlave wrote: Can this issue overcome somehow? Why not add a deprecated overload for your function which takes the old Flag value? I thought about overloading too.

Renaming Flag!"" in API

2020-10-12 Thread FreeSlave via Digitalmars-d-learn
Let's say I use Flag type named 'myflagname' in API like this: import std.typecons; void func(Flag!"myflagname" flag) { //... } void main() { func(Yes.myflagname); } Later I realize that 'myflagname' is a bad name and I want to change it to something else. But if I do so, I break the

More complete windows declarations

2020-09-21 Thread FreeSlave via Digitalmars-d-learn
Druntime has a limited set of declarations, lacking some COM interfaces, e.g. IShellItem and IFileOperation (the latter is understandable though as it was introduced in Vista, and I guess druntime declarartions are limited to symbols from XP), and some others are declared wrongly (e.g.

Re: Access violation when using IShellFolder2

2020-09-10 Thread FreeSlave via Digitalmars-d-learn
On Thursday, 10 September 2020 at 15:20:54 UTC, John Chapman wrote: On Thursday, 10 September 2020 at 13:30:15 UTC, FreeSlave wrote: Thanks. I tried this, but VarDateFromStr does not succeed for me. It turns out the shell embeds some control characters in the string, specifically 8206 and

Re: Access violation when using IShellFolder2

2020-09-10 Thread FreeSlave via Digitalmars-d-learn
On Thursday, 10 September 2020 at 06:43:35 UTC, John Chapman wrote: On Wednesday, 9 September 2020 at 22:44:50 UTC, FreeSlave wrote: Btw do you know how to parse a date returned by GetDetailsOf? Couldn't find any examples in C++. I actually can see digits representing date and time as a part

Re: Access violation when using IShellFolder2

2020-09-09 Thread FreeSlave via Digitalmars-d-learn
On Wednesday, 9 September 2020 at 07:18:04 UTC, John Chapman wrote: On Tuesday, 8 September 2020 at 22:24:22 UTC, FreeSlave wrote: However if I change the type of recycleBin variable to IShellFolder (not IShellFolder2), the crash does not happen. Does IShellFolder2 require some special

Access violation when using IShellFolder2

2020-09-08 Thread FreeSlave via Digitalmars-d-learn
Consider the following code: import core.sys.windows.windows; import core.sys.windows.shlobj; import core.sys.windows.wtypes; import std.exception; pragma(lib, "Ole32"); void main() { OleInitialize(null); scope(exit) OleUninitialize(); IShellFolder desktop; LPITEMIDLIST

Re: Vibe.d timer - change callback?

2020-08-27 Thread FreeSlave via Digitalmars-d-learn
On Tuesday, 25 August 2020 at 18:42:53 UTC, codic wrote: I'd like to be able to change the callback of a vibe.d Timer (eg created with http://vibe-core.dpldocs.info/v1.9.3/vibe.core.core.createTimer.html) after creation, something like: auto timer = createTimer(); timer.rearm(duration,

Re: How to get the element type of an array?

2020-08-25 Thread FreeSlave via Digitalmars-d-learn
On Tuesday, 25 August 2020 at 03:41:06 UTC, Jon Degenhardt wrote: What's the best way to get the element type of an array at compile time? Something like std.range.ElementType except that works on any array type. There is std.traits.ForeachType, but it wasn't clear if that was the right

Re: Returning range of inout objects from inout method

2020-07-25 Thread FreeSlave via Digitalmars-d-learn
On Saturday, 25 July 2020 at 14:19:15 UTC, Steven Schveighoffer wrote: The only way to do this without code duplication (but with generated code duplication) is to template the byAction function on the type of `this`: auto byAction(this This)() { /* same implementation */ } Note that this

Re: Result and Option types

2020-07-25 Thread FreeSlave via Digitalmars-d-learn
On Saturday, 25 July 2020 at 18:06:51 UTC, powerboat9 wrote: Does dlang have an analog to Result or Option types from rust? Standard library has std.typecons.Nullable https://dlang.org/phobos/std_typecons.html#Nullable Note that objects are nullable by themselves as classes are reference

Returning range of inout objects from inout method

2020-07-25 Thread FreeSlave via Digitalmars-d-learn
I want to be able to return a range of const objects from the const object and a range mutable objects from the mutable object. inout comes to mind, but not applicable in this case, because inout must be applied to the return type as whole, which does not make much sense for the range.

Re: std.process - avoid interaction with parent shell

2020-07-20 Thread FreeSlave via Digitalmars-d-learn
On Monday, 20 July 2020 at 20:55:52 UTC, Steven Schveighoffer wrote: I don't want any user interaction. Occasionally, I get a repository that no longer exists (404). Then git comes up and asks for a username/password. I want it to just fail. Apparently git has no option to be

Redundant function calls in filtered joined range

2020-07-18 Thread FreeSlave via Digitalmars-d-learn
Consider the following code. It counts the number of subdirectories in directories provided via commandline args. import std.stdio; import std.algorithm; import std.file; import std.range; import std.exception; @trusted bool isDirNothrow(string dir) nothrow { bool ok;

Re: what am I missing here with that working dir?

2019-03-16 Thread FreeSlave via Digitalmars-d-learn
On Friday, 15 March 2019 at 21:48:50 UTC, DFTW wrote: What am I missing here? Maybe the terminal and your utility you run wkhtmltopdf from have different environment?

Re: std.process: spawnProcess

2018-09-08 Thread FreeSlave via Digitalmars-d-learn
On Friday, 7 September 2018 at 16:44:09 UTC, Russel Winder wrote: I guess this might work on Windows, but I am on Linux and OSX, so I'll have to try another route. On Posix systems you may try using SIGCHLD handler. Google for exact examples.

Re: std.process: spawnProcess

2018-09-08 Thread FreeSlave via Digitalmars-d-learn
On Friday, 7 September 2018 at 14:36:42 UTC, Russel Winder wrote: From what I can see, processes created with std.process: spawnProcess are not terminated when the creating process terminates, i.e. it seems Config.detached is the default for these process. No, detached is not default. By

Re: Convert path to file system path on windows

2018-06-21 Thread FreeSlave via Digitalmars-d-learn
On Thursday, 21 June 2018 at 18:46:05 UTC, Dr.No wrote: How can I do that with D? In C# you can do that: var filename = @"C:\path\to\my\file.txt"; var file = new Uri(filename).AbsoluteUri; // file is "file:///C:/path/to/my/file.txt" How can I do that in D? import std.stdio; import

Re: Idiomatic way to add examples to dub package

2018-04-28 Thread FreeSlave via Digitalmars-d-learn
On Friday, 27 April 2018 at 12:37:04 UTC, Basile B. wrote: On Thursday, 26 April 2018 at 18:16:01 UTC, FreeSlave wrote: Most dub packages are libraries and should provide runnable examples. What's the current idiomatic way to add examples? IMO the most simple way (and the best too) is to put

Idiomatic way to add examples to dub package

2018-04-26 Thread FreeSlave via Digitalmars-d-learn
Most dub packages are libraries and should provide runnable examples. What's the current idiomatic way to add examples? I used sub-packages with dependency on the library and "*" as version and running them as dub run :examplename Now I've noticed vibed uses a different scheme - examples are

Re: Disk space used and free size of a Network share folder in Windows

2018-02-14 Thread FreeSlave via Digitalmars-d-learn
On Wednesday, 14 February 2018 at 15:24:42 UTC, Vino wrote: On Wednesday, 14 February 2018 at 12:29:13 UTC, rikki cattermole wrote: [...] Hi Rikki, Wouldn't this be easy to use with std.process: execute package and calling wmic.exe, the only problem is i am not sure hot to get the out

Re: Check whether a file is empty.

2017-12-09 Thread FreeSlave via Digitalmars-d-learn
On Friday, 8 December 2017 at 19:13:20 UTC, vino wrote: Hi, The code is same just copy pasted the code form Windows 7 into Windows 2003 and executed, in Windows 7 the log file is of size 0 where as in windows 2003 the log file is of size 2 byte where the log file in both the server is

Re: Check whether a file is empty.

2017-12-08 Thread FreeSlave via Digitalmars-d-learn
On Friday, 8 December 2017 at 09:40:18 UTC, Vino wrote: Hi All, Request your help on how to check whether a given file is empty, I tried the getSize from std.file but no luck as in windows 7 is the file is empty the size of the file is 0 bytes but in Windows 2003 if the file is empty the

Re: Generating DDOX documentation

2017-10-20 Thread FreeSlave via Digitalmars-d-learn
On Friday, 20 October 2017 at 10:47:57 UTC, Andrew Edwards wrote: Given a documented source file (eg. process.d), I can generate the DDOC version of the documentation with the -D switch of DMD as such: $ dmd -Dfprocess.html process.d What do I modify on that line to get the DDOX version

Re: spawnProcess: Exit parent process without terminating child process

2017-08-26 Thread FreeSlave via Digitalmars-d-learn
On Friday, 25 August 2017 at 19:55:09 UTC, timvol wrote: Hi guys, I want execute a process. I know, I can execute a process using "spawnProcess" or "executeShell". But I want exit the parent. My code for testing purposes is the following: int main(string[] asArgs_p) { if (

Re: spawnProcess: Exit parent process without terminating child process

2017-08-26 Thread FreeSlave via Digitalmars-d-learn
On Friday, 25 August 2017 at 19:55:09 UTC, timvol wrote: Hi guys, I want execute a process. I know, I can execute a process using "spawnProcess" or "executeShell". But I want exit the parent. My code for testing purposes is the following: int main(string[] asArgs_p) { if (

Re: Atomicity of file-copying/moving

2017-05-16 Thread FreeSlave via Digitalmars-d-learn
On Tuesday, 16 May 2017 at 08:32:56 UTC, Nordlöw wrote: What's the status of atomicity of file-copying and -moving (renaming) using std.file on different platforms? Not sure about renaming but copying is not atomic on Posix because it does not handle interruption by signal. I opened issue

Re: Why File is exists in std.stdio and in std.file?

2017-04-25 Thread FreeSlave via Digitalmars-d-learn
On Tuesday, 25 April 2017 at 07:05:51 UTC, Suliman wrote: Just interesting. Is there any rational reasons for this decision? There's no File in std.file. It's located in std.stdio. std.stdio and std.file are different modules. The first one has safe wrappers around stdio.h from C library, the

Re: Cleaning up Dub/Dmd builds

2017-04-18 Thread FreeSlave via Digitalmars-d-learn
On Tuesday, 18 April 2017 at 17:58:32 UTC, WhatMeWorry wrote: On Tuesday, 18 April 2017 at 15:15:47 UTC, Stanislav Blinov wrote: On Tuesday, 18 April 2017 at 15:07:27 UTC, WhatMeWorry wrote: When I try to upload these files to my new repo, GitHub (rightfully so) complains that I have too many

Re: Interfacing C++ to D

2017-04-02 Thread FreeSlave via Digitalmars-d-learn
On Sunday, 2 April 2017 at 16:03:51 UTC, FreeSlave wrote: On Sunday, 2 April 2017 at 16:02:06 UTC, FreeSlave wrote: On Sunday, 2 April 2017 at 09:58:19 UTC, ANtlord wrote: [...] Now I see. 'Using C++ Classes From D' crashes for me too. It also returns the wrong value from 'field' method.

Re: Interfacing C++ to D

2017-04-02 Thread FreeSlave via Digitalmars-d-learn
On Sunday, 2 April 2017 at 16:02:06 UTC, FreeSlave wrote: On Sunday, 2 April 2017 at 09:58:19 UTC, ANtlord wrote: On Saturday, 1 April 2017 at 16:39:28 UTC, FreeSlave wrote: This page has many examples. Which exactly do you try to run and how do you build it? Which compilers, OS? My bad.

Re: Interfacing C++ to D

2017-04-02 Thread FreeSlave via Digitalmars-d-learn
On Sunday, 2 April 2017 at 09:58:19 UTC, ANtlord wrote: On Saturday, 1 April 2017 at 16:39:28 UTC, FreeSlave wrote: This page has many examples. Which exactly do you try to run and how do you build it? Which compilers, OS? My bad. I've tested example under caption Using C++ Classes From D. I

Re: Interfacing C++ to D

2017-04-01 Thread FreeSlave via Digitalmars-d-learn
On Saturday, 1 April 2017 at 07:37:25 UTC, ANtlord wrote: Hello! Can somebody give a relevant example shows how to use C++ classes in D? I've used the exmaple from https://dlang.org/spec/cpp_interface.html but I get a segmentation fault as result of D application. My application shows

Re: Cannot spawn process: npm start

2016-10-04 Thread FreeSlave via Digitalmars-d-learn
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

Re: Cannot spawn process: npm start

2016-10-04 Thread FreeSlave via Digitalmars-d-learn
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

Re: Get program stats at run time

2016-07-01 Thread FreeSlave via Digitalmars-d-learn
On Thursday, 30 June 2016 at 21:56:57 UTC, Special opOps wrote: How can I get the program stats at run time such as minimum and maximum amount of memory and cpu used, cpu architecture, os, etc? OS is compile-time constant. http://dlang.org/phobos/std_system.html#.os Or do you look for

Re: Recommended coding convention for combining unix and windows code ?

2016-06-07 Thread FreeSlave via Digitalmars-d-learn
On Tuesday, 7 June 2016 at 15:33:57 UTC, chmike wrote: Hello I'm writing some code that I want to be portable across Posix and Windows. What is the recommended code convention for such type of code ? 80% of the class implementation is the same for both OS. Should I write the following and

Re: What's wrong with my usage of std.algorithm.map in this code example?

2016-05-25 Thread FreeSlave via Digitalmars-d-learn
On Tuesday, 24 May 2016 at 20:03:14 UTC, pineapple wrote: I would've expected this to work, but instead I get a compile error. Is my syntax wrong? Is this just not a case that map can handle, and I should be doing something else? import std.algorithm : map; import std.conv : to;

Linking to library dependent on Objective-C functions

2016-04-30 Thread FreeSlave via Digitalmars-d-learn
I have two files. The one has Objective-C functions and interfaces declarations written in D. Another file is main app and it imports the first and uses its functions. Imported file: http://codepad.org/jqdBb6sh Main file: http://codepad.org/0gKBqKxi When I compile them in one command it run

Re: "inline" conversion of array to immutable

2016-04-22 Thread FreeSlave via Digitalmars-d-learn
On Friday, 22 April 2016 at 11:07:47 UTC, Jeff Thompson wrote: On Friday, 22 April 2016 at 09:40:14 UTC, FreeSlave wrote: On Friday, 22 April 2016 at 09:25:32 UTC, Jeff Thompson wrote: Hello. The following code compiles OK where func creates a mutable array and main assigns it to an immutable

Re: "inline" conversion of array to immutable

2016-04-22 Thread FreeSlave via Digitalmars-d-learn
On Friday, 22 April 2016 at 09:25:32 UTC, Jeff Thompson wrote: Hello. The following code compiles OK where func creates a mutable array and main assigns it to an immutable variable: [...] Probably this is what you look for http://dlang.org/phobos/std_exception.html#.assumeUnique

Is it legal to use std.windows modules?

2016-04-08 Thread FreeSlave via Digitalmars-d-learn
std.windows.syserror and others have documentation comments, but they are not listed in online documentation on dlang.org. Is it ok to use functions and classes from this modules in D applications?

Re: Can D interface with Free Pascal?

2016-01-28 Thread FreeSlave via Digitalmars-d-learn
On Thursday, 28 January 2016 at 04:26:26 UTC, Taylor Hillegeist wrote: Just curious... I had a thought that perhaps since Objective C was a replacement for Pascal on the mac. that they might have the same interface. but I'm not savvy enough with fpc to figure out how to try it. Not directly.

Re: Distribution of D apps

2016-01-21 Thread FreeSlave via Digitalmars-d-learn
On Thursday, 21 January 2016 at 13:26:15 UTC, W.J. wrote: On Wednesday, 20 January 2016 at 16:01:11 UTC, Dibyendu Majumdar wrote: Hi, I am trying to understand the options for distributing a D app to users. My assumption is that only the shared libraries and binaries need to be distributed,

assumeSorted can't access private function when compiling with -debug

2016-01-09 Thread FreeSlave via Digitalmars-d-learn
Here's code: private { import std.algorithm; import std.range; import std.typecons; alias Tuple!(int, string) Data; } private bool myCmp(Data a, Data b) { return a[0] < b[0]; } auto bar() { return [Data(1, "one"), Data(2, "two")].assumeSorted!myCmp; } void main() {

Re: Regression?

2015-09-08 Thread FreeSlave via Digitalmars-d-learn
On Tuesday, 8 September 2015 at 04:04:16 UTC, Sebastiaan Koppe wrote: Fixed it by changing into: ``` import std.conv : text; string json = File("../languages.json","r").byLineCopy().joiner.text; auto ls = json.parseJSON(); ``` Why would you read file by line and then merge

Using dub configurations with libraries

2015-09-07 Thread FreeSlave via Digitalmars-d-learn
Let's say I have two dub packages: A and B. A is a library. B is library or application (does not matter) and depends on A. A has several configurations in dub.json. How to build the B package that way it will use non-default configuration of A?

Re: Are there any Phobos functions to check file permissions on Windows and Posix?

2015-09-07 Thread FreeSlave via Digitalmars-d-learn
On Sunday, 6 September 2015 at 23:05:29 UTC, Jonathan M Davis wrote: http://dlang.org/phobos/std_file.html#.getAttributes will get you all of the file attributes for a file, though you'll have to look at the Windows and POSIX documentation to know how to interpret that. - Jonathan M Davis

Re: Why ElementType!(char[3]) == dchar instead of char?

2015-09-02 Thread FreeSlave via Digitalmars-d-learn
On Wednesday, 2 September 2015 at 05:00:42 UTC, drug wrote: 02.09.2015 00:08, Jonathan M Davis via Digitalmars-d-learn пишет: On Tuesday, September 01, 2015 20:05:18 drug via Digitalmars-d-learn wrote: My case is I don't know what type user will be using, because I write a library. What's the

Re: Decrease number of front evaluations

2015-08-26 Thread FreeSlave via Digitalmars-d-learn
On Wednesday, 26 August 2015 at 08:30:04 UTC, Yazan D wrote: On Wed, 26 Aug 2015 08:27:05 +, FreeSlave wrote: Are there ways to fix this? Should I consider writing my own range type probably? Check http://dlang.org/phobos/std_algorithm_iteration.html#.cache I tried it. It can help

Decrease number of front evaluations

2015-08-26 Thread FreeSlave via Digitalmars-d-learn
Example: import std.stdio; import std.algorithm; import std.path; import std.file; import std.exception; import std.getopt; import std.array; import std.range; auto algo(string fileName, string[] dirs, string[] extensions) { return dirs.filter!(delegate(dir) { bool ok;

Re: A couple questions about a simple project

2015-08-17 Thread FreeSlave via Digitalmars-d-learn
On Monday, 17 August 2015 at 15:05:56 UTC, Andre Polykanine wrote: Hi everyone, I'm new to D (I'm learning it by reading the great online book by Ali Çehreli - thank you very much for it, sir!), and, more than that, programming is my hobby, so please bear with me if I'm asking stupid

Re: How to provide this arg or functor for algorithm?

2015-08-16 Thread FreeSlave via Digitalmars-d-learn
On Sunday, 16 August 2015 at 12:30:54 UTC, cym13 wrote: On Sunday, 16 August 2015 at 11:53:42 UTC, FreeSlave wrote: [...] Ok, so as my lambda proposition obviously doesn't work, here is one way that does using a templated function. There may be a way to make it shorter, I don't know.

How to provide this arg or functor for algorithm?

2015-08-16 Thread FreeSlave via Digitalmars-d-learn
Let's say I want to map some range using some context. The obvious way is to do: uint[3] arr = [1,2,3]; uint context = 2; auto r = arr[].map!(delegate(value) { return value * context; }); The problem is that this allocates delegate, so it can't be used in @nogc code. What I want to do might

Re: How to provide this arg or functor for algorithm?

2015-08-16 Thread FreeSlave via Digitalmars-d-learn
On Sunday, 16 August 2015 at 16:23:05 UTC, FreeSlave wrote: On Sunday, 16 August 2015 at 15:29:10 UTC, Ali Çehreli wrote: On 08/16/2015 04:53 AM, FreeSlave wrote: The problem is that this allocates delegate, so it can't be used in @nogc code. Would constructing the delegate by setting its

Re: How to provide this arg or functor for algorithm?

2015-08-16 Thread FreeSlave via Digitalmars-d-learn
On Sunday, 16 August 2015 at 15:29:10 UTC, Ali Çehreli wrote: On 08/16/2015 04:53 AM, FreeSlave wrote: The problem is that this allocates delegate, so it can't be used in @nogc code. Would constructing the delegate by setting its .funcptr and .ptr properties work in this case? You can have

Re: Environment variable for application storage under OSX ?

2015-07-17 Thread FreeSlave via Digitalmars-d-learn
On Thursday, 16 July 2015 at 21:12:05 UTC, anonymous wrote: I have the following code, working under Win and Linux: --- import std.process: environment; immutable string p; static this() { version(Win32) p = environment.get(APPDATA); version(linux) p = /home/ ~ environment.get(USER);

Re: Environment variable for application storage under OSX ?

2015-07-17 Thread FreeSlave via Digitalmars-d-learn
On Friday, 17 July 2015 at 07:33:43 UTC, Anonymous wrote: On Friday, 17 July 2015 at 07:14:24 UTC, FreeSlave wrote: On Thursday, 16 July 2015 at 21:12:05 UTC, anonymous wrote: I have the following code, working under Win and Linux: --- import std.process: environment; immutable string p;

Re: linking external libs

2015-07-02 Thread FreeSlave via Digitalmars-d-learn
On Thursday, 2 July 2015 at 12:47:52 UTC, Nicholas Wilson wrote: On Thursday, 2 July 2015 at 12:19:06 UTC, Steven Schveighoffer wrote: On 7/2/15 8:10 AM, Nicholas Wilson wrote: [...] Try dmd -v, it will tell you the link line. Then you can try it yourself to see how to get it to work. I

Re: Calling a cpp function from d

2015-06-16 Thread FreeSlave via Digitalmars-d-learn
On Tuesday, 16 June 2015 at 12:26:45 UTC, C2D wrote: Hi, I encountered the following error: Error: function files.SHGetFolderPath (void* hwndOwner, int nFolder, void* hToken, uint dwFlags, char* pszPath) is not callable using argument types (typeof(null), int, typeof(null), int,

Re: Calling a cpp function from d

2015-06-16 Thread FreeSlave via Digitalmars-d-learn
On Tuesday, 16 June 2015 at 13:31:47 UTC, FreeSlave wrote: Also you may want to take a look at my library [1] where I use SHGetSpecialFolderPath (I know, it's deprecated, but it still works, so why not. I don't really need to bother with access tokens here). Note that I load shell32

Re: What is a mutable method?

2015-05-22 Thread FreeSlave via Digitalmars-d-learn
On Friday, 22 May 2015 at 12:12:46 UTC, tcak wrote: I know there is mutable variables, but what is a mutable method? Error message says mutable method project.mariadb.connector.ver2p1.resultset.ResultSetColumn.info is not callable using a const object. The method that can change the state

Re: Linking C++ standard library works with GDC... but not DMD. (Linux)

2015-04-16 Thread FreeSlave via Digitalmars-d-learn
On Thursday, 16 April 2015 at 08:51:15 UTC, TheGag96 wrote: Hi, I've got this project that requires me to link into a C++ backend. It works just fine when using GDC: gdc *.d [client libraries] However, this command using DMD does not work: dmd -L-lstdc++ *.d [client libraries] I still get

Re: stdout redirect

2015-04-12 Thread FreeSlave via Digitalmars-d-learn
On Sunday, 12 April 2015 at 04:39:06 UTC, Philip Stuckey wrote: why not: import std.stdio; stdout = File(args[4], w+); stderr = File(args[4], w+); It just replaces the object, not redirects output. E.g. if you use printf somewhere it will use stdout, not file.

Re: Binary search in structs

2015-04-06 Thread FreeSlave via Digitalmars-d-learn
I think I found solution using opBinaryRight import std.range; struct S { int i; string s; int opCmp(int i) { return this.i - i; } int opCmp(ref const S s) { return this.i - s.i; } int opBinaryRight(string op)(int i) if (op == ) { return i

Binary search in structs

2015-04-05 Thread FreeSlave via Digitalmars-d-learn
I have array of structs sorted by specific field. How can I perform binary search using this field as a key? Currently I ended up with this, but it gives error: struct S { int i; string s; } import std.range; void main(string [] args) { S[] structs = [{1,hello}, {2,world}, {3,

Re: Binary search in structs

2015-04-05 Thread FreeSlave via Digitalmars-d-learn
On Sunday, 5 April 2015 at 23:15:04 UTC, w0rp wrote: On Sunday, 5 April 2015 at 23:06:27 UTC, FreeSlave wrote: I have array of structs sorted by specific field. How can I perform binary search using this field as a key? Currently I ended up with this, but it gives error: struct S { int i;

Re: Loading Symbols from Loaded Libraries

2014-09-01 Thread FreeSlave via Digitalmars-d-learn
On Monday, 1 September 2014 at 13:31:32 UTC, Matt wrote: If I were to use Runtime.loadLibrary(), it claims to merge any D GC in the shared lib with the current process' GC. Do I need to version away symbol loading code for each platform? Or is there already code in Phobos that allows us to do

Re: struct or class

2014-08-24 Thread FreeSlave via Digitalmars-d-learn
On Sunday, 24 August 2014 at 11:56:44 UTC, nikki wrote: I come from languages that don't offer structs, I have this json load function that has to keep some data and intuitively I've written a struct, I've read about the differences, heap vs stack, value vs reference, but know I think i am

Re: Crash writing and reading back class instance address to void*

2014-08-18 Thread FreeSlave via Digitalmars-d-learn
On Monday, 18 August 2014 at 10:07:30 UTC, Remi Thebault wrote: Hi Starting to use GtkD TreeModel, I write an instance of an abstract class to TreeIter.userData. When reading back the void pointer and casting to my abstract class leads to crash when instance is used (Task is the abstract

Re: extern (c++) std::function?

2014-08-15 Thread FreeSlave via Digitalmars-d-learn
On Friday, 15 August 2014 at 03:10:43 UTC, Etienne Cimon wrote: I'm looking into making a binding for the C++ API called Botan, and the constructors in it take a std::function. I'm wondering if there's a D equivalent for this binding to work out, or if I have to make a C++ wrapper as well?

Re: pointer array?

2014-07-31 Thread FreeSlave via Digitalmars-d-learn
On Wednesday, 30 July 2014 at 20:51:25 UTC, Daniel Kozak via Digitalmars-d-learn wrote: V Wed, 30 Jul 2014 14:33:51 + seany via Digitalmars-d-learn digitalmars-d-learn@puremagic.com napsáno: In Ali's excllent book, somehow one thing has escaped my attention, and that it the mentioning of

Re: Split class declaration and definition

2014-07-31 Thread FreeSlave via Digitalmars-d-learn
On Thursday, 31 July 2014 at 11:34:38 UTC, Kozzi11 wrote: Is possible to somehow split class declaration and definition. I mean something like this: class C { void hello(); // just prototype } class C { void hello() { //actual code } } or something like this void

Re: Get the default hash function.

2014-07-31 Thread FreeSlave via Digitalmars-d-learn
On Thursday, 31 July 2014 at 12:05:53 UTC, francesco cattoglio wrote: Really simple question: how do I get the compiler-generated hash function for a given type? For example: Struct S { int i; } can be used in an associative array. That means the compiler generates a toHash function. Is

Re: Grabing C(++) stdout

2014-07-23 Thread FreeSlave via Digitalmars-d-learn
On Wednesday, 23 July 2014 at 15:35:59 UTC, Chris wrote: The C++ code does this: size_t fwrite ( const void * ptr, size_t size, size_t count, FILE * stream ); // stream is stdout and text appears in the console (a string). I don't how to grab the text that is written to console. I might

Re: fork/waitpid and std.concurrency.spawn

2014-07-22 Thread FreeSlave via Digitalmars-d-learn
On Tuesday, 22 July 2014 at 07:58:50 UTC, Puming wrote: Is there a fork()/wait() API similar to std.concurrency spawn()? The best thing I've got so far is module core.sys.posix.unistd.fork(), but it seems to only work in posix. Is there a unified API for process level concurrency? ideally

Re: How to know whether a file's encoding is ansi or utf8?

2014-07-22 Thread FreeSlave via Digitalmars-d-learn
Note that BOMs are optional and may be not presented in Unicode file. Also presence of leading bytes which look BOM does not necessarily mean that file is encoded in some kind of Unicode.

Re: fork/waitpid and std.concurrency.spawn

2014-07-22 Thread FreeSlave via Digitalmars-d-learn
On Tuesday, 22 July 2014 at 14:26:05 UTC, Puming wrote: I've only found spawnProcess/spawnShell and the like, which executes a new command, but not a function pointer, like fork() and std.concurrency.spawn does. What is the function that does what I describe? On Tuesday, 22 July 2014 at

Re: DUB help plz

2014-07-03 Thread FreeSlave via Digitalmars-d-learn
Derelict contains bindings to other libraries, not these libraries themselves. dub downloads only these bindings, not original libraries (since they are written in C, not D, and not included in dub repositories). You should manually get necessary libraries and put them in folder where .exe

Re: close program by code

2014-06-26 Thread FreeSlave via Digitalmars-d-learn
On Thursday, 26 June 2014 at 09:05:23 UTC, pgtkda wrote: How can i close my application by code? Do you mean exit status? Just call exit function from C library. import std.c.stdlib; void main() { exit(0); }

Re: close program by code

2014-06-26 Thread FreeSlave via Digitalmars-d-learn
On Thursday, 26 June 2014 at 11:07:37 UTC, Rene Zwanenburg wrote: On Thursday, 26 June 2014 at 10:40:00 UTC, John Colvin wrote: On Thursday, 26 June 2014 at 09:58:50 UTC, FreeSlave wrote: On Thursday, 26 June 2014 at 09:05:23 UTC, pgtkda wrote: How can i close my application by code? Do you

Re: Passing around a list of differently typed functions

2014-06-23 Thread FreeSlave via Digitalmars-d-learn
On Monday, 23 June 2014 at 01:16:49 UTC, Evan Davis wrote: As the subject says, I would like to pass around an array of functions. The trick is, that the functions have different type signatures. Is there a way to put the two functions int foo(int a, int b); bool bar(bool a, bool b); into

dub --annotate option

2014-06-19 Thread FreeSlave via Digitalmars-d-learn
Dub has option called --annotate. It's described like this: Do not perform any action, just print what would be done I supposed it's something similar to -n option of Jam build system (I really like this feature). But dub's annotate prints nothing. So what is that? I have DUB version 0.9.21

Re: Subclass of Exception

2014-06-15 Thread FreeSlave via Digitalmars-d-learn
I don't think you always need documentation for all exception classes, since the most of them have the same interface. Usually it's worth to describe where is some exception able to be thrown from, not exception itself. And it's covered by function documentation, not by documentation of

Re: Subclass of Exception

2014-06-14 Thread FreeSlave via Digitalmars-d-learn
On Saturday, 14 June 2014 at 11:59:53 UTC, Paul wrote: One stupid question: in Python subclassing of Exception looks like: class MyError(Exception): pass but in D, if I'm right, we should write more code: class MyError : Exception { this(string msg) { super(msg); } } (without

Re: crt1.o: could not read symbols: Bad value

2014-06-11 Thread FreeSlave via Digitalmars-d-learn
It seems like you're trying to compile 64-bit code when you are on 32-bit system and you have 32-bit libphobos.

Re: crt1.o: could not read symbols: Bad value

2014-06-11 Thread FreeSlave via Digitalmars-d-learn
I conclude that because I have similar errors when trying to build 64-bit library on 32-bit system. /usr/bin/ld: /usr/lib/x86_64-linux-gnu/libphobos2.a(format_712_5b3.o): relocation R_X86_64_32 against `.rodata' can not be used when making a shared object; recompile with -fPIC

Re: crt1.o: could not read symbols: Bad value

2014-06-10 Thread FreeSlave via Digitalmars-d-learn
dmd has -shared option. Try it instead of -L-shared.

Re: Can't link libs?

2014-06-08 Thread FreeSlave via Digitalmars-d-learn
On Friday, 6 June 2014 at 16:33:27 UTC, Adam D. Ruppe wrote: When you compile the final program, the library .d file needs to be available too, either in the folder based on its name or passed straight to dmd explicitly. Despite the presence of the .lib file, the .d file is still needed so

Re: why can't I call const methods on shared objects?

2014-05-11 Thread FreeSlave via Digitalmars-d-learn
On Sunday, 11 May 2014 at 07:31:10 UTC, FreeSlave wrote: On Friday, 9 May 2014 at 21:42:14 UTC, Vlad Levenfeld wrote: Is this still the case if the method is const or pure? Const methods still require synchronization, because other threads may change some data, needed by const method while

Re: why can't I call const methods on shared objects?

2014-05-11 Thread FreeSlave via Digitalmars-d-learn
On Friday, 9 May 2014 at 21:42:14 UTC, Vlad Levenfeld wrote: Is this still the case if the method is const or pure? Const methods still require synchronization, because other threads may change some data, needed by const method while method is executed, and then you may get wrong results.

Re: Configuring Phobos from the 1-click installer

2014-05-11 Thread FreeSlave via Digitalmars-d-learn
On Sunday, 11 May 2014 at 05:34:38 UTC, Moses wrote: On Sunday, 11 May 2014 at 04:33:24 UTC, Ali Çehreli wrote: On 05/10/2014 07:12 PM, Moses wrote: After using the 1-click Ubuntu installer, I'm having trouble figuring out how to import standard library functions for Phobos. I get the

Re: Temporary silence output (stdout)

2014-05-11 Thread FreeSlave via Digitalmars-d-learn
On Saturday, 10 May 2014 at 20:24:50 UTC, MarisaLovesUsAll wrote: Hi! I sometimes got a useless messages in stdout from SDL_Image library, and I want to temporary silence it. How do I do? You can temporary redirect output to file. Example (on C): #include stdio.h #include unistd.h #include

Re: Messy code in console

2014-05-11 Thread FreeSlave via Digitalmars-d-learn
On Sunday, 11 May 2014 at 07:43:07 UTC, Kagamin wrote: Known bug https://issues.dlang.org/show_bug.cgi?id=2742 It's not bug. Write-functions are designed to output text to stdout, and it's issue of programmer to make sure that expected acceptor can interpret them properly. Note that stdout

Re: Get and set terminal size

2014-04-19 Thread FreeSlave via Digitalmars-d-learn
What are compiler and platform do you use? Probably you are trying to link with 64-bit library while being on 32-bit OS (or vice versa) It works fine on my 32-bit Debian with ldc2 and dmd.

  1   2   >