Re: Shared library module system with dub

2021-03-01 Thread evilrat via Digitalmars-d-learn

On Tuesday, 2 March 2021 at 04:26:52 UTC, Pillager86 wrote:

On Tuesday, 2 March 2021 at 04:13:31 UTC, Pillager86 wrote:

On Tuesday, 2 March 2021 at 03:42:14 UTC, Pillager86 wrote:
Update: the dub "dynamicLibrary" target option is busted on 
Windows and does not build anything at all. This should be 
filed as a bug.


Update again: I got the Windows DLL to build and run without 
crashing, but I don't know how to put specific platform 
options in dub. I need "dflags" "-defaultlibrary=phobos2" or 
something on Linux but not Windows.


Try this (for dub.json)

"dflags-linux": ["-defaultlibrary=phobos2"]

For platform/architecture/compiler specific variants just add 
suffix like this, also works with lflags, and I guess pretty much 
any other options.


"dflags-linux" : ["specific flags for linux"]
"dflags-windows" : ["specific flags for windows"]
"dflags-windows-dmd" : ["more flags if building with dmd"]
"dflags-windows-dmd-x86" : ["even more flags if building for x86 
using dmd"]


Also, what do you do if the shared library needs to refer to 
types in the main static library?



You need to link it with your DLL, this will however will create 
lots of duplicated symbols in your executable.


In most cases this is undesireable, so instead one will usually 
put all common stuff into DLL and share across main executable 
and other DLL's that relies on it.


On Windows however DLL support is unfinished, so you are stuck 
with hacks and/or static libs option.




Re: Vibe.d tutorial

2021-03-01 Thread bachmeier via Digitalmars-d-learn

On Monday, 1 March 2021 at 22:25:39 UTC, Rey Valeza wrote:
Hi, I wrote a tutorial on Vibe.d while trying to re-learn 
Vibe.d. I find that most of Kai Nacke's book need updating, so 
I wrote a tutorial while trying to re-learn it.


Here it is.

https://github.com/reyvaleza/vibed/commit/27ec3678f25d1dd414fae1390677397a7bc57721

I would be glad if you can give me some feedback so I can 
improve it.


Thanks!


I have to agree with the comment about PDF files on Github. I 
tried to read it on my i7 with 16 GB of RAM and my machine froze. 
It looks like you wrote it up as a MS Word document. You could 
enable Github Pages on your repo, export from Word to html, 
upload that document to the repo, and then let Github Pages 
handle the rest. You appear to have put a lot of work into it, 
but posting it as a PDF on Github may reduce your readership.


Re: Shared library module system with dub

2021-03-01 Thread Pillager86 via Digitalmars-d-learn

On Tuesday, 2 March 2021 at 04:13:31 UTC, Pillager86 wrote:

On Tuesday, 2 March 2021 at 03:42:14 UTC, Pillager86 wrote:
Update: the dub "dynamicLibrary" target option is busted on 
Windows and does not build anything at all. This should be 
filed as a bug.


Update again: I got the Windows DLL to build and run without 
crashing, but I don't know how to put specific platform options 
in dub. I need "dflags" "-defaultlibrary=phobos2" or something 
on Linux but not Windows.


Also, what do you do if the shared library needs to refer to 
types in the main static library?


Re: Shared library module system with dub

2021-03-01 Thread Pillager86 via Digitalmars-d-learn

On Tuesday, 2 March 2021 at 03:42:14 UTC, Pillager86 wrote:
Update: the dub "dynamicLibrary" target option is busted on 
Windows and does not build anything at all. This should be 
filed as a bug.


Update again: I got the Windows DLL to build and run without 
crashing, but I don't know how to put specific platform options 
in dub. I need "dflags" "-defaultlibrary=phobos2" or something on 
Linux but not Windows.


Re: Shared library module system with dub

2021-03-01 Thread Pillager86 via Digitalmars-d-learn
Update: the dub "dynamicLibrary" target option is busted on 
Windows and does not build anything at all. This should be filed 
as a bug.


Shared library module system with dub

2021-03-01 Thread Pillager86 via Digitalmars-d-learn
What is the correct multi-platform way to build one dub project 
as a shared library, and load said shared library in a separate 
dub project? So far I am able to load a shared library and run a 
function from it (had to extern(C) it to get the symbol to load) 
by using "targetType":"dynamicLibrary" in the shared library 
project, but the main program exits with code -11 and if I don't 
unload the library manually I get a weird "Aborting from 
src/rt/sections_elf_shared.d(500) DSO being unregistered isn't 
current last one.Program exited with code -6" error that Google 
knows nothing about.


I'm trying to add a module system to DMildew because the core 
runtime is over 50 MB in the debug build. Libraries would be 
written in regular D and optionally dynamically loaded by a 
regular D application that links to the core static library (the 
DMildew runtime).


Re: Vibe.d tutorial

2021-03-01 Thread ryuukk_ via Digitalmars-d-learn

On Monday, 1 March 2021 at 22:25:39 UTC, Rey Valeza wrote:
Hi, I wrote a tutorial on Vibe.d while trying to re-learn 
Vibe.d. I find that most of Kai Nacke's book need updating, so 
I wrote a tutorial while trying to re-learn it.


Here it is.

https://github.com/reyvaleza/vibed/commit/27ec3678f25d1dd414fae1390677397a7bc57721

I would be glad if you can give me some feedback so I can 
improve it.


Thanks!


I think, specially for github, a markdown (.MD) doc would be MUCH 
better, so you can embed code this way:


```D
void main() {
writeln("hi");
}
```

You can also embbed screenshots and stuff


It would be easier to browse

Also i'd skip the DMD installation part, and focus on the vibe.d 
and IDE experience (with debugging)




Vibe.d tutorial

2021-03-01 Thread Rey Valeza via Digitalmars-d-learn
Hi, I wrote a tutorial on Vibe.d while trying to re-learn Vibe.d. 
I find that most of Kai Nacke's book need updating, so I wrote a 
tutorial while trying to re-learn it.


Here it is.

https://github.com/reyvaleza/vibed/commit/27ec3678f25d1dd414fae1390677397a7bc57721

I would be glad if you can give me some feedback so I can improve 
it.


Thanks!




Re: Does reserve() preallocate for futher appends too?

2021-03-01 Thread bachmeier via Digitalmars-d-learn

On Monday, 1 March 2021 at 03:07:19 UTC, Jack wrote:
isn't clear for me if reserve() does preallocate memory so that 
that operator like arr ~= x can use previously allocate memory 
by reserve() or it's just used in slices like b = arr[x .. y]?


You may potentially find this article of use:

https://dlang.org/articles/d-array-article.html


Re: How can I tell if the give parameter can be run at compile time?

2021-03-01 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Mar 01, 2021 at 08:05:57PM +, Jack via Digitalmars-d-learn wrote:
> bool g(T)(T)
> {
>   return __traits(compiles, mixin("{ enum a = t; }"));
> }
> 
> 
> int a;
> enum s = "";
> // both return false but g(s) is expected to return true
> pragma(msg, g(s));
> pragma(msg, g(a));

https://wiki.dlang.org/User:Quickfur/Compile-time_vs._compile-time


T

-- 
They pretend to pay us, and we pretend to work. -- Russian saying


Re: How can I tell if the give parameter can be run at compile time?

2021-03-01 Thread Adam D. Ruppe via Digitalmars-d-learn

On Monday, 1 March 2021 at 20:05:57 UTC, Jack wrote:

int a;
enum s = "";
// both return false but g(s) is expected to return true


So the value must be known at compile time without any extra 
context. So that `a` variable might be changed somewhere else so 
compile time can't read or write it.


`enum` is only allowed to be set once (and at compile time!) so 
it is allowed at CT too.


`static immutable` generally allows it too since it must be set 
at declaration then never changed again.


But almost any mutable variable is no go unless it is directly 
returned from a function which itself can be called at compile 
time.


How can I tell if the give parameter can be run at compile time?

2021-03-01 Thread Jack via Digitalmars-d-learn

bool g(T)(T)
{
return __traits(compiles, mixin("{ enum a = t; }"));
}


int a;
enum s = "";
// both return false but g(s) is expected to return true
pragma(msg, g(s));
pragma(msg, g(a));



Re: vibe.d selectively include attribute into tag using diet template

2021-03-01 Thread JG via Digitalmars-d-learn
On Sunday, 28 February 2021 at 18:10:26 UTC, Steven Schveighoffer 
wrote:

On 2/28/21 12:29 AM, JG wrote:
On Saturday, 27 February 2021 at 19:12:55 UTC, Steven 
Schveighoffer wrote:


If you use an expression without quotes
in diet, it becomes an interpolation.


Would you mind explaining in more detail what this means? How 
could one use this, other than with booleans?


So if you have an expression as the right side of an attribute 
assignment, it is treated as a D expression, which is then 
evaluated and turned into string form.


So e.g. your original example:

tag(attribute='#{dexpression}')

can be written as:

tag(attribute=dexpression)

-Steve


Thanks



Re: Unexpected threads observed before main()

2021-03-01 Thread Keivan Shah via Digitalmars-d-learn

On Monday, 1 March 2021 at 09:03:32 UTC, rikki cattermole wrote:
So it is debatable if it is a good idea to get rid of them once 
done (even if delayed).


Makes sense, Thanks a lot for the quick help!


Re: Unexpected threads observed before main()

2021-03-01 Thread rikki cattermole via Digitalmars-d-learn

On 01/03/2021 8:02 PM, Keivan Shah wrote:
If possible, Can you also help me understand that why are the threads 
not despawned once the GC is done collecting in this example?


There was a PR about this ages ago.

But one thing to consider is that keeping threads around not doing 
anything doesn't cost anything. But spinning up will cost something.


So it is debatable if it is a good idea to get rid of them once done 
(even if delayed).


Re: Name mangling problem with tiny Windows 10 load-time DLL example

2021-03-01 Thread Siemargl via Digitalmars-d-learn

On Sunday, 28 February 2021 at 23:00:56 UTC, WhatMeWorry wrote:

On Sunday, 28 February 2021 at 22:10:21 UTC, Siemargl wrote:

On Sunday, 28 February 2021 at 18:29:11 UTC, WhatMeWorry wrote:
It seems pretty obvious the problem is with name mangling. 
But how to fix it?



fixing

   int numb = 1;


and your example work correct

ldc 1.24 / win10

P.S.I'm not recommend using such keywords as 'file', may cross 
with other modules.


I double checked my posting and of course works it now 
works!?!?  I've been having trouble where it works and then it 
doesn't. I've been using examples with file.d, file1.d, 
file2.d, etc.  I also came across the note that Windows file 
system is not case sensitive. Or is that case in-sensitive?


This worked fine for Linux (Ubuntu) so you might be on to 
something.


Win10. Just try delete all obj, dll, lib and do full recompile 
from scratch.


module patron;
import file;
void main()
{
import std.stdio;
int numb = 1;
writeln("mangled name of addOne is ", addOne.mangleof);
numb = addOne(numb);
writeln(numb);
}

-
E:\VSProjects\testjunk\D_load_dll>patron.exe  
  
  
 mangled name of addOne is _D4file6addOneFiZi 
  
  
  2





Re: tiny alternative to std library

2021-03-01 Thread Imperatorn via Digitalmars-d-learn

On Thursday, 25 February 2021 at 22:39:11 UTC, Anthony wrote:

Hello,

I noticed that importing some std libraries causes the build 
time to jump to around 1 - 3 secs.


I started creating my own helper functions to avoid importing 
std for scripting and prototyping in order to keep the compile 
time at around 0.5 secs.


I was wondering if anyone knows of any libraries that are 
geared towards something like this?


Thanks


What part of std? Have you tried selective imports?