Re: Problem with aliasing member function

2019-08-18 Thread rjframe via Digitalmars-d-learn
On Sun, 18 Aug 2019 19:17:16 +, Andrey wrote:

> Here in tester I want to alias a template method and call it on object
> if this object isn't null. But I don't understand how to do it.
> How to solve the problem?

I don't think you can alias an object method directly; three methods I 
know of:

---
struct Struct {
void run(int number) {
import std.stdio;
writeln("run ", number);
}
}

// Pass the object itself.
void func1(alias obj)(int number) if (isFunction!(obj.run)) {
obj.run(number);
}

// Pass the object and the name of the method.
void func2(alias obj, string method)(int number)
if (__traits(compiles, "obj." ~ method ~ "(number);")) 
{
mixin("obj." ~ method ~ "(number);");   
}

// Pass the method at runtime.
void func3(void delegate(int) f, int number) {
f(number);
}

void main() {
Struct obj;
func1!(obj)(1);
func2!(obj, "run")(2);
func3(, 3);
}
---

Also, you don't want to name something "Object"; the base class is called 
Object -- the struct shadows it but you may run into some bug or confusion 
later.

--Ryan


Re: D-oriented Syntax Highlighting Plugin for WordPress?

2019-01-01 Thread rjframe via Digitalmars-d-learn
On Tue, 01 Jan 2019 16:48:00 +, Ron Tarrant wrote:

> SilverStripe, on the surface, seems quite WordPress-alike. Did you find
> advantages over WordPress, or is it personal preference?
> How's the syntax highlighting? (I skimmed the video, but didn't see any
> mention of this.)
> 
> PrismJS looks promising.

I started using SilverStripe 7 or 8 years ago, and have never had a reason 
to look for anything else. It doesn't have the ecosystem of WordPress and 
never seemed to get much following outside New Zealand, but it's well-
designed and makes working with PHP not-horrible (and sometimes almost 
pleasant). I'm not familiar enough with WordPress to make any comparison.

I've documented my syntax highlighting setup[0] but it assumes familiarity 
with SilverStripe; reading through the official examples should be enough:

https://www.ryanjframe.com/blog/syntax-highlighting-in-silverstripe/


--Ryan


Re: D-oriented Syntax Highlighting Plugin for WordPress?

2019-01-01 Thread rjframe via Digitalmars-d-learn
On Tue, 01 Jan 2019 14:46:15 +, Ron Tarrant wrote:

> I've found a ton of syntax highlighter plugins for WordPress, but none
> that admit to supporting D. Anyone know of one?
> 
> Or, short of that, perhaps a different site build/management tool (read:
> not WordPress) with decent D syntax highlighting...
> 
> Or, one that can be adapted without rolling my sleeves much past my
> wrists.

I use SilverStripe instead of Wordpress, but if WordPress uses TinyMCE you 
can use the codesample plugin[0] with PrismJS[1], which does support D 
(though I don't know if it actively gets updates).


[0]: https://www.tiny.cloud/docs/plugins/codesample/
[1]: http://prismjs.com/


Re: Map of functions

2018-12-14 Thread rjframe via Digitalmars-d-learn
On Fri, 14 Dec 2018 16:33:44 +, Giovanni Di Maria wrote:

> 
> I need the flow of calls.
> Thank you Giovanni

gprof will do this on Linux/BSD if gdc supports the -pg flag (I don't know 
whether it would, but assume so) and your application is working.


>From code, you'd need to call a trace function on function entry. Mine 
lets you also specify a message (parameter values, etc.):

---
void trace(T...)(T args, string func = __FUNCTION__) {
import std.stdio : writeln;
if (args.length > 0) {
debug writeln("*trace: ", func, "- ", args);
} else {
debug writeln("*trace: ", func);
}
}

void main(int a, string b) {
trace();
trace(a, ", ", b);
}
---


Re: How to implement D to HTML pages ?

2018-10-01 Thread rjframe via Digitalmars-d-learn
On Mon, 01 Oct 2018 19:29:56 +, Aurélien Plazzotta wrote:
On Mon, 01 Oct 2018 19:29:56 +, Aurélien Plazzotta wrote:

> Hello guys,
> 
> I would like to implement a forum and a blog within my website
> (currently including only HTML, CSS and JS, written without CMS), using
> D and SQL but I really don't know how to proceed. How can I integrate D
> into HTML pages? Are there any kind of include's commands like PHP ?
> 
> Also, do I have to use vibe.d ? Or is it optional? I admit I didn't read
> the book yet (D Web Development), but only "Programming in D", which
> doesn't deal much with website workflow.

If you're most comfortable with PHP you may want to look at Adam Ruppe's 
arsd[0]; the readme has an overview of web-related and database-related 
modules.

vibe.d has more of a node.js feel. There's also DiamondMVC[1], which 
reminds me of ASP.NET (I'm not 100% sure whether that's intentional, and I 
haven't tried Diamond) and includes an ORM.


> Finally, what database system do you recommand to interact with for
> data-oriented website purpose? Perhaps, there are some standard or
> tierce-party librairies or ORM for PostgreSQL or SQLite ?
> 
> Thanks for all the light anyone will be willing to spread :)

There are low-level bindings for MySQL/MariaDB, Postgres, SqLite, and some 
people have made higher-level libraries and ORMs[2]. You may want to 
browse a bit and see what you like. I believe the Diamond ORM can be used 
without the rest of the framework, and the hunt-entity ORM is actively 
developed.


[0]: Repo: https://github.com/adamdruppe/arsd
 Docs: https://arsd-official.dpldocs.info/index.html (note that not 
everything is documented)
[1]: https://github.com/DiamondMVC/Diamond
[2]: http://code.dlang.org/?sort=updated=20=library.database


Re: Returning dynamic array from the function?

2018-09-08 Thread rjframe via Digitalmars-d-learn
On Sat, 08 Sep 2018 10:22:38 +, SuperPrower wrote:

> Also, is this me and my bad English, or first comment in code in this
> paragraph (linked above, not in the discussion) is supposed to be
> something different? Shouldn't it be reference?

Static arrays are value types, so the values are copied (see section 
12.1.2 on that page).

That said, static arrays do make that example a bit strange.


Re: Determine if CTFE or RT

2018-06-24 Thread rjframe via Digitalmars-d-learn
On Sun, 24 Jun 2018 14:43:09 +, Mr.Bingo wrote:

> let is(CTFE == x) mean that x is a compile time constant. CTFE(x)
> converts a x to this compile time constant. Passing any compile time
> constant essentially turns the variable in to a compile time
> constant(effectively turns it in to a template with template parameter)
> 

You can use __ctfe:

static if (__ctfe) {
// compile-time execution
} else {
// run-time execution
}



Re: Generate documentation for mixin'd function?

2018-06-02 Thread rjframe via Digitalmars-d-learn
On Fri, 01 Jun 2018 22:48:41 -0600, Jonathan M Davis wrote:
> 
> It's currently possible to put ddoc on template mixins but not string
> mixins:
> 
> https://issues.dlang.org/show_bug.cgi?id=2420
> 
> It was fix for template mixins with
> 
> https://issues.dlang.org/show_bug.cgi?id=648
> 
> but has yet to be fixed for string mixins.
> 
> - Jonathan M Davis


Thank you.

--Ryan


Re: GDC on Travis-CI

2018-06-02 Thread rjframe via Digitalmars-d-learn
On Sat, 02 Jun 2018 03:15:56 +, crimaniak wrote:

> I started to work with Travis-CI, building packages using all three main
> compilers, and noticed that I have problems with gdc every time and need
> to tweak code because of many things missing.
> For example: https://travis-ci.org/crimaniak/json-patch/jobs/386963340
> Why this situation with gdc and how best to deal with it?

GDC is on the 2.068 frontend, so you can't use any symbols introduced 
since then.

There is documentation for older Phobos versions online, but I don't 
remember the link and haven't found it by searching.


Generate documentation for mixin'd function?

2018-06-01 Thread rjframe via Digitalmars-d-learn
Hi

I'm making an API for a web service, and have a small collection of 
endpoints where I'd basically be creating copy+paste functions (a small 
enough number that this isn't really that important for this project). I 
thought I'd generate them via a mixin, but haven't seen that I can 
generate documentation for the mixin'd functions with either ddoc or ddox:

---
string GenerateSimpleEndpoint(string endpoint, string type) {
return
"MyServiceObj " ~ endpoint ~ "(MyServiceObj service) {\n"
  ~ "service.addQueryType(" ~ type ~ ");\n"
  ~ "return service;\n"
  ~ "}";
}

/** My documentation goes here. No function shows up. */
mixin(GenerateSimpleEndpoint("endp", "EndpointType.MyType"));

/+
// If I write the function instead, everything's good.
MyServiceObj endp(MyServiceObj service) {
service.addQueryType(EndpointType.MyType);
return service;
}
+/
---

The doc generators don't see anything created via the mixin. `dmd -X` does 
have the generated function, but its "file" is "file.d-mixin-172" rather 
than just "file.d". My guess is that this is the problem for ddoc, but ddox 
doesn't appear to use this json file so it would be a different problem.

Is this intended behaviour? Am I able to document generated functions?

Thank you for your time
--Ryan


Re: "Start a Minimal web server" example do not work.

2018-05-08 Thread rjframe via Digitalmars-d-learn
On Tue, 08 May 2018 13:23:07 +, BoQsc wrote:

> On Tuesday, 8 May 2018 at 13:04:12 UTC, Seb wrote:
>>
>> Did you try the newer MSCOFF format
>>
>> dub --arch=x86_mscoff start_minimum_server.d
>>
>> or
>>
>> dub --arch=x64 start_minimum_server.d
> 
> C:\Users\Vaidas\Desktop>dub --arch=x86_mscoff start_minimum_server.d
> Failed to find a package named 'start_minimum_server.d'.
> 
> C:\Users\Vaidas\Desktop>dub --arch=x64 start_minimum_server.d
> Unsupported architecture: x64

Try the 64-bit build as "--arch=x86_64"; dub doesn't recognize x64 (at 
least on Windows).

dub --arch=x86_64 --single start_minimum_server.d

For your first attempt above, adding the --single flag might work.


--Ryan


Re: How to enable verbose logging during application run

2018-03-17 Thread rjframe via Digitalmars-d-learn
On Sat, 17 Mar 2018 22:37:36 +, Venkat wrote:

> Sorry posted the above message by accident.
> 
> I am running a vibed app using `dub` command. But it produces no logging
> what so ever when requests are made. The server returns http error codes
> but it doesn't log anything to the console. How do I make it show me a
> lot more detail than it is doing now ?
> 
> For example, in a Java webapp, one would change the logging level to
> debug if a logging library is configured.


vibe.core.log has a setLogLevel function.

http://vibed.org/api/vibe.core.log/setLogLevel
http://vibed.org/api/vibe.core.log/LogLevel


Also, the URLRouter class has a getAllRoutes method; if needed, writing 
that to the terminal can verify the routes are what you expect.


Re: Fixed size array initialization

2018-02-11 Thread rjframe via Digitalmars-d-learn
On Sat, 10 Feb 2018 10:55:30 +, rumbu wrote:

> I know that according to language spec
> (https://dlang.org/spec/arrays.html#static-init-static) you can skip
> declaring all your elements in a fixed size array.
> 
> I'm just recovering from a bug which took me one day to discover because
> of this.
> 
> I have a large static initialized array, let's say int[155], and I
> forgot to declare the last element:
> 
> int[155] myarray = [
>a,
>b,
>c,
>...
>//forgot to declare the 155th element
> ];
> 
> I took for granted that the compiler will warn me about the fact that my
> number of elements doesn't match the array declaration but I was wrong.
> 
> Does it worth to fill an enhancement on this, or this is intended
> behavior?

If you separate initialization to a static this, you'll get a compile 
error:

```
immutable uint256[78] pow10_256;

static this() {
// Error: mismatched array lengths, 78 and 2
pow10_256 = [
uint256(1UL),
uint256(10UL)
];
}
```

Or if you know that no element should be the object's init value, you 
could do a static foreach to validate that at compile-time.

You could also generate the elements at compile-time (this could use some 
improvement, and should be generalized so a single function can generate 
fillers for your other arrays as well):

```
immutable uint256[78] pow10_256;

static this() {
// Uncomment this to view the generated code. Helpful for debugging.
//pragma(msg, GenPow10_256Initializer);
mixin(GenPow10_256Initializer);
}

static string GenPow10_256Initializer() {
import std.range : repeat;
import std.conv : text;

string code = "pow10_256 = [\n";
foreach(i; 0..78) {
code ~= `uint256("1` ~ '0'.repeat(i).text ~ `")` ~ ",\n";
}
code = code[0..$-2]; // Remove trailing comma.
code ~= "\n];";
return code;
}
```


Re: Debugging bad requests with vibe

2018-02-09 Thread rjframe via Digitalmars-d-learn
On Fri, 09 Feb 2018 15:48:54 +, Nicholas Wilson wrote:

> On Friday, 9 February 2018 at 08:06:53 UTC, Seb wrote:
>> On Thursday, 8 February 2018 at 17:09:44 UTC, Nicholas Wilson wrote:
>>> Is there a way I can see/log what requests are being made? I can
>>> change both the client and server.
>>
>> -v and -vv
> 
> So it turns out that structs do not work as parameters TO rest interface
> functions.
> 
> https://github.com/vibe-d/vibe.d/issues/2067

I have a project doing this; I think I solved that (or something) with:

```
@path("/api/")
interface RestAPI {
// stuff
}
```

I cannot reproduce your problem with that code though to see if it will 
work.


Re: Interfacing with C++

2018-02-04 Thread rjframe via Digitalmars-d-learn
On Sun, 04 Feb 2018 08:33:20 +, Mike Parker wrote:

> Though, I'm curious why anyone would want to declare a callback in a C++
> program as cdecl only on Windows and use the default C++
> convention everywhere else. I suggest you dig into it and make sure
> that's what's intended. And good luck binding to OpenCV!

My guess would be that it's to prevent name mangling of functions in a 
generated DLL and the need for a DEF file.


Re: How to proceed with learning to code Windows desktop applications?

2018-01-30 Thread rjframe via Digitalmars-d-learn
On Tue, 30 Jan 2018 05:56:51 +, DanielG wrote:

> Then there's all the modern Microsoft stuff (WPF/XAML/WinRT/etc),
> but you pretty much have to use either .NET or C++ for that.

VS release builds compile to native now by default; for easy Windows 
programming, you really can't beat C# and drawing the GUI (Windows Forms, 
not necessarily the new stuff). If the OP wants to learn what's needed for 
more complex GUI tasks (like for most non-simple applications), learning 
to build a GUI from source is kind of necessary though.

If/when .NET Core becomes something people can rely on and are willing to 
try, I think we'll see more people using C# outside the enterprise; you 
get easy when you want it, power when you need it, native code generation 
on Windows, and OS portability.


Re: dmd error - unrecognized file extension

2018-01-29 Thread rjframe via Digitalmars-d-learn
On Mon, 29 Jan 2018 17:25:34 +, Evan Burkey wrote:

> Hi there, I have a problem that is eluding me, hoping someone can help
> me see the light. I'm on Windows 10 using the latest version of dmd. I
> have a directory with 2 files: "version.txt" and "versioncheck.d".
> version.txt contains a single line of text. I have the line:
> 
>  immutable version = import("version.txt");
> 
> and my dmd switches are:
> 
>  dmd -J. .\versioncheck.d
> 
> but dmd fails with "Error: unrecognized file extension". I've searched
> the internet but found very little about this problem. Hopefully I'm
> just missing something simple.
> 
> Thanks!

I have the same issue on Windows 10, but Linux works; have you checked the 
issue tracker yet?

It looks like just `dmd -J .\versioncheck.d` should work [I haven't tested 
this properly with an actual string mixin, but I don't get that error this 
way]. On Windows, dmd doesn't seem to like starting with the period.

So if it was in a different directory, instead of `dmd -J.\somedir` on 
Windows you'd need to just do `dmd -Jsomedir`

--Ryan


Re: assert and enforce both compiled out with -release

2018-01-28 Thread rjframe via Digitalmars-d-learn
On Sun, 28 Jan 2018 00:59:12 +, lobo wrote:

> On Saturday, 27 January 2018 at 22:53:37 UTC, Ali Çehreli wrote:
>> On 01/27/2018 10:33 AM, kdevel wrote:
>>
>>> I suggest the deletion of the sentence "Use assert in contracts."
>>
>> Done.
>>
>> Ali
> 
> Wait, no this isn't right, is it? Enforce should not be used in
> contracts so the "Use assert in contracts" statement is correct and
> should remain. I think the issue here is the OP is getting confused
> between assert vs. exception.

Without that statement, the documentation is still pretty clear that you 
shouldn't use enforce in contracts, so removing it won't hurt anything, 
and does make things clearer by staying on-topic.


Re: assert and enforce both compiled out with -release

2018-01-27 Thread rjframe via Digitalmars-d-learn
On Sat, 27 Jan 2018 17:12:25 +, kdevel wrote:

 
> This is not a problem, because this is perfectly legal. The problem is
> the wording of this phrase on the docs:
> 
> | Also, do not use enforce inside of contracts (i.e. inside of in and
> out blocks | and invariants), because they will be compiled out when
> compiling with | -release. Use assert in contracts.
> 
> Using assert *IN* contracts in -release mode is equally pointless.

...
 
> | Also, do not use enforce inside of contracts (i.e. inside of in and
> out blocks | and invariants), because they will be compiled out when
> compiling with | -release. Use assert in contracts.
> 
> to me. IMHO this advice is pointless.

...
 
> Then please explain to me, in which respect the advice to "Use assert[s]
> in contracs" makes sense if the contracts are to be compiled out. I
> don't get it.

I think I see what you mean; you interpret "use asserts, because enforce 
will be compiled out" to imply that asserts wouldn't be compiled out, 
correct? Since, in reality, both would be compiled out, it shouldn't 
matter what you use, so the docs shouldn't care. That makes sense.

The documentation seems to assume the reader has certain expectations of 
assert and enforce[0], so each function expresses a different intention to 
the programmer; when I see `assert()` I expect those checks only in non-
release mode; when I see `enforce()` I expect those checks regardless of 
the flags that have been set[1]. Placing `enforce` in a contract messes 
with that expectation.

What language here would make more sense to you? Anything I can come up 
with is either awkward or pretty verbose.

--Ryan


[0]: The correct expectation, but that's not necessarily important when 
it's not explicitly described.
[1]: So you can use enforce to validate user input, but never assert.


Re: assert and enforce both compiled out with -release

2018-01-27 Thread rjframe via Digitalmars-d-learn
On Sat, 27 Jan 2018 13:52:47 +, kdevel wrote:

> https://dlang.org/phobos/std_exception.html#enforce states:
> 
> | Also, do not use enforce inside of contracts (i.e. inside of in and
> out blocks | and invariants), because they will be compiled out when
> compiling with -release.
> | Use assert in contracts.
> 
> But assert is also ignored in release mode:
> 

enforce is a wrapper around try/catch (I don't know if that's technically 
true, but it is pragmatically true); assert is a debug tool. Contracts and 
assertions are removed for release builds, which means if you place an 
enforce in a contract, it's removed - but the same enforce placed in the 
function body would remain. You don't want the enforce stripped from the 
exe (if you are OK with that, it should be an assertion), so it shouldn't 
be in the contract.

Use assertions to catch programming bugs, and enforce or try/catch for 
exceptions.

If DIP 1006[0] is accepted, we'll have greater control over the removal of 
asserts and contracts in release mode.


[0]: https://github.com/dlang/DIPs/blob/master/DIPs/DIP1006.md


Re: structs inheriting from and implementing interfaces

2018-01-01 Thread rjframe via Digitalmars-d-learn
On Tue, 02 Jan 2018 00:54:13 +, Laeeth Isharc wrote:

> On Friday, 29 December 2017 at 12:59:21 UTC, rjframe wrote:
>> On Fri, 29 Dec 2017 12:39:25 +, Nicholas Wilson wrote:
>>
>> I've actually thought about doing this to get rid of a bunch of if
>> qualifiers in my function declarations. `static interface {}` compiles
>> but doesn't [currently] seem to mean anything to the compiler, but
>> could be a hint to the programmer that nothing will directly implement
>> it; it's a compile-time interface. This would provide a more generic
>> way of doing stuff like `isInputRange`, etc.
> 
> Atila does something like this
> 
> https://code.dlang.org/packages/concepts

Thanks; I actually started skimming through his repositories a couple of 
days ago, but didn't see this.

--Ryan


Re: take symbol as parameter

2017-12-30 Thread rjframe via Digitalmars-d-learn
On Sat, 30 Dec 2017 13:07:49 +, Marc wrote:

> how do I take a symbol as parameter?
> 
> for example:
> 
>> template nameof(alias S) {
>>  import std.array : split;
>>  enum nameof = S.stringof.split(".")[$-1];
>>}
> 
> Works fine for say a enum member such nameof!(myEnum.X) but this:
> 
>>  struct S { int v; }
>>  S s;
>>  writefln(nameof!(s.v)); // should return "v"
> 
> return the following error:
> 
>> Error: template instance nameof!(v) cannot use local 'v' as parameter
>> to > non-global template nameof(alias S)

You can use the name of the struct rather than the instance.

writefln(nameof!(S.v));


Re: structs inheriting from and implementing interfaces

2017-12-29 Thread rjframe via Digitalmars-d-learn
On Fri, 29 Dec 2017 12:39:25 +, Nicholas Wilson wrote:

> On Friday, 29 December 2017 at 12:03:59 UTC, Mike Franklin wrote:
>
> The problem is that interfaces are a runtime thing (e.g. you can cast a
> class to an interface)
> structs implement compile time interfaces via template duck typing
> (usually enforced via an if()).
> you could probably write a wrapper that introspected an interface and
> enforced that all members were implemented.

I've actually thought about doing this to get rid of a bunch of if 
qualifiers in my function declarations. `static interface {}` compiles but 
doesn't [currently] seem to mean anything to the compiler, but could be a 
hint to the programmer that nothing will directly implement it; it's a 
compile-time interface. This would provide a more generic way of doing 
stuff like `isInputRange`, etc.


Re: Sort in return statement

2017-12-09 Thread rjframe via Digitalmars-d-learn
On Sat, 09 Dec 2017 07:32:42 +, Seb wrote:

> 
> Use .release to obtain the underlying array. No need to do another
> allocation!
> 
> ```
> numbers.take(8).sort.release;
> ```

I did not realize that was there; thanks.


Re: Sort in return statement

2017-12-08 Thread rjframe via Digitalmars-d-learn
On Sat, 09 Dec 2017 02:34:29 +, codephantom wrote:

> Anyone got ideas on how to get sort() working in the *return*
> statement?
> 
> //
> 
> ushort[] draw8Numbers()
> {
>  import std.meta : aliasSeqOf;
>  import std.range : iota;
>  ushort[] numbers = [ aliasSeqOf!(iota(1,46)) ];
> 
>  import std.random : randomShuffle;
>  randomShuffle(numbers);
> 
>  import std.range : take;
>  import std.algorithm.sorting : sort;
>  return numbers.take(8); /* ok */
>  //return sort(numbers.take(8)); /* I want this, but it won't
> work. */
> 
> }
> 
> // -


`sort` returns a SortedRange of ushorts, not an array of ushorts. Make it:

```
import std.array : array;
return sort(numbers.take(8)).array;
```

--Ryan


Re: Windows Share Path

2017-12-03 Thread rjframe via Digitalmars-d-learn
On Sun, 03 Dec 2017 16:42:46 +, vino wrote:

> Question:
> Is there a way to map network drive in windows using D code, similar to
> the windows command such as "net use" or "pushd" or powershell command
> New-PSDrive.?
> 
> From,
> Vino.B

There's WNetAddConnection2[1] and WNetAddConnection3[2] in the Windows API. 
The API header module is core.sys.windows.winnetwk[3].

I've not used either function, but based on the documentation, it looks 
straightforward.

--Ryan


[1]: https://msdn.microsoft.com/en-us/library/windows/desktop/aa385413
(v=vs.85).aspx
[2]: https://msdn.microsoft.com/en-us/library/windows/desktop/aa385418
(v=vs.85).aspx
[3]: https://github.com/dlang/druntime/
blob/2db828bd4f21807254b770b3ec304f14596a9805/src/core/sys/windows/
winnetwk.d


Re: Windows Share Path

2017-12-02 Thread rjframe via Digitalmars-d-learn
On Sat, 02 Dec 2017 14:16:17 +, Vino wrote:

> Hi,
> 
>The script is schedule using a domain user id(domain\user id),
> and the windows share are mapped using the same user id /password and
> ran the scheduled task by login with the same domain user(Not
> Administrator) , the script executes fine when run manually and executes
> fine when scheduled with option "Run when user is logged in" , but the
> same is not running when schedule with option "Run whether user is
> logged in or not". The domain id is added to the Administrator Group and
> the Security policy "Logon as Batch user"
> is assigned. The domain id has the Full access to the Network share.
> 
> From,
> Vino.B

Is storing the password allowed by your local security policy? (gpedit on 
the local machine: Computer Configuration > Windows Settings > Security 
Settings > Local Policies > Security Options > Network access: Do not 
allow storage of passwords and credentials for network authentication)

Other than that, I'm out of ideas; this should be a slow week at work so I 
might be able to try later.

Note that running "whether logged on or not" will run in interactive mode 
so your `writeln`s won't output anywhere; you'd need to log to a file. But 
it shouldn't restrict network access.

--Ryan


Re: Windows Share Path

2017-12-02 Thread rjframe via Digitalmars-d-learn
On Sat, 02 Dec 2017 07:48:14 +, Vino wrote:

> On Saturday, 2 December 2017 at 05:08:27 UTC, Vino wrote:
>> Hi All,
>>
>>   Request your help, I have samll program which validates the
>> file path, the script run perfectly when i run it manually, but if i
>> run it via windows task scheduler i am getting "Invalid File Path
>>  or Path do not Exist", The path is a windows share, Even tried
>> to add the net path as "server\\share$\\BACKUP" for the parameter
>> "p" in the below code but no luck, the same error.
>>
>> Even tried to call this program via .bat script not luck same error
>>
>> Windows .BAT program @echo off cd D:\DScript start /D D:\DScript /B
>> /WAIT D:\DScript\TestDir.exe exit
>>
>> Program import std.stdio;
>> import std.file;
>> import std.path;
>> import std.system;
>>
>> void main()
>> {
>>  version (Windows) { auto p = "N:\\\BACKUP";
>>   if (!p.isValidPath && !p.strip.isValidFilename || !p.exists )
>> { writeln("Invalid File Path (", p, ") or Path do not Exist"); }
>>   else { writeln("File Exist":, p); }
>> }
>>   }
>>
>> From,
>> Vino.B
> 
> Even tried with the below code, it works manually but not via Windows
> scheduler with option "Run whether user is logged on or not"
> 
> Program:
> import std.stdio;
> import std.file;
> import std.path;
> import std.string;
> import std.process;
> 
> void main()
> {
> auto result =
> execute(["C:\\Windows\\System32\\WindowsPowerShell\\v1.0\
\powershell.exe",
> "-command", "New-PSDrive -Name", "R", "-PSProvider FileSystem -Root",
> "bp1xeuss005-f05.bp.com\\ea_sap_basis2$", "-Persist"]);
> auto p = "R:\\BACKUP";
> if (!p.isValidPath && !p.strip.isValidFilename || !p.exists ) {
> writeln("Invalid File Path (", p, ") or Path do not Exist"); }
> else { writeln("File Exist :", p); }
> 
> }
> From,
> Vino.B

FYI: The backquote gives you a WYSIWYG string: `c:\windows\system32`, 
which is incredibly useful for Windows paths.


I don't have a network share available to test with, but:

Are you running with elevated privileges in the scheduled task? If so, do 
you run as admin when trying manually? If you mount the share as a user, 
I'm wondering if the task can't access it running in another context.

You could try in the batch file, either adding
```
net use N: \\server\share\BACKUP /USER:  
```

prior to running the exe (and "net delete" afterword), or try
"pushd \\server\share\BACKUP" to access the path (and make it the current 
working directory). Use "popd \\server\share\BACKUP" at the end of the 
script.

Source: https://blog.adrianbanks.co.uk/windows/2007/03/08/accessing-
network-file-shares-from-a-command-prompt.html


Re: D program in Windows Task Scheduler.

2017-11-28 Thread rjframe via Digitalmars-d-learn
On Tue, 28 Nov 2017 09:44:39 +, Vino wrote:

> Hi All,
> 
>   I have small D program which run's perfectly when i run it
> manually, but when I schedule the same via windows task scheduler and
> choose the option "Run whether user is logged on or not" the program
> does not execute, the task scheduler job log return code
> 4294967295(Invalid argument). SO request you help on this.

You're not using getopt in the sample; if you comment that line out, do 
you still have the problem?

How are you passing arguments in Task Scheduler? You should be using the 
textbox for arguments, not the same one the application is passed in.
Program/script: test.exe
Add arguments: dryrun, run


If that's correct, create a batch file that takes no arguments and calls 
your application and try running the batch file via Task Scheduler. If 
that fails, the application is probably trying to do something it doesn't 
have permission to do. If it succeeds, the task command is probably not 
set up correctly.

--Ryan


Re: dirEntries() and exceptions

2017-11-24 Thread rjframe via Digitalmars-d-learn
On Fri, 24 Nov 2017 12:02:47 +, doc wrote:

> I'm trying recursively find files, and have some trouble to catch
> exceptions if have no permission to read directory.
> 
...
> 
> std.file.FileException@std/file.d(3798):
> /tmp/systemd-private-8338348a306b4d589e3f6ba2bfd0c8fe-systemd-
timesyncd.service-3374MK:
> Permission denied 
> 
> [code]
> void main() {
> import std.stdio, std.file;
> 
> try {
> auto farray = dirEntries("/tmp", "*.{d,py,ph,sh}",
> SpanMode.breadth);
> foreach (f; farray) {
> writeln(f);
> }
> catch (FileException e) {
> writeln(e.msg);
> }
> }
> [/code]
> 
> This not work, after writeln(e.msg); program is exit.

The exception for dirEntries was reported as a bug here[1]; there is a 
workaround listed on that page that silently skips directories it can't 
read, but you'll need to modify it a bit to maintain a breadth search.

As to why your code stops after catching the exception, the try/catch 
block does not place you back in the block that threw the exception, but 
drops you off in the outer scope. You would need to place the code in some 
sort of loop to run until all input was consumed in order continue past 
the exception.


[1]: https://issues.dlang.org/show_bug.cgi?id=12391


Re: Why do I have to cast arguments from int to byte?

2017-10-10 Thread rjframe via Digitalmars-d-learn
On Tue, 10 Oct 2017 19:55:36 +, Chirs Forest wrote:

> It wouldn't be so bad if I didn't have to use the word cast before each
> cast, bust since I have to specify both the word cast and the cast type
> and then wrap both the cast type and the value in brackets... it just
> explodes my code into multiple lines of unreadable mess.
> 
> 
> void foo(T)(T bar, T bar2, T bar3){...}
> 
> byte foobar = 12;
> 
> foo!byte(foobar + 1, foobar + 22, foobar + 333);
> vs.
> foo!byte(cast(byte)(foobar + 1), cast(byte)(foobar + 22),
> cast(byte)(foobar + 333));


You could wrap the cast in a function to clean it up a bit:

void main() {
byte foobar = 12;
foo!byte((foobar + 1).b, (foobar + 22).b, (foobar + 333).b);
}

byte b(int n) pure {
pragma(inline, true); // Probably not necessary.
return cast(byte)n;
}

void foo(T)(T bar, T bar2, T bar3) {
import std.stdio : writeln;
import std.string : format;
writeln("%s, %s, %s".format(bar, bar2, bar3));
}


--Ryan


Re: It makes me sick!

2017-07-28 Thread rjframe via Digitalmars-d-learn
On Fri, 28 Jul 2017 05:14:16 +, FoxyBrown wrote:
> 
> You can make any claim you want like: "The end user should install in to
> a clean dir so that DMD doesn't get confused and load a module that
> doesn't actually have any implementation" but that's just your opinion.

I have never seen extracting into the directory as a supported upgrade 
path for anything except the simplest of applications and a few PHP 
projects that supply a migration script.

> At the end of the day it only makes you and dmd look bad when it doesn't
> work because of some lame minor issue that could be easily fixed. It
> suggests laziness["Oh, there's a fix but I'm too lazy to add it"],
> arrogance["Oh, it's the end users fault, let them deal with it"], and a
> bit of ignorance.

The only solution I can think of is never splitting a module in Phobos; 
the alternative would be to change the way the module system works (which 
seems to be what you want), and that's going to break everybody's 
everything.


Re: GDC generate wrong .exe ("not a valid win32 application")

2017-06-19 Thread rjframe via Digitalmars-d-learn
On Mon, 19 Jun 2017 14:08:56 +, Patric Dexheimer wrote:

> Fresh install of GDC. (tried with 32x ad 32_64x)
> 
> GDC: 6.3.0 DUB: 1.3.0
> 
> dub run --build=release --arch=x86 --compiler=gdc
> 
> (...)
> Running .\main Failed to spawn new process (%1 is not a valid win32
> application)

If you try compiling a single file directly (gdc app.d -o app), does it 
work?

If it does, what's the output of `dub run -v ...`?


Re: Namespaces like C++

2017-01-16 Thread rjframe via Digitalmars-d-learn
On Mon, 16 Jan 2017 18:02:09 +, Andrey wrote:

> Hello, can I using namespaces like in C++, for example: ui::Widget or
> ui::Manager? I created ui/widget.d and ui/manager.d for implementation
> classes Widget and Manager, bun I can't import their correctly for using
> ui.Manager uiManager;
> If it is impossible, then what is the best way to using namespaces in D?
> Should I naming my classes with prefix e.g. UIManager and UIWidget?

You can do either a static import or renamed import. The static import 
requires using the fully-qualified name; renamed imports let you set a 
local name for the module.

static import ui.widget;
ui.widget.SomeWidget w;

import mymanager = ui.manager;
mymanager.uiManager m;



For more information on modules see http://dlang.org/spec/module.html

--Ryan


Re: DMD specify VS version in sc.ini

2016-12-27 Thread rjframe via Digitalmars-d-learn
On Tue, 27 Dec 2016 22:09:49 +, Ryan wrote:

> I have a C library I want to link against that was compiled with VS
> 2013. I have VS2013 and VS2015 installed. I want DMD to use the 2013
> version, since the C-runtime in 2015 is not backwards compatible.
> 
> Looking at sc.ini I see several entries that relate to the linker, CRT,
> and SDK. How do I edit these to force the use of VS 2013?
> 
> I think I can figure out most of them except for UCRTVersion.
> 
> Thanks,

You want either LINKCMD or LINKCMD64. VS 2013 is what, 11.0? So you'd add 
something like:

LINKCMD64=C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\bin
\x86_amd64\link.exe


--Ryan