Re: access violation With dll?

2015-07-16 Thread jklp via Digitalmars-d-learn
On Thursday, 16 July 2015 at 17:22:50 UTC, jklp wrote: On Thursday, 16 July 2015 at 17:04:09 UTC, Taylor Hillegeist wrote: [...] Your proto is wrong. Your forgot the FFI convention (__cdecl = extern(C)). Try this instead: --- extern(C) alias Proto = void function(char*, int); Proto func =

Re: Weird behavior of this in a subclass, I think?

2015-07-16 Thread Daniel Kozák via Digitalmars-d-learn
On Thu, 16 Jul 2015 00:18:30 + seashell86 via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: So I've been mostly just toying around with D as it seems like it will end up being a strong language for game development both now and even moreso in the future. That being said,

Re: Template function that accept strings and array of strings

2015-07-16 Thread Jacob Carlborg via Digitalmars-d-learn
On 2015-07-15 23:57, badlink wrote: Hello, I can't figure how to write a template function that accept either strings or array of strings. This is my current code: bool hasItemParent(T)(const(char)[] itemId, const(T)[] parentId) if (is(typeof(T) == char) || (isArray!T is(typeof(T[]) ==

Are Lua tables possible to do with D?

2015-07-16 Thread Robert M. Münch via Digitalmars-d-learn
Hi, do you think it's possible to implemented something like Lua Tables (a hashed heterogeneous associative array) in D? I know that Lua is dynamic and interpreted, hence it's a lot simpler to do than with a compiled language but I'm wondering if we could express such a generic data-structure

Re: question about the semantics of unshared variables

2015-07-16 Thread aki via Digitalmars-d-learn
I noticed just making many threads cause an error. Are there any limit for the number of threads? import std.concurrency; import core.thread; void fun() { Thread.sleep(5000.msecs); } void testThread() { foreach(i; 0..2000) { spawn(fun); } }

Re: question about the semantics of unshared variables

2015-07-16 Thread aki via Digitalmars-d-learn
On Thursday, 16 July 2015 at 07:36:39 UTC, Jonathan M Davis wrote: Yes. Every thread gets a copy of the non-shared static variables, and all of the non-shared static constructors get run for each thread. - Jonathan M Davis Thank you for reply. Now i know. I did some test using C++ as you

Re: Weird behavior of this in a subclass, I think?

2015-07-16 Thread Jacob Carlborg via Digitalmars-d-learn
On 2015-07-16 09:46, Jonathan M Davis via Digitalmars-d-learn wrote: I've never heard of a language that overloaded member variables, and given how class polymorphism works, I don't see how it would even be possible without making it so that all accesses to a variable actually call a function

Re: Functional oriented programming in D

2015-07-16 Thread via Digitalmars-d-learn
On Thursday, 16 July 2015 at 09:52:59 UTC, ponce wrote: On Thursday, 16 July 2015 at 09:49:03 UTC, Jarl André Hübenthal wrote: Why? The syntax for delegate literals with braces is listenHTTP(settings, (req, res) { res.writeBody(Hello, World!); }); Thanks. Those small details you

Re: How to use core.thread.Thread

2015-07-16 Thread maarten van damme via Digitalmars-d-learn
You can certainly use thread but in most use cases, concurrency or parallelism will accomplish the same in a much saner/safer way. (they're wrappers around core.thread anyway). Don't know of any tutorials about core.thread, about the other two you can find help here : http://ddili.org/ders/d.en/

Re: Casting random type to random struct - is this a bug?

2015-07-16 Thread rumbu via Digitalmars-d-learn
On Wednesday, 15 July 2015 at 15:58:17 UTC, Daniel Kozák wrote: On Wed, 15 Jul 2015 15:45:43 + rumbu ru...@rumbu.ro wrote: struct S { int a, b; } auto s = cast(S)10; //compiles and sets s.a to 10. It works also for any other type, if the structure contains a member of that type in the

Re: Functional oriented programming in D

2015-07-16 Thread ponce via Digitalmars-d-learn
On Thursday, 16 July 2015 at 09:49:03 UTC, Jarl André Hübenthal wrote: Why? The syntax for delegate literals with braces is listenHTTP(settings, (req, res) { res.writeBody(Hello, World!); });

Re: How to use core.thread.Thread

2015-07-16 Thread Daniel Kozák via Digitalmars-d-learn
On Thu, 16 Jul 2015 07:57:10 + aki via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: I can't resolve the compile errors: import core.thread; class DerivedThread : Thread { int count = 0; this() { super(run); } private void run()

Re: How to use core.thread.Thread

2015-07-16 Thread aki via Digitalmars-d-learn
On Thursday, 16 July 2015 at 08:21:26 UTC, maarten van damme wrote: Have you checked out std.parallelism and std.concurrency? I know std.concurrency to use spawn. If I cannot use Thread, I'll implement by spawn. But want to try Thread class because it seems similar to Java's Thread class. I

Functional oriented programming in D

2015-07-16 Thread via Digitalmars-d-learn
Hi After a couple of years using and keeping an eye on D I have grown into a functional oriented programmer. I began with JavaScripts semi pseudo functional style, then Clojures dynamic functional style, Haskells burritos and now Scala. I have began to dislike Haskell for the academic

Re: question about the semantics of unshared variables

2015-07-16 Thread Jonathan M Davis via Digitalmars-d-learn
On Thursday, July 16, 2015 06:53:50 aki via Digitalmars-d-learn wrote: I noticed just making many threads cause an error. Are there any limit for the number of threads? import std.concurrency; import core.thread; void fun() { Thread.sleep(5000.msecs); } void testThread() { foreach(i;

Re: Weird behavior of this in a subclass, I think?

2015-07-16 Thread Jonathan M Davis via Digitalmars-d-learn
On Thursday, July 16, 2015 01:20:10 seashell86 via Digitalmars-d-learn wrote: On Thursday, 16 July 2015 at 00:39:29 UTC, H. S. Teoh wrote: On Thu, Jul 16, 2015 at 12:18:30AM +, seashell86 via Digitalmars-d-learn wrote: [...] The reason is that class variables cannot be overridden,

How to use core.thread.Thread

2015-07-16 Thread aki via Digitalmars-d-learn
I can't resolve the compile errors: import core.thread; class DerivedThread : Thread { int count = 0; this() { super(run); } private void run() { inc(); //testThread.d(8): Error: shared method testThread.DerivedThread.inc is not callable using a

Re: How to use core.thread.Thread

2015-07-16 Thread maarten van damme via Digitalmars-d-learn
Have you checked out std.parallelism and std.concurrency? 2015-07-16 9:57 GMT+02:00 aki via Digitalmars-d-learn digitalmars-d-learn@puremagic.com: I can't resolve the compile errors: import core.thread; class DerivedThread : Thread { int count = 0; this() {

Re: Are Lua tables possible to do with D?

2015-07-16 Thread Fusxfaranto via Digitalmars-d-learn
On Thursday, 16 July 2015 at 06:48:12 UTC, Robert M. Münch wrote: Hi, do you think it's possible to implemented something like Lua Tables (a hashed heterogeneous associative array) in D? I know that Lua is dynamic and interpreted, hence it's a lot simpler to do than with a compiled language

Re: question about the semantics of unshared variables

2015-07-16 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, July 15, 2015 16:21:29 aki via Digitalmars-d-learn wrote: I want to make sure about the semantics of unshared variables. import std.concurrency; import core.thread; ubyte[1024 * 1024] buf1MB; void fun() { Thread.sleep(5000.msecs); } void testThread() { foreach(i; 0..2000) {

Re: Are Lua tables possible to do with D?

2015-07-16 Thread Robert M. Münch via Digitalmars-d-learn
On 2015-07-16 07:20:15 +, Fusxfaranto said: An associative array of Variant[string] ought to do the job well enough. http://dlang.org/phobos/std_variant.html Thanks a lot. Somehow didn't see that... -- Robert M. Münch http://www.saphirion.com smarter | better | faster

Re: Functional oriented programming in D

2015-07-16 Thread Meta via Digitalmars-d-learn
On Thursday, 16 July 2015 at 09:57:55 UTC, Jarl André Hübenthal wrote: On Thursday, 16 July 2015 at 09:52:59 UTC, ponce wrote: On Thursday, 16 July 2015 at 09:49:03 UTC, Jarl André Hübenthal wrote: Why? The syntax for delegate literals with braces is listenHTTP(settings, (req, res) {

access violation With dll?

2015-07-16 Thread Taylor Hillegeist via Digitalmars-d-learn
Beleive it or not the code below does work. However I get an access violation after every run? any Ideas why? +Code to Run DLL function+++ import core.runtime; import std.stdio; import core.memory; import std.c.windows.windows; int main() {

Re: access violation With dll?

2015-07-16 Thread Adam D. Ruppe via Digitalmars-d-learn
On Thursday, 16 July 2015 at 17:04:09 UTC, Taylor Hillegeist wrote: void function(ref char[], int) Testf = cast(void function(ref char[], int)) GetProcAddress(h, Test); //Function Says HELLO WORLD void __cdecl Test(char MyOutput[], int32_t len); Those signatures

Re: access violation With dll?

2015-07-16 Thread jklp via Digitalmars-d-learn
On Thursday, 16 July 2015 at 17:04:09 UTC, Taylor Hillegeist wrote: Beleive it or not the code below does work. However I get an access violation after every run? any Ideas why? +Code to Run DLL function+++ import core.runtime; import

Re: question about the semantics of unshared variables

2015-07-16 Thread QAston via Digitalmars-d-learn
On Thursday, 16 July 2015 at 07:43:10 UTC, Jonathan M Davis wrote: [...] On linux you can alter the limit by using ulimit command. -a option shows the current limits.

Re: Template function that accept strings and array of strings

2015-07-16 Thread badlink via Digitalmars-d-learn
Thank you for all answers. Removing typeof do resolve the problem when the second parameter is a simple string. However when passing an array of string the error still occur: Error: template cache.MetadataCache.hasItemParent cannot deduce function from argument types !()(string, string[]).

Re: Working functionally with third party libraries

2015-07-16 Thread via Digitalmars-d-learn
On Thursday, 16 July 2015 at 20:17:54 UTC, Jarl André Hübenthal wrote: return coll.find().map!(doc = deserialize!(BsonSerializer, Resource)(doc)); Solved by wrapping return statement in array(...)

Re: access violation With dll?

2015-07-16 Thread Adam D. Ruppe via Digitalmars-d-learn
On Thursday, 16 July 2015 at 17:28:52 UTC, jklp wrote: Also i guess that the dll returns a null terminated string so the result has to be read like this: --- import std.string; printf(%s\n, fromStringz(STUFF.ptr)); --- That's not needed with printf, since it works with null terminated

Re: access violation With dll?

2015-07-16 Thread Adam D. Ruppe via Digitalmars-d-learn
On Thursday, 16 July 2015 at 19:25:42 UTC, Taylor Hillegeist wrote: Also if you have any good resources regarding this topic I would be interested. my book goes into it briefly *shameless plug* https://www.packtpub.com/application-development/d-cookbook The interfacing with C page on the

Environment variable for application storage under OSX ?

2015-07-16 Thread anonymous via Digitalmars-d-learn
I have the following code, working under Win and Linux: --- import std.process: environment; immutable string p; static this() { version(Win32) p = environment.get(APPDATA); version(linux) p = /home/ ~ environment.get(USER); version(OSX) p = ?; } --- what would be the OSX

Re: Template function that accept strings and array of strings

2015-07-16 Thread Gary Willoughby via Digitalmars-d-learn
On Wednesday, 15 July 2015 at 21:57:50 UTC, badlink wrote: Hello, I can't figure how to write a template function that accept either strings or array of strings. This is my current code: bool hasItemParent(T)(const(char)[] itemId, const(T)[] parentId) if (is(typeof(T) == char) || (isArray!T

Re: Template function that accept strings and array of strings

2015-07-16 Thread Gary Willoughby via Digitalmars-d-learn
Also checkout inout functions: http://dlang.org/function.html#inout-functions

Re: access violation With dll?

2015-07-16 Thread Taylor Hillegeist via Digitalmars-d-learn
On Thursday, 16 July 2015 at 17:28:52 UTC, jklp wrote: On Thursday, 16 July 2015 at 17:22:50 UTC, jklp wrote: On Thursday, 16 July 2015 at 17:04:09 UTC, Taylor Hillegeist wrote: [...] Your proto is wrong. Your forgot the FFI convention (__cdecl = extern(C)). Try this instead: ---

Re: Working functionally with third party libraries

2015-07-16 Thread Ali Çehreli via Digitalmars-d-learn
On 07/16/2015 12:35 PM, Jarl =?UTF-8?B?QW5kcsOpIEjDvGJlbnRoYWwi?= jarl.an...@gmail.com wrote: Hi using mongo with vibe.d is easy. But I would like to skip the foreach on MongoCursor? I mean, I want to use map!, filter! and reduce! on the resulting docs. Is there a fast way to convert

Re: Template function that accept strings and array of strings

2015-07-16 Thread badlink via Digitalmars-d-learn
After a thorough reading of the documentation I found an even simpler solution: bool hasItemParent(T)(const(char)[] itemId, T parentId) if (is(T : const(char)[]) || is(T : const(char[])[])) { ... } Now it accepts all these: char[], const(char)[], immutable(char)[], char[][], const(char)[][]

Re: access violation With dll?

2015-07-16 Thread Adam D. Ruppe via Digitalmars-d-learn
On Thursday, 16 July 2015 at 17:04:09 UTC, Taylor Hillegeist wrote: void function(ref char[], int) Testf = cast(void function(ref char[], int)) GetProcAddress(h, Test); //Function Says HELLO WORLD char[] STUFF; STUFF.length = 5000; Testf( STUFF ,

Working functionally with third party libraries

2015-07-16 Thread via Digitalmars-d-learn
Hi using mongo with vibe.d is easy. But I would like to skip the foreach on MongoCursor? I mean, I want to use map!, filter! and reduce! on the resulting docs. Is there a fast way to convert MongoCursor to an array without resolving to ugly for loops with appender! ?

Re: Working functionally with third party libraries

2015-07-16 Thread via Digitalmars-d-learn
On Thursday, 16 July 2015 at 20:00:38 UTC, Ali Çehreli wrote: On 07/16/2015 12:35 PM, Jarl =?UTF-8?B?QW5kcsOpIEjDvGJlbnRoYWwi?= jarl.an...@gmail.com wrote: Hi using mongo with vibe.d is easy. But I would like to skip the foreach on MongoCursor? I mean, I want to use map!, filter! and

Re: Working functionally with third party libraries

2015-07-16 Thread ZombineDev via Digitalmars-d-learn
On Thursday, 16 July 2015 at 20:17:54 UTC, Jarl André Hübenthal wrote: On Thursday, 16 July 2015 at 20:00:38 UTC, Ali Çehreli wrote: On 07/16/2015 12:35 PM, Jarl =?UTF-8?B?QW5kcsOpIEjDvGJlbnRoYWwi?= jarl.an...@gmail.com wrote: Hi using mongo with vibe.d is easy. But I would like to skip the

Re: Are Lua tables possible to do with D?

2015-07-16 Thread Jesse Phillips via Digitalmars-d-learn
On Thursday, 16 July 2015 at 06:48:12 UTC, Robert M. Münch wrote: Hi, do you think it's possible to implemented something like Lua Tables (a hashed heterogeneous associative array) in D? I know that Lua is dynamic and interpreted, hence it's a lot simpler to do than with a compiled language

Re: Template function that accept strings and array of strings

2015-07-16 Thread badlink via Digitalmars-d-learn
On Thursday, 16 July 2015 at 18:41:47 UTC, Gary Willoughby wrote: bool hasItemParent(A, B)(A itemId, B parentId) if (isSomeString!(A) (isSomeString!(B) || isArray!(B) isSomeString!(ElementType!(B Thank you ! I completely missed isSomeString. I think the definition can be safely

Re: Working functionally with third party libraries

2015-07-16 Thread via Digitalmars-d-learn
On Thursday, 16 July 2015 at 20:00:38 UTC, Ali Çehreli wrote: On 07/16/2015 12:35 PM, Jarl =?UTF-8?B?QW5kcsOpIEjDvGJlbnRoYWwi?= jarl.an...@gmail.com wrote: Hi using mongo with vibe.d is easy. But I would like to skip the foreach on MongoCursor? I mean, I want to use map!, filter! and

Re: Environment variable for application storage under OSX ?

2015-07-16 Thread Maeriden via Digitalmars-d-learn
On Thursday, 16 July 2015 at 21:12:05 UTC, anonymous wrote: I have the following code, working under Win and Linux: --- import std.process: environment; immutable string p; static this() { version(Win32) p = environment.get(APPDATA); version(linux) p = /home/ ~ environment.get(USER);

Re: How to use core.thread.Thread

2015-07-16 Thread byron via Digitalmars-d-learn
On Thursday, 16 July 2015 at 21:48:06 UTC, byron wrote: On Thursday, 16 July 2015 at 07:57:13 UTC, aki wrote: [...] If I remember a synchronized method requires this to be shared, you should be fine using a synchronized block in the method for non-shared instances. But using atomicOp

Re: Environment variable for application storage under OSX ?

2015-07-16 Thread byron via Digitalmars-d-learn
On Thursday, 16 July 2015 at 21:12:05 UTC, anonymous wrote: I have the following code, working under Win and Linux: --- import std.process: environment; immutable string p; static this() { version(Win32) p = environment.get(APPDATA); version(linux) p = /home/ ~ environment.get(USER);

Re: How to use core.thread.Thread

2015-07-16 Thread byron via Digitalmars-d-learn
On Thursday, 16 July 2015 at 07:57:13 UTC, aki wrote: I can't resolve the compile errors: import core.thread; class DerivedThread : Thread { int count = 0; this() { super(run); } private void run() { inc(); //testThread.d(8): Error: shared