Re: Is this bug ? format %(%)

2021-04-07 Thread novice2 via Digitalmars-d-learn

On Wednesday, 7 April 2021 at 13:43:18 UTC, Paul Backus wrote:

So, you should change your code to

writefln("%-(%s, %)", s);


sorry i dont read docs so carefully
thanks


Re: Derived type

2021-04-01 Thread novice2 via Digitalmars-d-learn

thanks, i tried 2 variants:
```d
struct Tnew {TBase payload; alias payload this;}
```
```d
enum Tnew : Tbase {init = Tbase.init}
```

both works, but 1-st not allow "2 level" cast:
```d
struct Xptr {void* payload; alias payload this;} //Xptr based on 
void*
struct Xobj {Xptr payload; alias payload this;}  //Xobj based on  
Xptr

Xptr xptr = cast(Xptr) null; //OK
Xobj xobj = cast(Xobj) null; //ERROR
Xobj xobj = cast(Xobj) cast(Xptr) null;  //OK, needs both levels 
explitity

```
```d
enum Xptr : void* {init = (void*).init} //Xptr based on void*
enum Xobj : Xptr {init = Xptr.init} //Xobj based on  Xptr
Xptr xptr = cast(Xptr) null;//OK
Xobj xobj = cast(Xobj) null;//OK
```

so "enum" variant is better for me, thanks!


Re: Derived type

2021-03-30 Thread novice2 via Digitalmars-d-learn

My tries to make template for struct and alias this:

// variant 1
template Typedef(alias Tnew, Tbase)
{
  struct Tnew
  {
Tbase payload;
alias payload this;
  }
}

Typedef!(Xobj, void*);

void foo (Xobj obj) {}  //compiler Error: no identifier for 
declarator Typedef!(Xobj, void*)



// variant 2
mixin template Typedef(alias Tnew, Tbase)
{
  struct Tnew
  {
Tbase payload;
alias payload this;
  }
}

mixin Typedef!(Xobj, void*);  //compiler Error: undefined 
identifier Xobj





Re: Derived type

2021-03-30 Thread novice2 via Digitalmars-d-learn

On Tuesday, 30 March 2021 at 19:12:29 UTC, Ali Çehreli wrote:
"Derived type" is used in the context of object oriented 
programming at least in D


Sorry, i use wrong termin.
I just want create new type Tnew, based on exist type Tbase.
Tnew have same allowed values, same properties, same allowed 
operations as Tbase.

Compiler should distinguish New from Tbase.
Allowed implicit cast Tnew to Tbase.
Prohibited implicit cast Tbase to Tnew.
Allowed exlicit cast Tbase to Tnew.


but your examples indicate you need something else. How about 
the 'alias this' feature?


Thanks, this is what i want.
I just think that Typedef do it for me, hide this boilerplait 
code.




Re: Derived type

2021-03-30 Thread novice2 via Digitalmars-d-learn

On Tuesday, 30 March 2021 at 14:45:12 UTC, WebFreak001 wrote:
Xobj can then be used interchangeably with void*, so all void* 
arguments accept Xobj and all Xobj arguments accept void*.


yes, i understand alias, and i dont want such behaviour


If you want a type-safe alias that makes all void* arguments 
accept Xobj but not Xobj arguments to accept void*


yes, this is that i search



you can use `Typedef` like you linked.


Problem with Typedef template - code
  alias Xobj = Typedef!(void*)
not generate type named "Xobj",
but type named "Typedef!(void*, null, null)".
This makes compiler error messages unusable.



enum Xobj : void*;
```
This allows explicit conversion in both ways using cast, but 
only allows implicit conversion from Xobj to void*, not from 
void* to Xobj:


Strange syntax.
Behavour exactly what i want, but this code not works for me :(

  enum Xobj : void*;
  Xobj var;  //DMD Error: enum test7.Xobj forward reference of 
Xobj.init




Re: Derived type

2021-03-30 Thread novice2 via Digitalmars-d-learn

On Tuesday, 30 March 2021 at 13:43:52 UTC, Mike Parker wrote:

the straightforward way is just to use an alias.


i cant use alias - compiler cannot distinguish base type and 
alias, and cannot catch programmer errors


Buf if you need a more concrete type, you can use alias this in 
a struct:

I think Typedef template should do this struct for me.

Thanks Mike, this way is what i wanted

  struct Xobj {
private void* payload;
alias payload this;
  }

  Xobj good;
  foo(good);//nice
  foo(cast(Xobj)null);  //explicit cast allowed - nice
  foo(null);//no implicit cast disallowed - compiler 
error - nice


  void* bad;
  foo(bad); //compiler distinguish type - error - nice


I think Typedef template should do this struct for me.

Problem with Typedef template - code
  alias Xobj = Typedef!(void*)
not generate struct named "Xobj",
but struct named "Typedef!(void*, null, null)".
This makes compiler error messages unusable.

I will try to make template for struct. But template is black 
magic for me :)


Re: Since DMD 2.089.0 and later, compiled .exe showing SFX zip and opening with winRar when use resource.

2020-08-30 Thread novice2 via Digitalmars-d-learn

5. Open WinRAR support issue
6. Upload your .exe and say WinRar version then other peoples can 
reproduce


Re: Since DMD 2.089.0 and later, compiled .exe showing SFX zip and opening with winRar when use resource.

2020-08-30 Thread novice2 via Digitalmars-d-learn

Dear Marcone, that you want we all to do?
Rar detect sfx by small signature, and some bytes in exe looks 
like signature.

But this is not the problem - just do not open your exe with rar.
Or i just don't understand...

Another options:
1. try to compile with anoter .res or/and  another .ico (if magic 
bytes in .res)

2. wait next dmd version (if magic bytes in dmd runtime)
3. try gdc or ldc from https://dlang.org/download.html (if magic 
bytes in dmd runtime)

4 try to pack yor exe with free packer like https://upx.github.io/


Re: RtlAdjustPrivilege and NtRaiseHardError

2020-05-24 Thread novice2 via Digitalmars-d-learn
"doesn't work" isn't very helpful. Are you seeing compiler 
errors? Linker errors? Runtime errors? Please describe your 
problem.


Solved my problem alone : wrong signatures with functions ;)


and this reply isn't very helpful.
what is right signature?
you go to forum to ask help.
but wish you help to other readers, those will have the ame 
problems?


Re: Working with cmd

2020-04-18 Thread novice2 via Digitalmars-d-learn

On Friday, 17 April 2020 at 21:38:23 UTC, Quantium wrote:

Are there any libs which can be used to access cmd commands?


std.process

https://dlang.org/phobos/std_process.html#.execute



Re: How to converte string to wstring[]?

2020-02-06 Thread novice2 via Digitalmars-d-learn

import std.conv: to;

string str = "test1";
wstring[] wstr = [to!wstring(str)];


Re: What is wrong with this function that I can not get resource content?

2020-02-05 Thread novice2 via Digitalmars-d-learn

On Wednesday, 5 February 2020 at 20:01:19 UTC, Marcone wrote:

Sorry! Solved. Just need add # in this line:

get_resource("#300", "BMP", "melancia.bmp");


the mistake, very imho, is not check windows API functions 
results.

you can use wenforce:
https://dlang.org/phobos/std_windows_syserror.html#.wenforce


Re: foreach loop

2015-10-19 Thread novice2 via Digitalmars-d-learn

On Monday, 19 October 2015 at 15:56:00 UTC, Namal wrote:

Is it possible to use foreach backwards?



yes
http://dlang.org/statement.html#ForeachStatement
http://dpaste.dzfl.pl/cf847a9e1595


Re: Why does File.byLine() return char[] and not string

2015-10-18 Thread novice2 via Digitalmars-d-learn

what buffer you are talking.


internal buffer. where result line resides.



And what is "signal"? How it's working?


just the fact for programmer, that result line can be changed by 
other code (by phobos library code in this case).


no any special programming "signal".



Re: dis...@dlang.org

2015-09-23 Thread novice2 via Digitalmars-d-learn

http://forum.dlang.org/thread/hrzfcjrltftgzansd...@forum.dlang.org
https://github.com/Trass3r/hooksample


Re: Regex-Fu

2015-05-25 Thread novice2 via Digitalmars-d-learn

I cannot get the longest possible

it match longest for first group ([a-z]+)

try

^([a-z]+?)(hula|ula)$



Re: getopt helpWanted

2015-04-30 Thread novice2 via Digitalmars-d-learn

Thank you, Brian!


getopt helpWanted

2015-04-29 Thread novice2 via Digitalmars-d-learn

Hello.

Help me please to understand, how to show usage help to user, who 
enter wrong options?

For example, user not provided required filename.
I want to show error message, and program usage help text.
But likely getopt don't provide help text until valid options 
will be parsed.


Reduced code:
///
import std.stdio: writefln;
import std.getopt;

void main (string[] args)
{
  string fname;
  GetoptResult helpInfo;

  try
  {
helpInfo = getopt(
  args,
  std.getopt.config.required, file|f, File name, fname);

writefln(Options parsed: fname=%s, fname);
  }
  catch(Exception e)
  {
writefln(\nERROR: %s, e.msg);
defaultGetoptPrinter(Program usage:, helpInfo.options);
  }
}
///

Output:
ERROR: Required option file|fwas not supplied
Program usage:


Re: ErrnoException in Windows

2015-03-01 Thread novice2 via Digitalmars-d-learn

Thans guys!

wenforce not sutable - error code is lost.
may be, i will use modified wenforce, wich throws ErrnoException.


Re: ErrnoException in Windows

2015-03-01 Thread novice2 via Digitalmars-d-learn

Ha, i found
std.windows.syserror: WindowsException, wenforce;


ErrnoException in Windows

2015-03-01 Thread novice2 via Digitalmars-d-learn

Could you, please, help me to understand, why code:


import std.c.windows.windows;
import std.exception: ErrnoException;
import std.stdio: writefln;
import std.string: toStringz;

void main ()
{
  CreateFileA(toStringz(nonexisting file name), GENERIC_READ, 
FILE_SHARE_READ, null, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 
null);

  auto ex = new ErrnoException(CreateFileA);
  writefln(ex.errno=%d, ex.msg=%s, lasterror=%d, ex.errno, 
ex.msg, GetLastError());

}


prints:
ex.errno=0, ex.msg=CreateFileA (No error), lasterror=2

I wanted it will be:
ex.errno=2, ex.msg=CreateFileA (File not found), lasterror=2


one problem at dlang.org site

2015-02-23 Thread novice2 via Digitalmars-d-learn

sorry - i cant find where i can post this.
bugtracker have no dlang.org product.

when i click to left menu Standart Library - std - windows - 
charset
then i have error The requested URL 
/phobos/std_windows_charset.html was not found on this server.


Re: string concatenation with %s

2015-01-07 Thread novice2 via Digitalmars-d-learn

what if a_college[i] will contain ` char?
almost SQL have prepare statement...


Re: Scoped external function declaration

2015-01-02 Thread novice2 via Digitalmars-d-learn

Thanx Daniel, thanx Ketmar.

I just thinked that this is some sort of bug.
May be DMD should not change mangled name of external function...
Bit i dont know.


Re: Templates for structures

2014-11-04 Thread novice2 via Digitalmars-d-learn

On Monday, 3 November 2014 at 14:53:29 UTC, Ali Çehreli wrote:
It sounds possible but I don't understand it yet. Can you give 
an example of the input and output to the D code?


Ali


Thank you Ali.
I realized, that my wishes look like serialization.
So i decide read and learn code from existent serialization 
libraries.


Templates for structures

2014-11-02 Thread novice2 via Digitalmars-d-learn

Hello.

I need write some wrapper around legacy data structure.
May be it should be class. May be structure with methods.
The problem is writing repetitive code for underlying data.
For example:
 - code to read length-byte-prefixed string to D string for every 
field in every structure;

 - code to write D string back to length-byte-prefixed string;

Is it possible to write some template or mixin, and then just 
write

myStruct.addFiled(type=ByteLengthString, name=name)
myStruct.addFiled(type=ShortLengthString, name=filed2)
myStruct.addFiled(type=WeirdStoredInteger, name=counter)

May be it can be done with template, mixin, UDA, ...?

May be something already realized, and i can see sources as 
example?


Any ideas or examples please.
Just show direction for me )

Thanx.


Is this RDMD bug ?

2014-08-23 Thread novice2 via Digitalmars-d-learn
I have 2 reduced files, wich i can't compile with new (DMD 2.066) 
rdmd.exe under Windows 7 32-bit.


Command: rdmd --force --build-only aaa.d
Message Error 42: Symbol Undefined _D3etc3bbb3fooFZi

But command: dmd aaa.d etc\bbb.d
Compile without errors.
And then i replace rdmd.exe by old (from DMD 2.065) compile OK 
too.


Can anybody reproduce this?


/*** begin of file aaa.d ***/
import etc.bbb;

void main()
{
  int i = foo();
}
/***/


/*** begin of file etc\bbb.d ***/
module etc.bbb;

public int foo()
{
  return 1;
}
/***/


Re: Is this RDMD bug ?

2014-08-23 Thread novice2 via Digitalmars-d-learn
On Saturday, 23 August 2014 at 17:32:15 UTC, Vladimir Panteleev 
wrote:

etc is a standard D package name reserved for Phobos, the


Thanks for explanation.
I not be able to undertsand the cause - weird error message.
Now i can easy fix my code.

BTW, did rdmd determine user code or standard library by sorce 
file pathes?

Or it those names must be hardcoded?