Re: Can't pass [] to extern function object method

2020-11-18 Thread frame via Digitalmars-d-learn
On Monday, 16 November 2020 at 22:22:42 UTC, frame wrote: On Monday, 16 November 2020 at 21:58:44 UTC, Jack wrote: What is the function prototype like and how are you declaring that struct? The struct is very simple, it contains: I found the "bug". It was caused by a debug {} statement

Re: Calling function within class.

2020-11-18 Thread Vino via Digitalmars-d-learn
On Wednesday, 18 November 2020 at 16:53:44 UTC, frame wrote: On Wednesday, 18 November 2020 at 15:01:53 UTC, Vino wrote: Hi All, Request your help on how to call a function(listFile) from another function(getFilelist) within the same class(GetDirlist), below is an example code. I think

Re: Calling function within class.

2020-11-18 Thread Vino via Digitalmars-d-learn
On Wednesday, 18 November 2020 at 18:24:59 UTC, frame wrote: On Wednesday, 18 November 2020 at 17:55:36 UTC, Vino wrote: I made the changes as below , still not working auto fltask = task!listFile(st); to auto fltask = task!({listFile(st);})(this).executeInNewThread(); The syntax is

Re: Calling function within class.

2020-11-18 Thread frame via Digitalmars-d-learn
On Wednesday, 18 November 2020 at 15:01:53 UTC, Vino wrote: Hi All, Request your help on how to call a function(listFile) from another function(getFilelist) within the same class(GetDirlist), below is an example code. I think it's basically the same issue like that recently opened topic:

Re: Calling function within class.

2020-11-18 Thread frame via Digitalmars-d-learn
On Wednesday, 18 November 2020 at 17:55:36 UTC, Vino wrote: I made the changes as below , still not working auto fltask = task!listFile(st); to auto fltask = task!({listFile(st);})(this).executeInNewThread(); The syntax is just wrong: auto fltask =

Calling function within class.

2020-11-18 Thread Vino via Digitalmars-d-learn
Hi All, Request your help on how to call a function(listFile) from another function(getFilelist) within the same class(GetDirlist), below is an example code. Code: class GetDirlist { @system private auto listFile(immutable string st) { auto fl = execute(["ls","-l"]); enforce(fl.status

Re: Executing AWS commands

2020-11-18 Thread Vino via Digitalmars-d-learn
On Tuesday, 17 November 2020 at 21:08:21 UTC, Paul Backus wrote: On Tuesday, 17 November 2020 at 19:07:42 UTC, Vino wrote: auto pid = execute(["/usr/bin/aws ec2 describe-images --filters 'Name=state,Values=available' --query 'Images[*].[ImageId]'"]); [...] auto pid = execute(["/usr/bin/aws

Re: betterC question

2020-11-18 Thread Dibyendu Majumdar via Digitalmars-d-learn
On Thursday, 19 November 2020 at 00:08:59 UTC, Adam D. Ruppe wrote: On Thursday, 19 November 2020 at 00:07:12 UTC, Dibyendu Majumdar wrote: int function() fp = test; This tries to *call* the function test and assign its return value to fp. Really? why does it do that? You want to get

implementing default opCmp

2020-11-18 Thread Steven Schveighoffer via Digitalmars-d-learn
I have a struct like this: struct S { int x; int y; } and I want a default comparison. The problem is, that comparison doesn't have a default, and requires I implement opCmp. While this is useful for the compiler, there's no default I know of that is an easy one-liner. The truth is,

Re: implementing default opCmp

2020-11-18 Thread Paul Backus via Digitalmars-d-learn
On Wednesday, 18 November 2020 at 22:29:17 UTC, Steven Schveighoffer wrote: I have a struct like this: struct S { int x; int y; } and I want a default comparison. The problem is, that comparison doesn't have a default, and requires I implement opCmp. While this is useful for the

Re: Git-repo-root relative path

2020-11-18 Thread Petar via Digitalmars-d-learn
On Monday, 16 November 2020 at 10:21:27 UTC, Per Nordlöw wrote: I need a function that gets the relative path of a file in a Git-repo and preferrably also its status. I'm not sure I understand the question. I have written two programs, hopefully one of them does what you want :D Either via

betterC question

2020-11-18 Thread Dibyendu Majumdar via Digitalmars-d-learn
I have simple test program: import core.stdc.stdio : printf; void test() { int* a; printf("a == null %d\n", a == null); } int function() fp = test; extern (C) void main() { fp(); } Why do I get: \d\dmd-2.092.1\windows\bin64\dmd.exe -betterC tests.d tests.d(5): Error: printf

Re: betterC question

2020-11-18 Thread Adam D. Ruppe via Digitalmars-d-learn
On Thursday, 19 November 2020 at 00:07:12 UTC, Dibyendu Majumdar wrote: int function() fp = test; This tries to *call* the function test and assign its return value to fp. You want to get the address.

Re: betterC question

2020-11-18 Thread Dibyendu Majumdar via Digitalmars-d-learn
On Thursday, 19 November 2020 at 00:18:54 UTC, rikki cattermole wrote: You don't need the brackets to call a function (and with a little help from UFCS): void main() { import std.stdio; "Hello!".writeln; writeln; } Okay thanks. Bad idea IMO.

Re: implementing default opCmp

2020-11-18 Thread ag0aep6g via Digitalmars-d-learn
On Wednesday, 18 November 2020 at 22:29:17 UTC, Steven Schveighoffer wrote: How do I do something really simple for opCmp? I tried this it didn't work: return this == other ? 0 : this.tupleof < other.tupleof ? -1 : 1; std.typecons.Tuple has opCmp. So this works: int opCmp(S other)

Re: Can't pass [] to extern function object method

2020-11-18 Thread Bastiaan Veelo via Digitalmars-d-learn
On Wednesday, 18 November 2020 at 10:50:12 UTC, frame wrote: I found the "bug". It was caused by a debug {} statement within a struct method. I assume that the debug symbol is just incompatible called from the DLL context. Were the DLL and main program built in different modes

Re: Calling function within class.

2020-11-18 Thread Ali Çehreli via Digitalmars-d-learn
On 11/18/20 11:25 AM, Vino wrote: > why is this > so complicated in D where as in PHP it is simple like below > > PHP Code: > class PHPclass { >function test1 ($st) { return $st; } >function test2 () { return $this->test1("Test"); } > } > > $obj = new PHPclass(); >

Re: Calling function within class.

2020-11-18 Thread Ali Çehreli via Digitalmars-d-learn
On 11/18/20 7:01 AM, Vino wrote: >Request your help on how to call a function(listFile) from another > function(getFilelist) within the same class(GetDirlist), below is an > example code. That code looks unnecessarily complex to me. First of all, parallel() already executes the loop body

spurious conversion to int

2020-11-18 Thread Richard Delorme via Digitalmars-d-learn
The following code // module foo; static immutable ubyte [2] t = [2, 3]; ubyte g(const ubyte a) { return cast (ubyte) (a + 1); } void f(const ubyte a, const ubyte b, const int i) { ubyte [2] c = a > b ? [a.g(), b.g()] : [b, a]; // compile

Re: betterC question

2020-11-18 Thread rikki cattermole via Digitalmars-d-learn
On 19/11/2020 1:11 PM, Dibyendu Majumdar wrote: On Thursday, 19 November 2020 at 00:08:59 UTC, Adam D. Ruppe wrote: On Thursday, 19 November 2020 at 00:07:12 UTC, Dibyendu Majumdar wrote: int function() fp = test; This tries to *call* the function test and assign its return value to fp.

Re: betterC question

2020-11-18 Thread Dibyendu Majumdar via Digitalmars-d-learn
On Thursday, 19 November 2020 at 00:08:59 UTC, Adam D. Ruppe wrote: On Thursday, 19 November 2020 at 00:07:12 UTC, Dibyendu Majumdar wrote: int function() fp = test; You want to get the address. Okay that works. Thanks

Function Pointer Not Working

2020-11-18 Thread Marcone via Digitalmars-d-learn
// Function threadingw() void threadingw(HWND hwn, void delegate() fun) nothrow { try { // Function _fun() extern(Windows) uint _fun(void * arg){ (*(cast(void delegate()*) arg))(); // Do not show "Hello World!" :(

Re: Function Pointer Not Working

2020-11-18 Thread Vladimir Panteleev via Digitalmars-d-learn
On Thursday, 19 November 2020 at 04:23:13 UTC, Marcone wrote: // Function threadingw() void threadingw(HWND hwn, void delegate() fun) nothrow { try { // Function _fun() extern(Windows) uint _fun(void * arg){ (*(cast(void delegate()*)

Re: betterC question

2020-11-18 Thread Mike Parker via Digitalmars-d-learn
On Thursday, 19 November 2020 at 00:20:50 UTC, Dibyendu Majumdar wrote: On Thursday, 19 November 2020 at 00:18:54 UTC, rikki cattermole wrote: You don't need the brackets to call a function (and with a little help from UFCS): void main() { import std.stdio;