How to call one static method from another?

2016-06-13 Thread Konstantin Kutsevalov via Digitalmars-d-learn

Hi,

Just can't found information about "this" for static methods.
Can anyone explain how to call current class from static methods?

For example I have some class and I need to call some static 
method of current class from another static method. I don't like 
to use full class name for that, but I didn't know what need to 
use instead of "this".


I sure it must be something like "self". :(


Re: How to call one static method from another?

2016-06-14 Thread Konstantin Kutsevalov via Digitalmars-d-learn

May be my question was not enought clean...
this is example of code:

```
class ClassName {

public static void function method1()
{
// do something
// and now I need to call other static method
ClassName.method2(); // What I can use insted of full 
class name?

// Like "self.method2()"
}

public static void function method2()
{
//...
}
}
```


Re: How to call one static method from another?

2016-06-14 Thread Konstantin Kutsevalov via Digitalmars-d-learn

On Tuesday, 14 June 2016 at 07:35:36 UTC, Andrea Fontana wrote:
On Tuesday, 14 June 2016 at 07:20:47 UTC, Konstantin Kutsevalov 
wrote:

May be my question was not enought clean...
this is example of code:

```
class ClassName {

public static void function method1()
{
// do something
// and now I need to call other static method
ClassName.method2(); // What I can use insted of full 
class name?

// Like "self.method2()"
}

public static void function method2()
{
//...
}
}
```


Simply:
method2();

Anyway I guess you mean public static void method1() { } 
without "function"


Andrea


Yep, it's my mistake about "function" :)

Thanks!


How to get a screenshot?

2016-09-21 Thread Konstantin Kutsevalov via Digitalmars-d-learn

Hello everyone,

do anybody know how to get screenshot (for now in Linux only)? 
May be some library , examples?


Re: How to get a screenshot?

2016-09-21 Thread Konstantin Kutsevalov via Digitalmars-d-learn
On Wednesday, 21 September 2016 at 16:36:32 UTC, Adam D. Ruppe 
wrote:
On Wednesday, 21 September 2016 at 16:33:58 UTC, Konstantin 
Kutsevalov wrote:
do anybody know how to get screenshot (for now in Linux only)? 
May be some library , examples?


simplest might be to just call out to `shellExec("import 
-window root filename.png");` and it will write the file.


Hmm, that's good idea as fast solution. Thank you Adam.


Re: How to get a screenshot?

2016-09-22 Thread Konstantin Kutsevalov via Digitalmars-d-learn
On Thursday, 22 September 2016 at 16:09:23 UTC, Antonio Corbi 
wrote:
On Thursday, 22 September 2016 at 07:50:07 UTC, Antonio Corbi 
wrote:
Ok, took the time to translate it to D and created a github 
repo to clone. You can download and try it from: 
https://github.com/antoniocorbibellot/dsshot


Hope It helps you.
Antonio


Thank you Antonio, I'll try :)


Re: How to get a screenshot?

2016-09-25 Thread Konstantin Kutsevalov via Digitalmars-d-learn
On Thursday, 22 September 2016 at 16:09:23 UTC, Antonio Corbi 
wrote:


Ok, took the time to translate it to D and created a github 
repo to clone. You can download and try it from: 
https://github.com/antoniocorbibellot/dsshot


Hope It helps you.
Antonio



Hey!

It really works!

https://github.com/antoniocorbibellot/dsshot/blob/master/source/app.d

Thank you!




Re: How to get a screenshot?

2016-09-25 Thread Konstantin Kutsevalov via Digitalmars-d-learn

This is example:

```
import std.stdio;
import gtk.Main;
import gtk.MainWindow;
import gtk.VBox, gtk.Label, gtk.Button;
import gdk.Gdk;
import gdk.Window;
import gdk.Pixbuf;
private import stdlib = core.stdc.stdlib : exit;

int main(string[] args)
{
Main.init(args);
new ApMainWindow();
Main.run();
return 0;
}


class ApMainWindow : MainWindow
{
this()
{
super("Screen Capture");
setTitle("Screen Capture Example");
setDefaultSize(250, 120);
VBox box = new VBox(false, 2);
box.add(new Button("ScreenShot", &screenSave));
box.add(new Button("Exit", &exitProg));
add(box);
showAll();
}

void screenSave(Button button)
{
Window win = Window.getDefaultRootWindow();
int width = win.getWidth;
int height = win.getHeight;
Pixbuf screenshot = getFromWindow(win, 0, 0, width, height);
screenshot.savev("screenshot.png", "png", null, null);
}

void exitProg(Button button)
{
stdlib.exit(0);
}
}
```


Re: Easy sockets - don't exist yet?

2016-10-09 Thread Konstantin Kutsevalov via Digitalmars-d-learn

On Monday, 26 September 2016 at 23:40:10 UTC, Vincent wrote:

Hello, guys!

I was very surprised that module 'socketstream' was deprecated. 
Usually if something become obsolete, there is some perfect 
replacement! But my digging in Inet and forums gave nothing, 
but "outdated" examples with 'SocketStream' class. So first 
question is WHAT Phobos has to replace SocketStream?


Hello, I'm agree with your main question.

This looks very good http://dsfml.com/docs/sockets.html, but, 
there is no any answer for the question. Why 'socketstream' was 
deprecated when no any replacement modules? It looks strange, 
like you are removing feature from your app because his code old 
and don't write new code for same feature, and just say to users: 
no feature anymore, haha.


So anyone know the answer?



Re: Easy sockets - don't exist yet?

2016-10-10 Thread Konstantin Kutsevalov via Digitalmars-d-learn
On Monday, 10 October 2016 at 02:54:09 UTC, Jonathan M Davis 
wrote:
On Monday, October 10, 2016 01:43:54 Konstantin Kutsevalov via 
So, it's simply gone. But if someone wants to propose a 
replacement, they're certainly still free to do so.


- Jonathan M Davis


I see, thank you for answer


Re: Easy sockets - don't exist yet?

2016-10-10 Thread Konstantin Kutsevalov via Digitalmars-d-learn

On Monday, 10 October 2016 at 07:37:48 UTC, Bauss wrote:
Wrote some pretty simple sockets that you could use (Based on 
vibe.d though.)


https://github.com/bausshf/cheetah


Hi,

Yes I saw it, but not sure. Does it make sense to use vibe.d only 
for sockets. I mean, it like a web framework with many 
dependencies etc...


is there "this"?

2016-11-01 Thread Konstantin Kutsevalov via Digitalmars-d-learn

The question is simple.

Is there something like "this" word for classes?

For example:

```
class CLS {

int numberValue;

public this(numberValue)
{
// how can I put the local numberValue to class property?
// in some prog language I can do like:
// this.numberValue = numberValue;
}

}
```


Re: is there "this"?

2016-11-01 Thread Konstantin Kutsevalov via Digitalmars-d-learn
On Wednesday, 2 November 2016 at 02:20:43 UTC, rikki cattermole 
wrote:

On 02/11/2016 3:17 PM, Konstantin Kutsevalov wrote:

The question is simple.

Is there something like "this" word for classes?

For example:

```
class CLS {

int numberValue;

public this(numberValue)
{
// how can I put the local numberValue to class 
property?

// in some prog language I can do like:
// this.numberValue = numberValue;
}

}
```


You forgot an int in the arguments but otherwise that would 
work fine with your line uncommented.


yes I missed "int", but it's just an example.
so if I'll write "this.property = value" it will work?


Re: is there "this"?

2016-11-01 Thread Konstantin Kutsevalov via Digitalmars-d-learn
On Wednesday, 2 November 2016 at 02:33:10 UTC, Konstantin 
Kutsevalov wrote:
On Wednesday, 2 November 2016 at 02:20:43 UTC, rikki cattermole 
wrote:

On 02/11/2016 3:17 PM, Konstantin Kutsevalov wrote:

The question is simple.

Is there something like "this" word for classes?

For example:

```
class CLS {

int numberValue;

public this(numberValue)
{
// how can I put the local numberValue to class 
property?

// in some prog language I can do like:
// this.numberValue = numberValue;
}

}
```


You forgot an int in the arguments but otherwise that would 
work fine with your line uncommented.


yes I missed "int", but it's just an example.
so if I'll write "this.property = value" it will work?


I tested already and it really works, thank you.
I asked that because I tried once to use "this" in past but I got 
error. So I asked on some forum "how to get property of class?" 
and peoples said that I may use just a name of property. So I 
thought that there isn't "this" word.




system's "kill " signal

2016-11-04 Thread Konstantin Kutsevalov via Digitalmars-d-learn

Hi,

is there a way to catch system signal of "kill" command or 
"shutdown"?


PS: are there some other ways also to send signals to running a D 
application?


Re: is there "this"?

2016-11-04 Thread Konstantin Kutsevalov via Digitalmars-d-learn
On Thursday, 3 November 2016 at 13:40:11 UTC, Steven 
Schveighoffer wrote:

On 11/2/16 4:43 AM, Jonathan M Davis via Digitalmars-d-learn

In the case of the original post, however, you *need* to use 
this.value, as the parameter masks the member of the same name. 
Using 'this' removes ambiguity.


This is a typical pattern seen in many languages. Often the 
intuitive name of a member is the same name as you want for the 
parameter of the constructor.


-Steve


I'd like to use "this" because when I see something like 
"this.pumpurum = 10;" then I understand that "pumpurum" is 
property of class and not some local variable :)


Re: system's "kill " signal

2016-11-07 Thread Konstantin Kutsevalov via Digitalmars-d-learn

On Saturday, 5 November 2016 at 07:52:53 UTC, Basile B. wrote:

On Saturday, 5 November 2016 at 06:17:51 UTC, Basile B. wrote:
3rd option, from my Windows times I remember that people tend 
to use launchers
to handle the real application, i.e a process that launches the 
main process. Then the launcher can have a thread that checks 
the PID (like in "After Term..."). If SIGKILL isn't handled by 
a signal() callback then this could be an option.


Do you have to check if a server crashes or something like that 
?


not a system crash. just a signal of sistems shutdown or process 
kill.


Re: system's "kill " signal

2016-11-07 Thread Konstantin Kutsevalov via Digitalmars-d-learn
On Sunday, 6 November 2016 at 16:05:44 UTC, Konstantin Kutsevalov 
wrote:

On Saturday, 5 November 2016 at 07:52:53 UTC, Basile B. wrote:

On Saturday, 5 November 2016 at 06:17:51 UTC, Basile B. wrote:
3rd option, from my Windows times I remember that people tend 
to use launchers
to handle the real application, i.e a process that launches 
the main process. Then the launcher can have a thread that 
checks the PID (like in "After Term..."). If SIGKILL isn't 
handled by a signal() callback then this could be an option.


Do you have to check if a server crashes or something like 
that ?


not a system crash. just a signal of sistems shutdown or 
process kill.


*of system


Re: system's "kill " signal

2016-11-07 Thread Konstantin Kutsevalov via Digitalmars-d-learn

On Saturday, 5 November 2016 at 06:17:51 UTC, Basile B. wrote:
On Saturday, 5 November 2016 at 02:24:00 UTC, Konstantin 
Kutsevalov wrote:

Hi,

is there a way to catch system signal of "kill" command or 
"shutdown"?


During the Run-time:


You can register a signal callback, like in this sample (hit 
CTRL+C once running in a terminal):



After termination:
==

if (tryWait(PID)[0] == true) then the value carried by 
tryWait(PID)[1] will tell you if the process has exited because 
of a signal whatever it's, e.g SIGKILL, SIGTERM, SIGINT, ...


Thank you!


Thread (spawn) for object's method

2016-11-07 Thread Konstantin Kutsevalov via Digitalmars-d-learn

Is there a way to make new thread for class method?

E.g. I have some class and I need to run one of them method in 
new thread.


I found wxamples only with function...


Re: Thread (spawn) for object's method

2016-11-08 Thread Konstantin Kutsevalov via Digitalmars-d-learn

On Tuesday, 8 November 2016 at 06:40:32 UTC, Basile B. wrote:
On Monday, 7 November 2016 at 16:15:44 UTC, Konstantin 
Kutsevalov wrote:

Is there a way to make new thread for class method?

E.g. I have some class and I need to run one of them method in 
new thread.


I found wxamples only with function...



import core.thread;

class Foo
{
void method(){}
}

void main()
{
Foo foo = new Foo;
Thread t = new Thread(&foo.method);
}


oh, so simple... :) thank you!


Question about dsfml.system.err

2016-11-08 Thread Konstantin Kutsevalov via Digitalmars-d-learn
I need to see errors from dsfml.system.err, but it doesn't write 
to terminal as I expected.


The general problem is that I cannot listen any port by 
tcplistener. And listen method is:


Status accept(TcpSocket socket)
{
import dsfml.system.string;
Status toReturn = sfTcpListener_accept(sfPtr, socket.sfPtr);
err.write(dsfml.system.string.toString(sfErr_getOutput()));
return toReturn;
}

so, as you can see, there is "err.write". I need to see which 
error is wrining ro "err"...

Is it possible to redeclate "err" File() object?

:(


Re: Question about dsfml.system.err

2016-11-08 Thread Konstantin Kutsevalov via Digitalmars-d-learn

ADD:

I tried to open other stream in main()

```
...
import dsfml.system.err;

int main(string[] args)
{
err.open("errors.log", "a");
err.write("test\n");

}
...
```

but as can I see, that hasn't any effect for tcplistener module...


Re: Question about dsfml.system.err

2016-11-08 Thread Konstantin Kutsevalov via Digitalmars-d-learn
On Tuesday, 8 November 2016 at 16:34:04 UTC, Konstantin 
Kutsevalov wrote:

ADD:

I tried to open other stream in main()

```
...
import dsfml.system.err;

int main(string[] args)
{
err.open("errors.log", "a");
err.write("test\n");

}
...
```

but as can I see, that hasn't any effect for tcplistener 
module...


OK ... problem with tcplistener solved, just a code mistake. But 
the question is actual.


Re: Question about dsfml.system.err

2016-11-08 Thread Konstantin Kutsevalov via Digitalmars-d-learn
On Tuesday, 8 November 2016 at 19:00:15 UTC, Steven Schveighoffer 
wrote:

On 11/8/16 11:48 AM, Konstantin Kutsevalov wrote:
On Tuesday, 8 November 2016 at 16:34:04 UTC, Konstantin 
Kutsevalov wrote:

ADD:

I tried to open other stream in main()

```
...
import dsfml.system.err;

int main(string[] args)
{
err.open("errors.log", "a");
err.write("test\n");

}
...
```

but as can I see, that hasn't any effect for tcplistener 
module...


OK ... problem with tcplistener solved, just a code mistake. 
But the

question is actual.


I can honestly say, I don't know what dsfml is or any of the 
code you have posted.


-Steve


oh, it's ok because it's all work fine, I just was too 
inattentive.


Correct way to create singleton?

2016-11-10 Thread Konstantin Kutsevalov via Digitalmars-d-learn

Hi, what is a correct (and simple) way to create an singleton?

This is how I see that now:

```
class ApMessageRouter
{

static ApMessageRouter instance = null;


	private this() { }  // for disable constructor to use from 
outside



public ApMessageRouter getInstance()
{
if (this.instance is null) {
this.instance = new ApMessageRouter();
}
return this.instance;
}

}
```

Thank you.


Re: Correct way to create singleton?

2016-11-10 Thread Konstantin Kutsevalov via Digitalmars-d-learn

On Thursday, 10 November 2016 at 17:22:48 UTC, Anonymouse wrote:
On Thursday, 10 November 2016 at 17:17:51 UTC, Konstantin 
Kutsevalov wrote:

Hi, what is a correct (and simple) way to create an singleton?


https://wiki.dlang.org/Low-Lock_Singleton_Pattern


great!


How to correct share data between threads?

2016-11-19 Thread Konstantin Kutsevalov via Digitalmars-d-learn
I need to receiving data in main thread and send its to other 
thread for processing. There is a simple (but wrong) code for 
example.

What need I to change to make it correct?


```
import std.stdio, std.string, std.array, core.thread, 
std.datetime, std.conv;


int main() {
Pumpurum pp = new Pumpurum();
Thread ppt = new Thread(&pp.processingData);
ppt.start();
while(pp.waitData())
{
// some operations may be
}
writeln("finished main");
return 0;
}

class Pumpurum
{
private string[string] Data;

private string[string] Result;

private bool _quit = false;

private int _counter = 0;

bool waitData()
{
// waits for new data and adds to Data
string key;
		string line = readln(); // just for example, in real its will 
be data from several socket connections

if (line !is null) {
if (line == "quit\n") {
this._quit = true;
return false;
}
			key = Clock.currTime().toString() ~ " " ~ 
to!string(this._counter);

this.Data[key] = line; // adds new data to "Data"
}
return true;
}

void processingData()
{
string key, value;
while(!this._quit) {
if (this.Data.length > 0) {
// todo checks the "Data" for some data, processing its and 
saves a result to "Result"

foreach (key, value; this.Data) {
writeln(value); // some processing :)
this.Result[key] = value;
this.Data.remove(key);
}
}
}
writeln("finished processing");
}

}
```

Any advice may help. Thank you.


Re: How to correct share data between threads?

2016-11-20 Thread Konstantin Kutsevalov via Digitalmars-d-learn
On Saturday, 19 November 2016 at 19:04:12 UTC, Nicolas Gurrola 
wrote:
On Saturday, 19 November 2016 at 17:29:30 UTC, Konstantin 
Kutsevalov wrote:
I need to receiving data in main thread and send its to other 
thread for processing. There is a simple (but wrong) code for 
example.

What need I to change to make it correct?


```
import std.stdio, std.string, std.array, core.thread, 
std.datetime, std.conv;


int main() {
Pumpurum pp = new Pumpurum();
Thread ppt = new Thread(&pp.processingData);
ppt.start();
while(pp.waitData())
{
// some operations may be
}
writeln("finished main");
return 0;
}

class Pumpurum
{
private string[string] Data;

private string[string] Result;

private bool _quit = false;

private int _counter = 0;

bool waitData()
{
// waits for new data and adds to Data
string key;
		string line = readln(); // just for example, in real its 
will be data from several socket connections

if (line !is null) {
if (line == "quit\n") {
this._quit = true;
return false;
}
			key = Clock.currTime().toString() ~ " " ~ 
to!string(this._counter);

this.Data[key] = line; // adds new data to "Data"
}
return true;
}

void processingData()
{
string key, value;
while(!this._quit) {
if (this.Data.length > 0) {
// todo checks the "Data" for some data, processing its 
and saves a result to "Result"

foreach (key, value; this.Data) {
writeln(value); // some processing :)
this.Result[key] = value;
this.Data.remove(key);
}
}
}
writeln("finished processing");
}

}
```

Any advice may help. Thank you.


I'd recommend using std.concurrency or std.parallelism instead 
of core.thread, as they're higher level APIs. You probably want 
to check out std.parallelism first to see if it has what you 
need. Otherwise, the generic messaging API of std.concurrency 
should be easier to use than core.thread while still being very 
flexible.


Ok, thank you. But I cannot to find good example. May be you know 
some good article about it?