Re: get element index when using each!(x)

2020-09-16 Thread dangbinghoo via Digitalmars-d-learn

On Thursday, 17 September 2020 at 03:16:42 UTC, Paul Backus wrote:

On Thursday, 17 September 2020 at 03:14:08 UTC, JG wrote:


Perhaps there are other ways, but you can use enumerate. For 
example

---
import std.algorithm;
import std.range;
import std.stdio;
void main() {
 string s = "hello";
 s.enumerate.each!(x=>writeln(x[0],":",x[1]));
}


Worth knowing that the tuples you get from enumerate actually 
have named members, so you can write:


s.enumerate.each!(x => writeln(x.index, ":", x.value));

Documentation: 
http://dpldocs.info/experimental-docs/std.range.enumerate.html


thanks you! and thanks to JG.

-
binghoo


get element index when using each!(x)

2020-09-16 Thread dangbinghoo via Digitalmars-d-learn

hi,

is there any way to get the index for an element when iteration 
using each!(x)?


 I know I can do this using foreach statement, but I prefer using 
the each template.


---
string s = "hello";
foreach(i, c; s) {
}
--

how can I get to ?


Thanks!

binghoo dang


Re: Does std.net.curl: download have support for callbacks?

2020-06-17 Thread dangbinghoo via Digitalmars-d-learn

On Thursday, 11 June 2020 at 06:13:59 UTC, adnan338 wrote:

On Thursday, 11 June 2020 at 06:05:09 UTC, adnan338 wrote:
I would like to set a callback for the `download()` function 
but I do not seem to find a way to add a callback to the 
procedure.


[...]


I have also been told that Gtk is not thread safe. What does 
this mean and does it effect me on this scenario?


Don't worry, almost ALL GUI FRAMEWORK in the world IS NOT THREAD 
SAFE, the wellknow Qt and Gtk, and even morden Android and the 
java Swing.




binghoo dang




Re: GUI library for DMD 2.090 or DMD 2.091

2020-04-26 Thread dangbinghoo via Digitalmars-d-learn

On Friday, 24 April 2020 at 13:45:22 UTC, Phrozen wrote:
I'm too new to DLang and I have a lot to learn. Probably that's 
why I have a lot of difficulties. Has anyone tried using a GUI 
library to the latest DMD 2.090 or DMD 2.091? I plan to use 
this language for a specific Thermal calculator application for 
Windows, but for two days I've been struggling with dub and 
elementary examples in GUI libraries. I need something simple - 
a modal window with 3 buttons and a two text boxes. So far I 
have tested DWT, TKD, DFL, dlangui without success.
Can anyone help me with advice or some more recent tutorial. 
Thank you!


working GUI library for D:

Gtkd and tkd.


---
dbh.


Re: Best way to learn 2d games with D?

2020-03-19 Thread dangbinghoo via Digitalmars-d-learn
On Sunday, 15 March 2020 at 17:58:58 UTC, Steven Schveighoffer 
wrote:
I want to try and learn how to write 2d games. I'd prefer to do 
it with D.


I've found a ton of tutorials on learning 2d gaming with other 
languages. Is there a place to look that uses D for learning? 
Should I just start with another language and then migrate to D 
later? Anyone recommend any specific tutorial/book?


-Steve


there's a youtube channel teaching 2D game dev. using dlang:

https://www.youtube.com/channel/UCK3fxU3_7tzBhZZ_6rljAQA/videos


Re: Using LDC2 on ARM

2020-03-02 Thread dangbinghoo via Digitalmars-d-learn

On Monday, 2 March 2020 at 17:45:26 UTC, Severin Teona wrote:

Hello,

I am working on a project that uses a Raspberry Pi (armv7l) and 
the latest LDC version I found for this architecture is 1.13.0. 
Can you help me install the latest version(1.20.0)?


Also, I'm having problems using the DPP package with the 1.13.0 
LDC version, most likely because the latest version of 
DPP(0.4.1) is using a newer version of Phobos.


Is there any reason why the LDC team stopped releasing 
pre-built binaries for arm?


I'm looking forward to your help.
Teona.


please refer to 
https://wiki.dlang.org/Programming_in_D_tutorial_on_Embedded_Linux_ARM_devices


you can build your own LDC toolchain always using the latest.


Re: Is there any writeln like functions without GC?

2019-11-10 Thread dangbinghoo via Digitalmars-d-learn

On Sunday, 3 November 2019 at 05:46:53 UTC, 9il wrote:

On Thursday, 31 October 2019 at 03:56:56 UTC, lili wrote:

Hi:
   why writeln need GC?


See also Mir's @nogc formatting module

https://github.com/libmir/mir-runtime/blob/master/source/mir/format.d


hi, is mir right now fully implemented using betterC?

thanks!
--
binghoo


Re: is the runtime implemented in betterC?

2019-11-09 Thread dangbinghoo via Digitalmars-d-learn

On Saturday, 9 November 2019 at 22:46:16 UTC, kinke wrote:
druntime depends on OS, architecture and coupled C runtime - 
what OS are you going to target?


thank you all first! I just made a basic mistake and didn't 
realized that druntime is just libraries and onlymatter when 
linking the final executebals.


and for xtensa cpu, most used chip is the esp32 mcu, it only has 
support of freeRTOS, and implemented just few posix api for stdio 
and threads.


so, basically i can only use betterC set of normal D.

thanks!


Re: is the runtime implemented in betterC?

2019-11-08 Thread dangbinghoo via Digitalmars-d-learn

On Friday, 8 November 2019 at 13:52:18 UTC, kinke wrote:

On Friday, 8 November 2019 at 10:40:15 UTC, dangbinghoo wrote:

hi,


I'm not sure what you are trying to achieve; you can easily 
cross-compile druntime & Phobos with LDC, see 
https://wiki.dlang.org/Building_LDC_runtime_libraries.


hmm, if runtime is implemented in regular D, how could the 
regular D code depends on regular D runtime be compiled when we 
doesn't have a D runtime even exists? thinking thant we just have 
xtensa-llvm, and building ldc for xtensa CPU,  the runtime will 
simply just not compiled.


it's an egg-chicken problem?


--
thanks!




is the runtime implemented in betterC?

2019-11-08 Thread dangbinghoo via Digitalmars-d-learn

hi,

is the runtime d code implemented purely with betterC?

i was thinking that what's happening when we building ARM dlang 
compiler, when the dlang compiler ready in the first, there's no 
ARM version of the runtime lib and phobos, so, it's likely we are 
using bare metal D and trying to build the runtime.


is this true?


thanks!

---
binghoo


can we use D to programming ESP32?

2019-07-10 Thread dangbinghoo via Digitalmars-d-learn

hi there,

Does anyone know what's D's status for ESP32?

I just getting started a few days programming with ESP32, and 
found the official esp-idf SDK even get CPP enabled by default, 
and this makes the HelloWorld app used 160KB of flash. What I 
want to talk is that ESP32 might be a powerful Embedded 
Controller for running D.


And It seems that gcc already support Xtensa arch, maybe gdc 
works with ESP32.



thanks!

--
binghoo dang


Re: make C is scriptable like D

2019-06-21 Thread dangbinghoo via Digitalmars-d-learn

On Thursday, 20 June 2019 at 16:55:01 UTC, Jonathan Marler wrote:

On Thursday, 20 June 2019 at 06:20:17 UTC, dangbinghoo wrote:

[...]


rdmd adds a few different features as well, but the bigger 
thing it does is cache the results in a global temporary 
directory.  So If you run rdmd on the same file with the same 
options twice, the second time it won't compile anything, it 
will detect that it was already compiled and just run it.


great! thanks.


Re: is there any micro-service library in D?

2019-06-20 Thread dangbinghoo via Digitalmars-d-learn

On Wednesday, 19 June 2019 at 11:19:17 UTC, Marco de Wild wrote:

On Wednesday, 19 June 2019 at 08:29:15 UTC, dangbinghoo wrote:

hi there,

Does anyone know the micro-service oriented design library or 
framework in D?



thanks!

binghoo dang


What do you need from such a library?

Some suggestions:

For networking, there is vibe.d[0] which provides both a client 
and a server REST (or web) interface. There is also 
GraphQL-D[1] that provides a server-side GraphQL interface that 
can be used by other services.


For modelling, there is Depend[2], which visualises 
dependencies.


[0] http://code.dlang.org/packages/vibe-d
[1] http://code.dlang.org/packages/graphqld
[2] http://code.dlang.org/packages/depend


thanks! I want to write a LoRaWAN NS server, and want all module 
is sit in like a independent service[1]. Or, more generally and 
big thing like java's OSGI.


thanks!

[1] : 
http://www.orocos.org/stable/documentation/rtt/v2.x/doc-xml/orocos-components-manual.html#idp3264320







make C is scriptable like D

2019-06-20 Thread dangbinghoo via Digitalmars-d-learn

hi there,

a funny thing:


$ cat rgcc
#!/bin/sh
cf=$@
mycf=__`echo $cf|xargs basename`
cat $cf | sed '1d'  > ${mycf}
gcc ${mycf} -o a.out
rm ${mycf}
./a.out

$ cat test.c
#!/home/user/rgcc
#include 
int main()
{
printf("hello\n");
}


And then,


chmod +x test.c
./test.c


output hello.

is rdmd implemented similarly?

thanks!


binghoo



is there any micro-service library in D?

2019-06-19 Thread dangbinghoo via Digitalmars-d-learn

hi there,

Does anyone know the micro-service oriented design library or 
framework in D?



thanks!

binghoo dang


Re: D compiler need -nogc witch and document of library also need nogc button

2019-06-11 Thread dangbinghoo via Digitalmars-d-learn

On Tuesday, 11 June 2019 at 10:24:05 UTC, KnightMare wrote:

On Tuesday, 11 June 2019 at 08:05:31 UTC, dangbinghoo wrote:
I think that D compiler needs -nogc switch to fully disable gc 
for a project,



LDC -nogc?



thanks for help. It's a shame that I didn't look in details of 
the LCD help info.

Yeah, the great LDC already support this!

Thanks!

---
binghoo dang




Re: D compiler need -nogc witch and document of library also need nogc button

2019-06-11 Thread dangbinghoo via Digitalmars-d-learn

On Tuesday, 11 June 2019 at 12:40:39 UTC, Adam D. Ruppe wrote:

On Tuesday, 11 June 2019 at 08:59:01 UTC, dangbinghoo wrote:
We need to make sure we use only @nogc API when writing code, 
not when running the app.


That's what the @nogc annotation does, statically forces you to 
only use other @nogc stuff via compiler errors.


yeah, @nogc does the job. But the problem is that, you need to 
mark all functions, classes, everything you write to manually 
marked, so if compiler supports -nogc, it will helps great.



-
binghoo dang


Re: D compiler need -nogc witch and document of library also need nogc button

2019-06-11 Thread dangbinghoo via Digitalmars-d-learn

On Tuesday, 11 June 2019 at 08:16:31 UTC, Basile B. wrote:

On Tuesday, 11 June 2019 at 08:08:14 UTC, Basile B. wrote:




you can do this with a druntime switch or by calling GC.disable
 in your main()


the druntime switch is "--DRT-gc=gc:manual". You pass it the 
compiled program after its own args.


thanks, I know this from dlang.org. But this is not useful when 
trying to write @nogc code for a project.


We need to make sure we use only @nogc API when writing code, not 
when running the app.



Thanks!



binghoo dang


D compiler need -nogc witch and document of library also need nogc button

2019-06-11 Thread dangbinghoo via Digitalmars-d-learn

hi there,

I think that D compiler needs -nogc switch to fully disable gc 
for a project, and document of phobos also needs a friendly way 
to list-out all @nogc API.


we already have -betterC, and betterC disabled GC, why we could 
not have a standalone option for doing this?





binghoo dang


Re: Create object from a library's Class returns Null

2019-05-29 Thread dangbinghoo via Digitalmars-d-learn



change gwlib buildtype to sourceLibrary solves the problem, but 
it should work for static or shared library.


Re: Create object from a library's Class returns Null

2019-05-28 Thread dangbinghoo via Digitalmars-d-learn

On Wednesday, 29 May 2019 at 05:04:54 UTC, dangbinghoo wrote:

On Wednesday, 29 May 2019 at 02:42:23 UTC, Adam D. Ruppe wrote:
Object.factory is pretty unreliable and has few supporters 
among the developers. I wouldn't suggest relying on it and 
instead building your own factory functions.


oh, that's bad news, but the hibernated library is using this 
feature. what should I do with this?


now we found that, class from a module library won't work, if I 
move gwlib to testobj/source, it works.


Re: Create object from a library's Class returns Null

2019-05-28 Thread dangbinghoo via Digitalmars-d-learn

On Wednesday, 29 May 2019 at 02:42:23 UTC, Adam D. Ruppe wrote:
Object.factory is pretty unreliable and has few supporters 
among the developers. I wouldn't suggest relying on it and 
instead building your own factory functions.


oh, that's bad news, but the hibernated library is using this 
feature. what should I do with this?


Re: Create object from a library's Class returns Null

2019-05-28 Thread dangbinghoo via Digitalmars-d-learn

On Tuesday, 28 May 2019 at 14:24:30 UTC, dangbinghoo wrote:

On Tuesday, 28 May 2019 at 14:16:44 UTC, Nick Treleaven wrote:

On Tuesday, 28 May 2019 at 09:25:51 UTC, dangbinghoo wrote:




yeah, I made a typo mistake in the forum post, but the code in 
github repo is really with no typo problem.


This seems to be a serious problem, I found it works when I 
using Ldc2 1.12 version even on ARM target.


hi there,

Anyone help with this?

Not a typo problem, even this
---
writeln(Object.factory(ns.toString()));
---

result in `null`.

just try the github demo project:

https://github.com/dangbinghoo/DObjectCreatTest.git



Thanks!
---
binghoo dang


Re: Create object from a library's Class returns Null

2019-05-28 Thread dangbinghoo via Digitalmars-d-learn

On Tuesday, 28 May 2019 at 14:16:44 UTC, Nick Treleaven wrote:

On Tuesday, 28 May 2019 at 09:25:51 UTC, dangbinghoo wrote:


class NSconf
{
String name;
...
}


Does this class have a non-default constructor?


yes, I didn't provide constructor, as Class will have a default 
one if not supplied.



Typo, should be NSconf.


yeah, I made a typo mistake in the forum post, but the code in 
github repo is really with no typo problem.


This seems to be a serious problem, I found it works when I using 
Ldc2 1.12 version even on ARM target.





Create object from a library's Class returns Null

2019-05-28 Thread dangbinghoo via Digitalmars-d-learn

hi there,

I have a set of DB entity class in a library and creating Object 
from another project which linked with the library returns Null.


I don't know what's wrong there.

the source is like this:

  a. I have a library with such a structure:
 gwlib/source/gwlib/entity/nsconf.d

with content:

   --
module gwlib.entity.nsconf;

class NSconf
{
String name;
...
}
   --

  b. I use this gwlib library in another project named testobj

 testobj/source/app.d :

--
 import gwlib.entity.nsconf;

 void main()
 {
  writeln(Object.factory("gwlib.entity.nsconf.NSConf"));
 }
--

 this print out `null`.

dub file cofig is :
-
"dependencies": {
"gwlib": {"path":"../gwlib"}
},
-

And I just tested with DMD and LDC2, the result is a little 
different, but all the two is returning a null object.


I don't know what's the reason.


Could someone help with this? Thanks!

  > I posted the dub version of the whole project on github:
https://github.com/dangbinghoo/DObjectCreatTest
one can just clone and reproduce the result.


---
binghoo dang



Re: compiler does not detect accessing on null class object.

2019-05-27 Thread dangbinghoo via Digitalmars-d-learn

On Monday, 27 May 2019 at 15:29:32 UTC, Daniel Kozak wrote:

On Monday, 27 May 2019 at 15:13:00 UTC, dangbinghoo wrote:

hello,




1.)
Yes this is by design. It is not easy to detect this at compile 
time.

It does not break safety

2.)
https://dlang.org/spec/function.html#function-safety
https://dlang.org/spec/memory-safe-d.html
https://dlang.org/articles/safed.html#safed-subset


thanks a lot.

so, The SafeD Subset consists of [function-safety, memory-safety].


compiler does not detect accessing on null class object.

2019-05-27 Thread dangbinghoo via Digitalmars-d-learn

hello,

code below:
-
class a  {
string a1;
}

a a1;
writeln(a1.a1);
-

compiles and produce "core dump" or "segfault", does this fit the 
original D design? why the compiler does not detect for accessing 
a null object and refused to compile?




And, 2nd question: where can I find the Subset spec of SafeD?


Thanks!

--
binghoo dang


Re: Logging best practices

2019-04-26 Thread dangbinghoo via Digitalmars-d-learn

On Friday, 26 April 2019 at 08:10:33 UTC, Bastiaan Veelo wrote:

std.experimental has been already moved to std.


Are you sure about that? 
https://github.com/dlang/phobos/tree/master/std
I think you are confusing the package std.experimental.all that 
moved to std. It means you can now import all of Phobos by 
doing `import std;` instead of `import std.experimental.all;`. 
It does not mean that everything below std.experimental moved 
to std and thereby lost its experimental status.


Bastiaan.


yes, you're right, I just made a misunderstanding.

Thanks!


Re: Logging best practices

2019-04-25 Thread dangbinghoo via Digitalmars-d-learn
On Thursday, 25 April 2019 at 10:33:00 UTC, Vladimirs Nordholm 
wrote:

Hello.

Is there a current "Best Practices" for logging in D?

For the actual logging, I know of `std.experimental.logger`. 
However, the `experimental` has kept me away from it.


Is it good, or are there any better alternatives?


for the latest alpha version of D release, all std.experimental 
has been already moved to std.


so, just don't be afraid! ~_^


-
binghoo dang


Re: How to do alias to a C struct member?

2019-04-22 Thread dangbinghoo via Digitalmars-d-learn

On Monday, 22 April 2019 at 15:50:11 UTC, dangbinghoo wrote:

On Monday, 22 April 2019 at 13:10:45 UTC, Adam D. Ruppe wrote:

On Monday, 22 April 2019 at 11:04:49 UTC, dangbinghoo wrote:

alias ifr_ifrn.ifrn_nameifr_name; /* interface name */

So, how to do alias for a C struct member?



D doesn't support this kind of alias. There's two options:



Then you should be able to use it the same way as in C.


OK, I'd prefer with option 2.
thank you in advance!


hi all,

the correct answer is :

---
struct ifreq {
private union ifr_ifrn_ {
byte[IFNAMSIZ] ifrn_name; /* if name, e.g. "en0" */   
}
ifr_ifrn_ ifr_ifrn;

private union ifr_ifru_ {
sockaddr ifru_addr;
sockaddr ifru_dstaddr;
sockaddr ifru_broadaddr;
sockaddr ifru_netmask;
sockaddr ifru_hwaddr;
short   ifru_flags;
int ifru_ivalue;
int ifru_mtu;
ifmap ifru_map;
byte[IFNAMSIZ] ifru_slave;  /* Just fits the size */
byte[IFNAMSIZ] ifru_newname;
byte * ifru_data;
}
ifr_ifru_ ifr_ifru;

	// NOTE: alias will not work : alias ifr_ifrn.ifrn_name	
ifr_name;
	@property ref ifr_name() { return ifr_ifrn.ifrn_name; } /* 
interface name */

---

the `need this` error is telling that `ifr_ifrn` is not an 
instance but a type for my previous code.


so for C struct's union member, we need to first declare a member 
of that union type, and then using property to implement The 
C-Macro.



but here I have a question in further:

 As showing above, ifreq has a member of ``byte[IFNAMSIZ] 
ifrn_name;``, when translating the C style calling code, I need 
to do such a cast for D byte:


  ```
 strcpy(cast(char *)ifr.ifr_name.ptr, 
std.string.toStringz(if_name));

 if (ioctl(s, SIOCGIFHWADDR, ) < 0)
 {
return;
 }
  ```
should I keep the `ifrn_name` to a `char[]` for avoid of doing 
cast D byte to C (char*) ? and I can calling like this:


  ```
struct ifreq {
private union ifr_ifrn_ {
char[IFNAMSIZ] ifrn_name; /* if name, e.g. "en0" */   
}
  ...

 strcpy(ifr.ifr_name.ptr, std.string.toStringz(if_name));
 if (ioctl(s, SIOCGIFHWADDR, ) < 0)
 {
return;
 }

  ```
this looks more clean and like the C style code.


--
Thanks!

Binghoo Dang



Re: How to do alias to a C struct member?

2019-04-22 Thread dangbinghoo via Digitalmars-d-learn
On Monday, 22 April 2019 at 15:45:52 UTC, Arun Chandrasekaran 
wrote:

On Monday, 22 April 2019 at 11:04:49 UTC, dangbinghoo wrote:

hi all,

as now we don't have the net/if.h binding, I need to do struct 
ifreq binding myself, here's my code:


[...]


Looks like we both were working on the same thing, few hours 
apart. 
https://forum.dlang.org/post/nkbnknlgmcwaivppm...@forum.dlang.org


yeah, I was doing that 4 hours ago! ^_^


Re: How to do alias to a C struct member?

2019-04-22 Thread dangbinghoo via Digitalmars-d-learn

On Monday, 22 April 2019 at 13:10:45 UTC, Adam D. Ruppe wrote:

On Monday, 22 April 2019 at 11:04:49 UTC, dangbinghoo wrote:

alias ifr_ifrn.ifrn_nameifr_name; /* interface name */

So, how to do alias for a C struct member?



D doesn't support this kind of alias. There's two options:

1) just write the full name in the code.

ifreq ifr;

ifr.ifr_ifrn.ifrn_name /* instead of ifr.ifrn_name */

or, if you are linking in the D module containing the 
translated headers (if you don't link it in, this will cause 
missing symbol linker errors!)


2) write ref property functions to get to it, using ufcs for 
the middle. So replace that *alias* line with:


@property ref ifr_name(ifreq this_) { return 
this_.ifr_ifrn.ifrn_name; }



Then you should be able to use it the same way as in C.


OK, I'd prefer with option 2.
thank you in advance!


How to do alias to a C struct member?

2019-04-22 Thread dangbinghoo via Digitalmars-d-learn

hi all,

as now we don't have the net/if.h binding, I need to do struct 
ifreq binding myself, here's my code:



struct ifreq {
private union ifr_ifrn {
byte[IFNAMSIZ] ifrn_name; /* if name, e.g. "en0" */   
}

private union ifr_ifru {
sockaddr ifru_addr;
sockaddr ifru_dstaddr;
sockaddr ifru_broadaddr;
sockaddr ifru_netmask;
sockaddr ifru_hwaddr;
short   ifru_flags;
int ifru_ivalue;
int ifru_mtu;
ifmap ifru_map;
byte[IFNAMSIZ] ifru_slave;  /* Just fits the size */
byte[IFNAMSIZ] ifru_newname;
byte * ifru_data;
}

alias ifr_ifrn.ifrn_nameifr_name; /* interface name */
alias ifr_ifru.ifru_hwaddr  ifr_hwaddr;   /* MAC address
*/
alias ifr_ifru.ifru_addrifr_addr; /* address*/
alias ifr_ifru.ifru_dstaddr	ifr_dstaddr;  /* other end of p-p 
lnk	*/
alias ifr_ifru.ifru_broadaddr	ifr_broadaddr;/* broadcast 
address	*/
alias ifr_ifru.ifru_netmask	ifr_netmask;  /* interface net 
mask	*/

alias ifr_ifru.ifru_flags   ifr_flags;/* flags  */
alias ifr_ifru.ifru_ivalue  ifr_metric;   /* metric */
alias ifr_ifru.ifru_mtu ifr_mtu;  /* mtu*/
alias ifr_ifru.ifru_map ifr_map;  /* device map */
alias ifr_ifru.ifru_slave   ifr_slave;/* slave device   
*/
alias ifr_ifru.ifru_data	ifr_data;	  /* for use by 
interface	*/
alias ifr_ifru.ifru_ivalue  ifr_ifindex;  /* interface index  
*/

alias ifr_ifru.ifru_ivalue  ifr_bandwidth;/* link bandwidth */
alias ifr_ifru.ifru_ivalue  ifr_qlen; /* queue length   
*/
alias ifr_ifru.ifru_newname ifr_newname;  /* New name   */
}
---

as show above we need to trun the C code

# define ifr_name   ifr_ifrn.ifrn_name  /* interface name   */

to D's alias, but when done the binding and trying to compiling 
this code:


---
import core.sys.posix.sys.socket;
import core.sys.posix.sys.ioctl;
import core.sys.posix.arpa.inet;

import core.stdc.string;
import core.stdc.stdio;
import core.sys.posix.stdio;
import core.stdc.errno;
import std.string;

..
ifreq ifr;

strcpy(ifr.ifr_name, std.string.toStringz(if_name)); //line 172
if (ioctl(s, SIOCGIFHWADDR, ) < 0)
{
return;
}
---

DMD compiler gives an error :
```
/test.d(172): Error: need this for ifrn_name of type byte[16]
./test.d(172): Error: function core.stdc.string.strcpy(return 
scope char* s1, scope const(char*) s2) is not callable using 
argument types (_error_, immutable(char)*)
./test.d(172):cannot pass argument __error of type 
_error_ to parameter return scope char* s1

```

So, how to do alias for a C struct member?


thanks!

Binghoo Dang


Re: could someone test support for Asian languages in nanogui port?

2018-12-07 Thread dangbinghoo via Digitalmars-d-learn

On Sunday, 6 May 2018 at 11:18:17 UTC, drug wrote:

On 06.05.2018 06:10, Binghoo Dang wrote:


hi,

I'm a Chinese, and I just have done the test. I also copied 
some Japanese text from Dlang twitter channel and added some 
Chinese wide punctuation Char.


And It's all seems displayed correctly.

The resulting screenshot is here: 
https://pasteboard.co/HjRmOYg.png


The only problem is that the font style simply looks strange. 
You can see the 'normal' text display in Win10 by default like 
this: https://pasteboard.co/HjRrigh.png


Can it fixed by other font or there are some other problems?



yeah, the bad font display can be resolved after setting a CJK 
font(I just replaced with msyh.ttf).


the result is like this: https://pasteboard.co/HQBdP14.png

thanks!





Re: D vs perl6

2018-11-22 Thread dangbinghoo via Digitalmars-d-learn
On Thursday, 22 November 2018 at 09:03:19 UTC, Gary Willoughby 
wrote:

On Monday, 19 November 2018 at 06:46:55 UTC, dangbinghoo wrote:
So, can you experts give a more comprehensive compare with 
perl6 and D?


Sure!

1). You can actually read and understand D code.


^_^, yeah, you're right.

D code is much simpler, but it's said that perl6 is a new design 
with great modeling power.


But what I think about is that: both D and perl6 have a very long 
compiler development time, and both have few users.


after reading the perl6 official document, I finally found that D 
has most of what the perl6 says it's modern powerful features, 
and then D compiles native code, we can write simple and clean 
code, and runs fast.


D vs perl6

2018-11-18 Thread dangbinghoo via Digitalmars-d-learn

hi,

What if D compared with the latest perl6? well, I know that perl6 
is a VM targeted language. so which has the greater 
modeling-power? And perl6 seems is selling for Concurrency[1], 
but I think D will do this far better than a VM targeted 
language, right?


with the pre-released version of perl6 publicity, perl6 will be a 
powerful language with features like "lazy and eager list 
evaluation", but after learned D, look back to perl6, I found 
very few things that means "powerful".


So, can you experts give a more comprehensive compare with perl6 
and D?  speed? modeling-power? concurrency? package-management 
dub vs CPAN? ...


Thanks!

[1]: https://www.evanmiller.org/why-im-learning-perl-6.html


Re: Building GUI projects with D

2018-10-21 Thread dangbinghoo via Digitalmars-d-learn

On Saturday, 20 October 2018 at 15:40:07 UTC, karis njiru wrote:
Hi. Am a computer science student from Kenya and decided to use 
D for my class project on Principles of Programming Languages. 
Am having a lot of fun with D but have come across an issue. I 
have been using Visual D for the past 2 months for my coding 
but after a lot of research i found out that i cannot build GUI 
projects with visual D. So i took on Entice Designer which for 
the past week has been a nightmare for me to compile my code 
error being the system cannot find the path in the command 
prompt specified. I have installed DMD and DFL lots of times 
but there is still the same issue. Please help


try GtkD or dlangui(UTF8 support is not complete, font rendering 
is a little bad.) or tkd


Re: assigment to null class object member compiled? is this a bug?

2018-10-21 Thread dangbinghoo via Digitalmars-d-learn

On Friday, 19 October 2018 at 09:08:32 UTC, Vijay Nayar wrote:
Technically the code you have is syntactically correct.  You 
are permitted to create a class variable without assigning it 
to a class object.  (Assigning it to a class object would look 
like "A a = new A();")


Which section of The D Programming Language book makes you 
think this would not compile?  I have the book as well, but I'm 
not quite sure what part of the book you're referring to.


the section 6.2, which is
---
A a;
a.x = 5;
---

the book explained this should be refused to compile.


thanks!

--
dangbinghoo


assigment to null class object member compiled? is this a bug?

2018-10-19 Thread dangbinghoo via Digitalmars-d-learn

hi,

why the code bellow compiles?

---
import std.stdio;
class A {
int m;
}

void main() {
A a;
a.m = 1;
}
---

and running this code get:

`segmentation fault (core dumped)  ./test`

I consider this couldn't be compiled according to book Programming Language>.


The latest dmd (2.082) and LDC2 behaves the same.


Re: Documents about ddoc? and markdown in ddoc?

2018-10-18 Thread dangbinghoo via Digitalmars-d-learn
On Thursday, 18 October 2018 at 05:59:36 UTC, rikki cattermole 
wrote:

On 18/10/2018 6:38 PM, dangbinghoo wrote:

hi,

Is there any other documents related about ddoc usage? the 
only thing I can find is:


 
 https://dlang.org/spec/ddoc.html#using_ddoc_to_generate_examples


But I found it never mentioned something like $(LI a  list 
item), is there a full ddoc document available?


Default for html output: 
https://github.com/dlang/dmd/blob/master/res/default_ddoc_theme.ddoc



And, is there any info about using markdown in ddoc?


Not possible.


thanks for your reply.

and sorry, I'm too careless for reading the documents
https://dlang.org/spec/ddoc.html#using_ddoc_to_generate_examples
the $(LI x y) is a macro which was mentioned.




Documents about ddoc? and markdown in ddoc?

2018-10-17 Thread dangbinghoo via Digitalmars-d-learn

hi,

Is there any other documents related about ddoc usage? the only 
thing I can find is:


 https://dlang.org/spec/ddoc.html#using_ddoc_to_generate_examples

But I found it never mentioned something like $(LI a  list item), 
is there a full ddoc document available?


And, is there any info about using markdown in ddoc?

thanks!

---
dangbinghoo





Re: is there something like `stm32-rs` in D?

2018-09-26 Thread dangbinghoo via Digitalmars-d-learn

On Wednesday, 26 September 2018 at 05:24:08 UTC, Radu wrote:
On Wednesday, 26 September 2018 at 03:46:21 UTC, dangbinghoo 
wrote:

hi,

https://github.com/adamgreig/stm32-rs looks great, is there 
something like this in Dlang?


thanks!
---
dangbinghoo


You might take a look at

https://github.com/JinShil/stm32f42_discovery_demo
and
https://github.com/JinShil/stm32_datasheet_to_d


thanks, Radu, I knew that there's a minimal D demo on STM32 exist 
for years. But, what I'm talking about is that rust community is 
doing a rust library for very production use. If you look at 
stm32-rs, you will found that stm32-rs is covering the whole 
STM32 MCU product line and making a promising peripherals library.


The library was generated using CMSIS-SVD files which were 
maintained by MCU vendors.


Anyway, I don't know what's the runtime size situation D vs rust. 
for those kinds of MCU devices, a runtime code size greater than 
5KB may even not suitable for  L0 lines MCU from ST.


It's not quite clear that whether D or rust is valuable for MCU 
development, but C is really lacking lots of things for quick 
development, today MCU is interfacing more IoT modules using AT 
command, and deal with these string things is quite painful in C. 
Maybe this is an opportunity for D?


Thanks!

---
dangbinghoo


is there something like `stm32-rs` in D?

2018-09-25 Thread dangbinghoo via Digitalmars-d-learn

hi,

https://github.com/adamgreig/stm32-rs looks great, is there 
something like this in Dlang?


thanks!
---
dangbinghoo



Re: SerialPort

2018-09-23 Thread dangbinghoo via Digitalmars-d-learn

On Thursday, 20 September 2018 at 10:51:52 UTC, braboar wrote:
I am going to play with serial port read/write, so I fetched 
serial-port. After that, I wrote simple program:


auto port_name = "/dev/ttyUSB1";
auto reader = new SerialPort(port_name);
reader.dataBits(DataBits.data8);
reader.stopBits(StopBits.one);
reader.parity(Parity.none);
reader.speed(BaudRate.BR_230400);
string[] income;
reader.read(income);

and the result is

serial.device.TimeoutException


Can anybody give me a guide of using serial port?

And one more question: how to outline code blocks? ''' or --- 
can't help me.


here is my code really works:

com is `reader` object in your code.

```
void writeBytes(ubyte[] arr)
{
com.write(arr);
}

void serialThread()
{
ubyte[500] buff;

running = true;
while (running)
{
string str;
size_t readed;

try
{
readed = com.read(buff);
// if (readed > 0) {
//writeln("com port readed " ~ 
std.conv.to!string(readed));

str = cast(string)(buff[0 .. readed]).idup;
// Don't use writeln for console or string serail 
application.

write(str);
// }
}
// must catch for continous reading, otherwize, com 
port will block.

catch (TimeoutException e)
{
}
   }
}
```

thanks!


Re: DMD32 compiling gtkd out of memory on 32bit Windows 7 machine

2018-09-16 Thread dangbinghoo via Digitalmars-d-learn

On Friday, 14 September 2018 at 17:34:59 UTC, Mike Wey wrote:


You will also have to pass `--build=plain` to dub because of a 
optlink bug.


https://issues.dlang.org/show_bug.cgi?id=15418


thanks Mike,

I tried using `--build-plain`, optlink didn't report out of 
memory, but it hangs !


```
Compiling source\utils.d...
Linking...
OPTLINK (R) for Win32  Release 8.00.17
Copyright (C) Digital Mars 1989-2013  All rights reserved.
http://www.digitalmars.com/ctg/optlink.html
OPTLINK : Warning 9: Unknown Option : LLIB
OPTLINK : Warning 9: Unknown Option : WIN32
C:\Users\Administrator.USER-20180912OL\AppData\Local\dub\packages\gtk-d-3.8.3\gtk-d\.dub\build\library-plain-windows-x86-dmd_2082-BF70B0A83AEE3E77C0F6B230586D03B2\gtkd-3.lib
 Warning 178: .LIB pagesize exceeds 512
```

my building command is ` dub build --compiler=dmd -a=x86  
-c=windows --build-mode=singleFile --build=plain --force`


Thanks !


Re: DMD32 compiling gtkd out of memory on 32bit Windows 7 machine

2018-09-13 Thread dangbinghoo via Digitalmars-d-learn

On Wednesday, 12 September 2018 at 15:13:36 UTC, Timoses wrote:


try `dub --build-mode=singleFile` ? I believe this will compile 
each file and then link them together (instead of compiling it 
all together what dub does, afaik).
There's been another topic on memory consumption of compilation 
[1].


[1]: 
https://forum.dlang.org/post/ehyfilopozdndjdah...@forum.dlang.org


thanks timoses ,

singleFile mode works for building, but when linking, I got this:

--
OPTLINK (R) for Win32  Release 8.00.17
Copyright (C) Digital Mars 1989-2013  All rights reserved.
http://www.digitalmars.com/ctg/optlink.html
OPTLINK : Warning 9: Unknown Option : LLIB
OPTLINK : Warning 9: Unknown Option : WIN32
C:\Users\Administrator.USER-20180912OL\AppData\Local\dub\packages\gtk-d-3.8.3\gtk-d\.dub\build\library-debug-windows-x86-dmd_2082-9C5C1D99F672708E9D6D6FE9E60296B4\gtkd-3.lib
 Warning 178: .LIB pagesize exceeds 512
C:\Users\Administrator.USER-20180912OL\AppData\Local\dub\packages\gtk-d-3.8.3\gtk-d\.dub\build\library-debug-windows-x86-dmd_2082-9C5C1D99F672708E9D6D6FE9E60296B4\gtkd-3.lib
 Error 7: Out of Memory
Error: linker exited with status 1
dmd failed with exit code 1.
---

I think that DMD should give up it's DMC linkers, using MinGW ld 
instead. DMC linker is not even a working linker.





DMD32 compiling gtkd out of memory on 32bit Windows 7 machine

2018-09-12 Thread dangbinghoo via Digitalmars-d-learn

hi ,

When compiling gtkd using dub, dmd32 reported "Out for memory" 
and exit.


OS: Windows 7 32bit.
RAM : 3GB
DMD version: v2.0.82.0 32bit.

No VC or Windows SDK installed, when setting up dmd, I selected 
install vc2010 and use mingw lib.


Re: help on how to wrap a C macros when binding linux/spi/spidev.h

2018-03-29 Thread dangbinghoo via Digitalmars-d-learn

On Thursday, 29 March 2018 at 09:16:11 UTC, dangbinghoo wrote:

On Thursday, 29 March 2018 at 09:13:27 UTC, dangbinghoo wrote:
On Thursday, 29 March 2018 at 09:02:16 UTC, Nicholas Wilson 
wrote:

On Thursday, 29 March 2018 at 08:47:50 UTC, dangbinghoo wrote:


[...]


try


[...]


thanks for your reply, but it will also fail, the compiler 
just gives me :



source/spidev.d-mixin-129(129,8): Error: variable n cannot be 
read at compile time




sorry, I just don't notice the `()`.
yeah! it compiles, but can you explain it? thanks!


just got it! `size_t N` need to be template param.

Thanks for the help!


Re: help on how to wrap a C macros when binding linux/spi/spidev.h

2018-03-29 Thread dangbinghoo via Digitalmars-d-learn

On Thursday, 29 March 2018 at 09:13:27 UTC, dangbinghoo wrote:
On Thursday, 29 March 2018 at 09:02:16 UTC, Nicholas Wilson 
wrote:

On Thursday, 29 March 2018 at 08:47:50 UTC, dangbinghoo wrote:


[...]


try


[...]


thanks for your reply, but it will also fail, the compiler just 
gives me :



source/spidev.d-mixin-129(129,8): Error: variable n cannot be 
read at compile time




sorry, I just don't notice the `()`.
yeah! it compiles, but can you explain it? thanks!


Re: help on how to wrap a C macros when binding linux/spi/spidev.h

2018-03-29 Thread dangbinghoo via Digitalmars-d-learn

On Thursday, 29 March 2018 at 09:02:16 UTC, Nicholas Wilson wrote:

On Thursday, 29 March 2018 at 08:47:50 UTC, dangbinghoo wrote:


 * #define SPI_MSGSIZE(N) \
	N)*(sizeof (struct spi_ioc_transfer))) < (1 << 
_IOC_SIZEBITS)) \

? ((N)*(sizeof (struct spi_ioc_transfer))) : 0)
 */
extern (D) size_t SPI_MSGSIZE(size_t N)
{
return ((N * (spi_ioc_transfer.sizeof)) < (1 << 
_IOC_SIZEBITS)) ? (N * (spi_ioc_transfer.sizeof)) : 0;

}

/* #define SPI_IOC_MESSAGE(N) _IOW(SPI_IOC_MAGIC, 0, 
char[SPI_MSGSIZE(N)]) */

extern (D) auto SPI_IOC_MESSAGE(size_t N)
{
size_t n = SPI_MSGSIZE(N);
return _IOW!(char[static n])(SPI_IOC_MAGIC, 0);
//mixin("return _IOW!(char[n])(SPI_IOC_MAGIC, 0);");
}
```



try


extern (D) auto SPI_IOC_MESSAGE(size_t N)()
{
enum n = SPI_MSGSIZE(N);
return _IOW!(char[n])(SPI_IOC_MAGIC, 0);
//mixin("return _IOW!(char[n])(SPI_IOC_MAGIC, 0);");
}


thanks for your reply, but it will also fail, the compiler just 
gives me :



source/spidev.d-mixin-129(129,8): Error: variable n cannot be 
read at compile time




Re: help on how to wrap a C macros when binding linux/spi/spidev.h

2018-03-29 Thread dangbinghoo via Digitalmars-d-learn

On Thursday, 29 March 2018 at 08:47:50 UTC, dangbinghoo wrote:

hi,

I'm doing a D binding myself to , and has 
some problems to wrap the C macros.


[...]


PS: if I just _IOW!(char[])... it compiles, but does it mean it's 
unsafe? thanks!


help on how to wrap a C macros when binding linux/spi/spidev.h

2018-03-29 Thread dangbinghoo via Digitalmars-d-learn

hi,

I'm doing a D binding myself to , and has 
some problems to wrap the C macros.


```
import core.sys.posix.sys.ioctl;

...

/* IOCTL commands */

enum SPI_IOC_MAGIC = 'k';

/**
 *  Orginal C macros.
 *
 * #define SPI_MSGSIZE(N) \
	N)*(sizeof (struct spi_ioc_transfer))) < (1 << 
_IOC_SIZEBITS)) \

? ((N)*(sizeof (struct spi_ioc_transfer))) : 0)
 */
extern (D) size_t SPI_MSGSIZE(size_t N)
{
return ((N * (spi_ioc_transfer.sizeof)) < (1 << 
_IOC_SIZEBITS)) ? (N * (spi_ioc_transfer.sizeof)) : 0;

}

/* #define SPI_IOC_MESSAGE(N) _IOW(SPI_IOC_MAGIC, 0, 
char[SPI_MSGSIZE(N)]) */

extern (D) auto SPI_IOC_MESSAGE(size_t N)
{
size_t n = SPI_MSGSIZE(N);
return _IOW!(char[static n])(SPI_IOC_MAGIC, 0);
//mixin("return _IOW!(char[n])(SPI_IOC_MAGIC, 0);");
}
```

as shown in the above code, the SPI_IOC_MESSAGE C macro has a 
param `char[SPI_MSGSIZE(N)]`, what should it be wrapped to the D 
world?


as you can see, I tried to use the type of `char[static n]` or 
`char[n]`, and the compile failed:


```
source/spidev.d-mixin-129(129,19): Error: expression expected, 
not static

source/spidev.d-mixin-129(129,26): Error: found n when expecting ]
source/spidev.d-mixin-129(129,27): Error: found ] when expecting 
) following template argument list
source/spidev.d-mixin-129(129,28): Error: found ) when expecting 
; following return statement

```

or when removed static,

```
source/spidev.d-mixin-129(129,8): Error: variable n cannot be 
read at compile time

```

Can anyone help me? Thanks!




how to install latest lcd2 for armbain

2018-03-02 Thread dangbinghoo via Digitalmars-d-learn

hi there,

I just flased a armbain for nanoPi M3.

And, I just installed ldc2-1.2.0 armhf using apt-get. it compiles 
d code with combination with gcc armhf and compiled program runs 
great even the arch is aarch64.


But I realized that ldc2 is too old, I know that latest ldc2 is 
1.8.0.


So, does anyone know how to install latest ldc2 from arm-debain?

Thanks!