Dynamically Sized Structs

2014-04-16 Thread Jeroen Bollen
Is it possible to have a structure with a dynamic size? The 
structure would contain an array.


I know I can use templates, but the size won't be known at 
compile time. I also know I could just put a dynamic array into 
it, but that way it would just be a pointer.


I know there would be major issues like how to pass the struct to 
a function, as it has an unknown size, but to be quite honest I 
just want pretty code. I'm doing network related operations. I 
was hoping there'd still be a way to do this using templates or 
so? I just don't want to go through the hassle of writing a 
constructor for it to fill in all the fields, and a toByteArray 
method to convert it back to raw data.


struct MyStruct {
ulong length;
ubyte[length] data; // obv won't compile
}


Extern Keyword for Function Type

2014-04-15 Thread Jeroen Bollen

exten(C) {
testFunction(int function(int));
}

testFunction now requires an external function as parameter. It 
can't be called with a pointer to a D function.


Logical Solution:

extern(C) {
testFunction(extern(D) int function(int)); // DOES NOT COMPILE
}

How do you fix this without moving it outside the global extern 
block?


Re: Extern Keyword for Function Type

2014-04-15 Thread Jeroen Bollen

On Tuesday, 15 April 2014 at 20:15:42 UTC, Jeroen Bollen wrote:

exten(C) {
testFunction(int function(int));
}

testFunction now requires an external function as parameter. It 
can't be called with a pointer to a D function.


Logical Solution:

extern(C) {
testFunction(extern(D) int function(int)); // DOES NOT 
COMPILE

}

How do you fix this without moving it outside the global extern 
block?


Whoops, assume testFunction is defined as void testFunction(...)


Re: Extern Keyword for Function Type

2014-04-15 Thread Jeroen Bollen

On Tuesday, 15 April 2014 at 20:19:36 UTC, Dicebot wrote:
C has no knowledge of D ABI so this can't work. If you just 
want to store D function pointer to later retrieve it and call 
from D code, you can as well store it as void* (or extern(C) 
with similar signature to preserve part of type) and cast upon 
interfacing.


Hmm so the function passed should be declared as extern C but be 
defined nonetheless? That makes sense.


Modify Object Pointer during Initialzation

2014-04-08 Thread Jeroen Bollen
This topic is somewhat related to this question I asked yesterday 
on StackOverflow: http://stackoverflow.com/q/22921395/2558778


Basically, why is this its own variable? Why doesn't D simply use 
the variable it was called with?


https://gist.github.com/Binero/10128826

I don't see why this needs to be a new variable and cannot simply 
be 'passed-by-reference'.


Re: Modify Object Pointer during Initialzation

2014-04-08 Thread Jeroen Bollen

On Tuesday, 8 April 2014 at 14:13:10 UTC, Adam D. Ruppe wrote:

On Tuesday, 8 April 2014 at 14:04:01 UTC, Jeroen Bollen wrote:
Basically, why is this its own variable? Why doesn't D simply 
use the variable it was called with?


A class reference is basically a pointer, passing it by 
reference to each method would be a double pointer and wasted 
effort most the time; all most methods care about is where to 
get the object data, they don't need to know how the caller was 
getting to the object data.


I don't see why this needs to be a new variable and cannot 
simply be 'passed-by-reference'.


You can get that with UFCS btw:

class A {}

void f(ref A a) { /* modify a here and it will change */ }

void main() {
  A a = new A;
  a.f; // a is passed by reference
}


Is there a documentation page about the 'uniform function call 
syntax'?


Re: Modify Object Pointer during Initialzation

2014-04-08 Thread Jeroen Bollen

On Tuesday, 8 April 2014 at 14:23:02 UTC, Jeroen Bollen wrote:
Is there a documentation page about the 'uniform function call 
syntax'?


Never mind, I think I understand all there is to it.


Re: Modify Object Pointer during Initialzation

2014-04-08 Thread Jeroen Bollen

On Tuesday, 8 April 2014 at 14:26:46 UTC, Adam D. Ruppe wrote:

On Tuesday, 8 April 2014 at 14:23:02 UTC, Jeroen Bollen wrote:
Is there a documentation page about the 'uniform function call 
syntax'?


http://dlang.org/function.html#pseudo-member


Oh beat me to it.


How to pass delegates to C functions?

2014-04-03 Thread Jeroen Bollen
After being downvoted on stackoverflow for no apperant reason, I 
figured I'd give it a shot here.


How do I pass a delegate to an external C function taking a 
function pointer?


If you want some extra rep on StackOverflow you can also answer 
here: 
http://stackoverflow.com/questions/22845175/pass-delegates-to-external-c-functions-in-d


Re: How to pass delegates to C functions?

2014-04-03 Thread Jeroen Bollen

On Thursday, 3 April 2014 at 18:05:26 UTC, Justin Whear wrote:

On Thu, 03 Apr 2014 17:59:30 +, Jeroen Bollen wrote:

After being downvoted on stackoverflow for no apperant reason, 
I figured

I'd give it a shot here.

How do I pass a delegate to an external C function taking a 
function

pointer?

If you want some extra rep on StackOverflow you can also 
answer here:

http://stackoverflow.com/questions/22845175/pass-delegates-to-external-

c-functions-in-d

Does the C function use the function pointer (call it), or just 
pass it

around/store it?


It will get called.


Re: How to pass delegates to C functions?

2014-04-03 Thread Jeroen Bollen

On Thursday, 3 April 2014 at 18:13:31 UTC, Adam D. Ruppe wrote:

On Thursday, 3 April 2014 at 17:59:33 UTC, Jeroen Bollen wrote:
How do I pass a delegate to an external C function taking a 
function pointer?



You can't do it directly in general, unless you can modify the 
C function, then you can hack around it, but a delegate and a 
regular function pointer are pretty different animals.


But perhaps you can magic hack it. Observe:

// a C function that needs a plain function
extern(C) void test(void function() f) {
// pretend this impl is in C
f();
}

// just create a random delegate
void delegate() foo(int a) {
return { import std.stdio; writeln(a); };
}

// what we want to work
void main() {
auto dg = foo(10);
dg(); // works

//test(dg); // won't work
test(bindDelegate(dg)); // we want this
}

// transform delegate into pointer..
import std.traits;
auto bindDelegate(T, string file = __FILE__, size_t line = 
__LINE__)(T t) if(isDelegate!T) {

static T dg;

dg = t;

extern(C)
static ReturnType!T func(ParameterTypeTuple!T args) {
return dg(args);
}

return func;
}




What bindDelegate does is create a special static variable and 
function for that specific call.  It is as if we wrote a 
separate function and global to hold it.


The __FILE__, __LINE__ things are a filthy hack to make it 
instantitate a separate variable+function pair for different 
lines so the global variable holding the delegate won't be so 
easily overwritten.


Thanks.


Re: How to pass delegates to C functions?

2014-04-03 Thread Jeroen Bollen

On Friday, 4 April 2014 at 05:20:42 UTC, Mengu wrote:

On Thursday, 3 April 2014 at 17:59:33 UTC, Jeroen Bollen wrote:
After being downvoted on stackoverflow for no apperant reason, 
I figured I'd give it a shot here.


How do I pass a delegate to an external C function taking a 
function pointer?


If you want some extra rep on StackOverflow you can also 
answer here: 
http://stackoverflow.com/questions/22845175/pass-delegates-to-external-c-functions-in-d


OT: you've got another upvote!


Ever since I posted it here it started climbing back up the 
ladder. Doesn't really matter now anyways, I got my answer. :P


Re: How to foreach over a DList?

2014-04-01 Thread Jeroen Bollen

Just for reference, this is the compiling code:

https://gist.github.com/Binero/f30e56351baf05f1a2ec


How to foreach over a DList?

2014-03-31 Thread Jeroen Bollen
I am trying to foreach over a std.container.DList but it isn't 
working. I have tried the following code: 
https://gist.github.com/Binero/f30e56351baf05f1a2ec


I am getting the following errors:

/usr/include/dlang/dmd/std/container.d(1925): Error: template 
std.container.DList!ubyte.DList.insertBeforeNode cannot deduce 
function from argument types !()(typeof(null), int), candidates 
are:
/usr/include/dlang/dmd/std/container.d(2096):
std.container.DList!ubyte.DList.insertBeforeNode(Stuff)(Node* n, 
Stuff stuff) if (isInputRange!Stuff  
isImplicitlyConvertible!(ElementType!Stuff, T))
/usr/include/dlang/dmd/std/container.d(2155):
std.container.DList!ubyte.DList.insertBeforeNode(Stuff)(Node* n, 
Stuff stuff) if (isImplicitlyConvertible!(Stuff, T))
source/app.d(7): Error: template instance 
std.container.DList!ubyte.DList.insertBack!int error instantiating

source/app.d(11): Error: invalid foreach aggregate list1


Re: How to foreach over a DList?

2014-03-31 Thread Jeroen Bollen

On Monday, 31 March 2014 at 19:26:23 UTC, Jeroen Bollen wrote:

On Monday, 31 March 2014 at 18:24:39 UTC, H. S. Teoh wrote:

On Mon, Mar 31, 2014 at 05:50:16PM +, Jeroen Bollen wrote:
I am trying to foreach over a std.container.DList but it 
isn't working. I

have tried the following code:

[...]

Maybe try using opSlice:

DList myList;
foreach (e; myList[]) { ... }

?


T


Can you explain that syntax?


nvm figured it out;

Are constant DLists supposed to be un-foreach-able?
Error: mutable method std.container.DList!(ubyte).DList.opSlice 
is not callable using a const object


Re: How to foreach over a DList?

2014-03-31 Thread Jeroen Bollen

On Monday, 31 March 2014 at 18:24:39 UTC, H. S. Teoh wrote:

On Mon, Mar 31, 2014 at 05:50:16PM +, Jeroen Bollen wrote:
I am trying to foreach over a std.container.DList but it isn't 
working. I

have tried the following code:

[...]

Maybe try using opSlice:

DList myList;
foreach (e; myList[]) { ... }

?


T


Can you explain that syntax?


Re: How to foreach over a DList?

2014-03-31 Thread Jeroen Bollen

Still not working:

https://gist.github.com/Binero/f30e56351baf05f1a2ec
/usr/include/dlang/dmd/std/container.d(1925): Error: template 
std.container.DList!ubyte.DList.insertBeforeNode cannot deduce 
function from argument types !()(typeof(null), int), candidates 
are:
/usr/include/dlang/dmd/std/container.d(2096):
std.container.DList!ubyte.DList.insertBeforeNode(Stuff)(Node* n, 
Stuff stuff) if (isInputRange!Stuff  
isImplicitlyConvertible!(ElementType!Stuff, T))
/usr/include/dlang/dmd/std/container.d(2155):
std.container.DList!ubyte.DList.insertBeforeNode(Stuff)(Node* n, 
Stuff stuff) if (isImplicitlyConvertible!(Stuff, T))
source/app.d(7): Error: template instance 
std.container.DList!ubyte.DList.insertBack!int error instantiating
source/app.d(11): Error: need upper and lower bound to slice 
pointer


Re: How to foreach over a DList?

2014-03-31 Thread Jeroen Bollen

Still no luck:

import std.container;
import std.stdio;

void main()
{
DList!ubyte list1 = DList!ubyte();
list1 ~= cast(ubyte) 1;
list1 ~= cast(ubyte) 2;
list1 ~= cast(ubyte) 3;

foreach(ubyte item; list1[]) {
writeln(item);
}
}

/usr/include/dlang/dmd/std/container.d(1874): Error: no property 
'_first' for type 'ubyte'
/usr/include/dlang/dmd/std/container.d(1875): Error: no property 
'_first' for type 'ubyte'
/usr/include/dlang/dmd/std/container.d(1875): Error: undefined 
identifier rhs_, did you mean variable rhs?
source/app.d(7): Error: template instance 
std.container.DList!ubyte.DList.opOpAssign!(~, ubyte) error 
instantiating
source/app.d(7): Error: cannot append type ubyte to type 
DList!ubyte


Re: Disabling the Garbage Collector

2014-03-03 Thread Jeroen Bollen

On Monday, 3 March 2014 at 02:33:49 UTC, Adam D. Ruppe wrote:

On Sunday, 2 March 2014 at 23:21:49 UTC, Jeroen Bollen wrote:
Is there maybe a way to disable the garbage collector from 
running unless you explicitly call it?


That's really the default. The GC in D runs if and only if you 
do a GC allocation and there isn't enough memory in its 
existing pool. Then it tries to do a collection to make room 
(and if that fails, it asks the operating system for more 
memory to grow its arena, and if that fails, it throws 
OutOfMemoryError).


If you call GC.disable, it just sets a flag to skip the try 
collection step.



But, in any case, the GC doesn't sit around in the background 
constantly running at random times. It only runs when you call 
on it to allocate.


If I were to compile without linking to the garbage collector, 
what would and what wouldn't work in D?


Disabling the Garbage Collector

2014-03-02 Thread Jeroen Bollen

How to disable D's Garbage Collector? I have read stuff about
editing Phobos and simply take it out, and replace it with your
own to have stuff like the new keyword still work. Surely there
must be an easier way, where you can still allocate like you
normally would, as long as you deallocate too.

I've read about ways to disable the garbage collector, but that'd
mean it was initially enabled.


Re: Disabling the Garbage Collector

2014-03-02 Thread Jeroen Bollen

On Sunday, 2 March 2014 at 23:17:12 UTC, bearophile wrote:

Jeroen Bollen:

I've read about ways to disable the garbage collector, but 
that'd

mean it was initially enabled.


You can disable and then enable the garbage collector like this:

void main() {
import core.memory;
GC.disable;
// Do stuff here.
GC.enable;
}

But if you perform GC-managed operations, they will not free 
their memory, like array appending, array concat, inserts in 
associative arrays, and so on.


You can also stub away the GC in a more complex way.

Bye,
bearophile


That'd mean that the garbage collector was initialized in the 
first place, wouldn't it?


Is there maybe a way to disable the garbage collector from 
running unless you explicitly call it?


Re: Check if path is child of directory

2014-02-11 Thread Jeroen Bollen

On Monday, 10 February 2014 at 00:44:23 UTC, Jesse Phillips wrote:

On Sunday, 9 February 2014 at 21:02:59 UTC, Jeroen Bollen wrote:
I'm building a webserver using the Vibe.d library. Whenever 
the user requests a page inside my /images/ folder; I want 
them to output this file.


Because there will be a lot of images present, and because 
these are likely to change in the future, I would like to just 
get the URL from the request, and automatically output the 
file.


I am aware though, that users could perform tricks like 
images/../../../../sensitive_file_here. In order to prevent 
that I would like a solid way of making sure the entered path 
is actually inside the images directory.


How do I do this?


You can remove the directory navigation with 
std.path.buildNormalizedPath, not sure the behavior on a 
relative path, but you could call std.path.absolutePath first.


Would that be relative to the working directory? Would ./../ 
still work?


Check if path is child of directory

2014-02-09 Thread Jeroen Bollen
I'm building a webserver using the Vibe.d library. Whenever the 
user requests a page inside my /images/ folder; I want them to 
output this file.


Because there will be a lot of images present, and because these 
are likely to change in the future, I would like to just get the 
URL from the request, and automatically output the file.


I am aware though, that users could perform tricks like 
images/../../../../sensitive_file_here. In order to prevent 
that I would like a solid way of making sure the entered path is 
actually inside the images directory.


How do I do this?


Re: Check if path is child of directory

2014-02-09 Thread Jeroen Bollen

On Sunday, 9 February 2014 at 21:02:59 UTC, Jeroen Bollen wrote:
I'm building a webserver using the Vibe.d library. Whenever the 
user requests a page inside my /images/ folder; I want them to 
output this file.


Because there will be a lot of images present, and because 
these are likely to change in the future, I would like to just 
get the URL from the request, and automatically output the file.


I am aware though, that users could perform tricks like 
images/../../../../sensitive_file_here. In order to prevent 
that I would like a solid way of making sure the entered path 
is actually inside the images directory.


How do I do this?


I just figured out vibe.d handles this automatically, but I'd 
still like to know of a secure way to do this, for future 
reference.


Re: Is continuously seeding a random number generator performance intensive?

2014-01-21 Thread Jeroen Bollen

On Friday, 17 January 2014 at 19:00:29 UTC, Jeroen Bollen wrote:
On Wednesday, 15 January 2014 at 21:00:57 UTC, Jeroen Bollen 
wrote:
How do you correctly create a MersenneTwisterEngine with a 
ulong as seed?


This question still isn't answered by the way.


Come on, surely someone knows how to. I've already tried the 
obvious, but it doesn't work.


MersenneTwisterEngine!(ulong, 32, 624, 397, 31, 0x9908b0df, 11, 
7, 0x9d2c5680, 15, 0xefc6, 18) rndEngine;

rndEngine = MersenneTwisterEngine(seed);

shift by 32 is outside the range 0..31
static assert  (false  4022730752LU = 0LU) is false
instantiated from here: MersenneTwisterEngine!(ulong, 32, 624, 
397, 31, 2567483615u, 11, 7, 2636928640u, 15, 4022730752u, 18)




Re: Is continuously seeding a random number generator performance intensive?

2014-01-21 Thread Jeroen Bollen

On Tuesday, 21 January 2014 at 17:51:44 UTC, monarch_dodra wrote:
On Tuesday, 21 January 2014 at 17:13:39 UTC, Jeroen Bollen 
wrote:
On Friday, 17 January 2014 at 19:00:29 UTC, Jeroen Bollen 
wrote:
On Wednesday, 15 January 2014 at 21:00:57 UTC, Jeroen Bollen 
wrote:
How do you correctly create a MersenneTwisterEngine with a 
ulong as seed?


This question still isn't answered by the way.


Come on, surely someone knows how to. I've already tried the 
obvious, but it doesn't work.


MersenneTwisterEngine!(ulong, 32, 624, 397, 31, 0x9908b0df, 
11, 7, 0x9d2c5680, 15, 0xefc6, 18) rndEngine;

rndEngine = MersenneTwisterEngine(seed);

shift by 32 is outside the range 0..31
static assert  (false  4022730752LU = 0LU) is false
instantiated from here: MersenneTwisterEngine!(ulong, 32, 
624, 397, 31, 2567483615u, 11, 7, 2636928640u, 15, 
4022730752u, 18)


Is that your actual code? MersenneTwisterEngine(seed) is not 
valid code, you have to provide the template arguments.


In any case, that's a bug. Please file a report for it, and 
I'll give it a full fix.


For a local fix, you can replace the incriminating line 
(random.d:550):

/// Largest generated value.
enum UIntType max =
w == UIntType.sizeof * 8 ? UIntType.max : (1u  w) - 1;

By:
/// Largest generated value.
enum UIntType max =
UIntType.max  (UIntType.sizeof * 8 - w);

I think that's all that's required.

PS: If you want to generate longs, you also need to set the w 
variable (wordSize) from 32 to 64, or you'll still just be 
generating 32 bits worth of randomness.


I also recommend you use an alias (and alignment), such as:

alias Mt19937UL =
MersenneTwisterEngine!(ulong, 64, 624, 397, 31,
   0x9908b0df, 11, 7,
   0x9d2c5680, 15,
   0xefc6, 18);
auto rndEngine = Mt19937UL(seed);

That is my actual code.


Re: Is continuously seeding a random number generator performance intensive?

2014-01-21 Thread Jeroen Bollen

On Tuesday, 21 January 2014 at 17:51:44 UTC, monarch_dodra
Is that your actual code? MersenneTwisterEngine(seed) is not 
valid code, you have to provide the template arguments.


I meant to answer to this by the way, sorry. (in
need of edit feature :P )


Re: Is continuously seeding a random number generator performance intensive?

2014-01-17 Thread Jeroen Bollen
On Wednesday, 15 January 2014 at 21:00:57 UTC, Jeroen Bollen 
wrote:
How do you correctly create a MersenneTwisterEngine with a 
ulong as seed?


This question still isn't answered by the way.


Re: Is continuously seeding a random number generator performance intensive?

2014-01-15 Thread Jeroen Bollen
How do you correctly create a MersenneTwisterEngine with a ulong 
as seed?


Prevent Garbage Collector

2014-01-04 Thread Jeroen Bollen
Is there a way to prevent the Garbage collector from running on 
one particular object? Something like:


int* CreatePermanentInt() {
int i = 5;
return i;
}

And i wouldn't be collected after this.


Re: Prevent Garbage Collector

2014-01-04 Thread Jeroen Bollen

On Saturday, 4 January 2014 at 17:16:53 UTC, Adam D. Ruppe wrote:
On Saturday, 4 January 2014 at 17:15:12 UTC, Jeroen Bollen 
wrote:
Is there a way to prevent the Garbage collector from running 
on one particular object? Something like:


I would just malloc it.

int* CreatePermanentInt() {
   int* i = malloc(int.sizeof);
   *i = 5;
   return i;
}


The malloced thing itself won't be freed, nor will its contents 
be scanned by the gc (unless you use GC.addRange yourself) so 
you can use it to hack some weak references too.


Do I get malloc from the C library or does D also have a function 
for this?


Re: Prevent Garbage Collector

2014-01-04 Thread Jeroen Bollen

On Saturday, 4 January 2014 at 17:22:44 UTC, Adam D. Ruppe wrote:
On Saturday, 4 January 2014 at 17:19:30 UTC, Jeroen Bollen 
wrote:
Do I get malloc from the C library or does D also have a 
function for this?


import core.stdc.stdlib; // malloc and free are in here

it uses it from the C library but the standard c lib is easily 
accessible from D in the core.stdc package.


Yeah I knew about the C library, just wasn't sure if D also had 
it's own function.


Re: Prevent Garbage Collector

2014-01-04 Thread Jeroen Bollen

On Saturday, 4 January 2014 at 17:24:24 UTC, Adam D. Ruppe wrote:

And GC.addRange is in core.memory if you want that.

http://dlang.org/phobos/core_memory.html#addRange


Would that work with structs too?

Struct* i = malloc(Struct.sizeof);
i = Struct(params);


Re: Is continuously seeding a random number generator performance intensive?

2014-01-04 Thread Jeroen Bollen

Also where is UIntType defined?


Re: Is continuously seeding a random number generator performance intensive?

2014-01-04 Thread Jeroen Bollen

On Saturday, 4 January 2014 at 20:16:31 UTC, Jeroen Bollen wrote:

Also where is UIntType defined?


Alright, turns out it was just a template.

One more question though, I have my Engine set to have 'ulong' as 
a seed through the template, which means that it'll also return 
'ulong' as a result. Is there a way to have it take 'ulong' as a 
seed, and output 'ubyte'? Divisions for every result would be 
expensive, and shifting the output wouldn't return a uniform 
distribution.


Re: Is continuously seeding a random number generator performance intensive?

2014-01-04 Thread Jeroen Bollen

On Saturday, 4 January 2014 at 21:48:02 UTC, bearophile wrote:

Jeroen Bollen:


Divisions for every result would be expensive, and shifting
the output wouldn't return a uniform distribution.


If the ulong is uniform, then every of its ubytes is uniform. 
So  ubyte.max could suffice. If that's not good enough for 
you, then you can xor together the eight ubytes of the ulong 
with some masking  shifts :-)


Bye,
bearophile


Oops yeah sorry, I was thinking there is more chance to get a 
small number and thus more chance for there being zeros up front, 
but actually there is as much chance due there being as many 
numbers started with 1 as with 0. Thanks for the help. :D


Re: Prevent Garbage Collector

2014-01-04 Thread Jeroen Bollen
Also a somewhat unrelated question, variables in D get 
initialized by default, do they also when you define them right 
after? Something like:


int[] iryy = new int[](50); // Will the array elements be 
initialized to 0?


foreach(int i; irry) {
i = 20;
}


Re: Prevent Garbage Collector

2014-01-04 Thread Jeroen Bollen

On Sunday, 5 January 2014 at 00:28:00 UTC, Adam D. Ruppe wrote:

On Sunday, 5 January 2014 at 00:17:12 UTC, Jeroen Bollen wrote:
Also a somewhat unrelated question, variables in D get 
initialized by default, do they also when you define them 
right after? Something like:


Maybe. Logically, it is always initialized unless you 
explicitly tell it not to ( = void on declarations, not sure 
about making new return uniniialized memory), but the optimizer 
might see that the initalization is useless and skip it.


The 'might' here is worrying, as the array will be huge and it's 
really costly to initialize it twice. Is there a way to tell it 
to not initialize it? Is it safe to use foreach on it if it isn't 
initialized?


Re: Prevent Garbage Collector

2014-01-04 Thread Jeroen Bollen


Also about the previous C style malloc, to free it, I just use 
the c style delete?


Re: Prevent Garbage Collector

2014-01-04 Thread Jeroen Bollen

On Sunday, 5 January 2014 at 01:23:58 UTC, Adam D. Ruppe wrote:

On Sunday, 5 January 2014 at 01:10:29 UTC, Jeroen Bollen wrote:

Is there a way to tell it to not initialize it?


I'm not sure of any except using the primitives. You can malloc 
GC memory from GC.malloc (works the same way as C malloc, 
except you don't have to free it yourself; the GC does it). 
GC.malloc doesn't initialize the memory.


http://dlang.org/phobos/core_memory.html#malloc


I don't think there's a way to tell new not to zero it out 
though...



Is it safe to use foreach on it if it isn't initialized?


Yeah, the contents will be random, but you are setting it 
anyway so that doesn't matter.


As GC.malloc returns a pointer, how does it know when it should 
garbage collect the allocated space?


Re: Is continuously seeding a random number generator performance intensive?

2014-01-03 Thread Jeroen Bollen

On Friday, 3 January 2014 at 10:06:27 UTC, monarch_dodra wrote:

On Friday, 3 January 2014 at 01:43:09 UTC, Chris Cain wrote:
So, it sounds like the OP is using the x and y coords for a 
seed to generate a single number and he was curious to whether 
it costs too much to reseed like this for every point.


FWIW, I'm under the impression that this is a fairly common 
strategy, but usually when I've seen this used more than one 
number is generated at a time.


I *thought* he wanted to do something like that, but was 
surprised by the fact he wanted to reseed *per* element...


You can still do this, in this case. For example, divide x by 
10 and generate 10 elements (column wise) in the noise map 
each time and it reduces the number of reseeds by a factor of 
10. Some effort might be wasted, but as long as you need a 
decent chunk of the noise map at any one point in time, this 
should work out pretty well in practice.


My biggest concern with this approach is that you must take 
care that your usage of seeding with x and y coordinates does 
not cause repeated elements to occur. For instance, using 
`Random rng = Random(x + y);` will _not_ work properly (unless 
you want strange mirroring down the diagonal in your noise 
map). There's numerous landmines to avoid when doing something 
like this. Some approaches may not be perfect, but depending 
on what you're doing they may be sufficient, however.


The approach I'd take here is to eagerly generate a uint[X / 
1000][Y / 1000] grid, that holds randomly generated numbers, 
to be used as seeds for individual 1000*1000 blocks of the 
noise map. I don't know how good that is though in terms of 
correlation...?


Or, even better, to create a single generator of type Gen, 
and store a Gen[X / 1000][Y / 1000]: EG: the generator, with 
a checkpoint every 1_000_000 elements. This should reduce 
correlation down to 0.


AFAIK, all generators above the linear congruential generator 
have a period above 10^12, so this approach should be fine. The 
only issue with such an approach might be the size of the 
PRNG's themselves: XOrShift, for example, is only a few bytes 
big, so that's fine. But MT is about 700B, which is a hefty 
amount to chug along.


I already considered this, but the problem is, I need to smoothen 
the noise, and to do that I need all surrounding 'checkpoints' 
too. This means that it'll have to load in 5 at a time.


Re: Is continuously seeding a random number generator performance intensive?

2014-01-03 Thread Jeroen Bollen

On Friday, 3 January 2014 at 13:42:19 UTC, monarch_dodra wrote:

On Friday, 3 January 2014 at 13:30:09 UTC, Jeroen Bollen wrote:
I already considered this, but the problem is, I need to 
smoothen the noise, and to do that I need all surrounding 
'checkpoints' too. This means that it'll have to load in 5 at 
a time.


I don't see that as a problem. Just because you can load 
sub-regions at once, doesn't mean you are limited to only 
loading one at a time.


That still means that out of 5 million pixels loaded, only 1 
million 4 thousand will be used. I guess I can recycle them 
though.


Re: Linux DLL

2014-01-03 Thread Jeroen Bollen

On Friday, 3 January 2014 at 20:31:09 UTC, Mineko wrote:
So, I was doing some stuff with shared libraries and need some 
confirmation on what's going on with 
http://dlang.org/dll-linux.html


Is that page recent, or really old?

It's using printf and stuff so uhh.. Seems old.

Could anyone here perhaps give me a more recent explanation of 
how to do the bottom example, if it's not already? 
(http://dlang.org/dll-linux.html#dso10)


Using the standard phobos library, of course, for instance, I 
would have issues with fprintf and the stuff going on with 
stderror and error/dlerror.


It says on top Preliminary and subject to change., although 
that might have just been put in.


Re: Linux DLL

2014-01-03 Thread Jeroen Bollen

On Friday, 3 January 2014 at 20:37:06 UTC, Mineko wrote:

On Friday, 3 January 2014 at 20:34:17 UTC, Jeroen Bollen wrote:

On Friday, 3 January 2014 at 20:31:09 UTC, Mineko wrote:
So, I was doing some stuff with shared libraries and need 
some confirmation on what's going on with 
http://dlang.org/dll-linux.html


Is that page recent, or really old?

It's using printf and stuff so uhh.. Seems old.

Could anyone here perhaps give me a more recent explanation 
of how to do the bottom example, if it's not already? 
(http://dlang.org/dll-linux.html#dso10)


Using the standard phobos library, of course, for instance, I 
would have issues with fprintf and the stuff going on with 
stderror and error/dlerror.


It says on top Preliminary and subject to change., although 
that might have just been put in.


Oh, thank you, can't believe I missed that..

Other than that, are there any better ways of doing the 
aforementioned?


I've asked a question related to DLL loading myself recently, but 
all I got from it was making DLLs in D is terribly complicated 
and when you hear anything related to it just run.


Here's the thread: 
http://forum.dlang.org/thread/sedvxeoxoslnzbeiy...@forum.dlang.org


Re: Linux DLL

2014-01-03 Thread Jeroen Bollen

On Friday, 3 January 2014 at 20:48:29 UTC, Jeroen Bollen wrote:

On Friday, 3 January 2014 at 20:37:06 UTC, Mineko wrote:

On Friday, 3 January 2014 at 20:34:17 UTC, Jeroen Bollen wrote:

On Friday, 3 January 2014 at 20:31:09 UTC, Mineko wrote:
So, I was doing some stuff with shared libraries and need 
some confirmation on what's going on with 
http://dlang.org/dll-linux.html


Is that page recent, or really old?

It's using printf and stuff so uhh.. Seems old.

Could anyone here perhaps give me a more recent explanation 
of how to do the bottom example, if it's not already? 
(http://dlang.org/dll-linux.html#dso10)


Using the standard phobos library, of course, for instance, 
I would have issues with fprintf and the stuff going on with 
stderror and error/dlerror.


It says on top Preliminary and subject to change., although 
that might have just been put in.


Oh, thank you, can't believe I missed that..

Other than that, are there any better ways of doing the 
aforementioned?


I've asked a question related to DLL loading myself recently, 
but all I got from it was making DLLs in D is terribly 
complicated and when you hear anything related to it just run.


Here's the thread: 
http://forum.dlang.org/thread/sedvxeoxoslnzbeiy...@forum.dlang.org


Or SO on Linux. :D


Is continuously seeding a random number generator performance intensive?

2014-01-02 Thread Jeroen Bollen
D provides a set of Random Number Generators in std.random. I am 
writing an application which would create a 2D map of noise. To 
do this though, I'll have to calculate the same random numbers 
over and over again. (I cannot store them, that'd take a horrible 
amount of RAM. )


Is it good to re-seed a generator for every coordinate, will this 
be performance intensive? Is there maybe way to easily implement 
Generator.at(uint x) in D?


Re: how to detect OS architecture?

2013-12-16 Thread Jeroen Bollen

On Monday, 16 December 2013 at 10:54:15 UTC, Hugo Florentino
wrote:

Hi,

I am writing a launcher to make a Windows application portable, 
but since this application supports both x86 and x86_64, I 
would like to detect the architecture of the OS my launcher is 
being run on, in order to launch the proper executable.


How can I do this?

Regards, Hugo


version(Windows) {
  // Windows code goes here
} else {
 // Other OS code goes here
}

More here: http://dlang.org/version.html


WinAPI Wide Functions

2013-12-15 Thread Jeroen Bollen
Are there default bindings to the WinAPI's Wide Functions? I'm 
talking about for example 'CreateWindowW'.


Re: WinAPI Wide Functions

2013-12-15 Thread Jeroen Bollen

On Sunday, 15 December 2013 at 14:26:26 UTC, Marco Leise wrote:

Am Sun, 15 Dec 2013 15:17:39 +0100
schrieb Jeroen Bollen jbin...@gmail.com:

Are there default bindings to the WinAPI's Wide Functions? I'm 
talking about for example 'CreateWindowW'.


I know of this project:
http://www.dsource.org/projects/bindings/wiki/WindowsApi


I would but there doesn't seem to be any documentation on that 
binding set. How am I supposed to know which modules to use or 
what DLLs to link?


Binary Data Serialization Libraries

2013-12-06 Thread Jeroen Bollen
Are there any Binary Data Serialization Libraries available 
written in D2? I'm looking for something like a BSON read/write 
library. (Although can be any other binary language really)


How to load a derelict program in D?

2013-12-06 Thread Jeroen Bollen

I am using the derelict-sfml2 package in my code. My code:

import std.stdio;
import derelict.sfml2.window;

void main()
{
DerelictSFML2Window.load();
sfVideoMode videoMode = sfVideoMode(1280, 720);
	sfWindow* window = sfWindow_create(videoMode, Animation, 
sfNone, null);

}

For some reason this always crashes inside a void load( string 
libNames ) function. The crash seems to happen inside the 
'DerelictSFML2Window.load();'.


Why is that? I am using Visual Studio 2013, with the VisualD 
add-on. I have created the solution using dub generate visuald; 
this is my project.json:



{
name: testing,
description: testing,
authors: [Jeroen Bollen],
dependencies: {
derelict-sfml2 : ~master,
}
}


Re: Read Byte Array to Integer

2013-11-24 Thread Jeroen Bollen

On Friday, 22 November 2013 at 21:17:56 UTC, monarch_dodra wrote:
On Friday, 22 November 2013 at 19:44:56 UTC, Jeroen Bollen 
wrote:

On Friday, 22 November 2013 at 19:22:16 UTC, Ali Çehreli wrote:

import std.bitmanip;
import std.system;

void main()
{
  ubyte[] data = [ 1, 2, 3, 4 ];
  assert(data.read!(uint, Endian.littleEndian) == 0x04030201);
}

Ali


I have std.system included... :s


What is the type of your data?


immutable ubyte[]


Re: undefined reference to `_D16TypeInfo_HAyayAa6__initZ'

2013-11-24 Thread Jeroen Bollen

On Sunday, 24 November 2013 at 12:07:18 UTC, Dejan Lekic wrote:
On Saturday, 23 November 2013 at 23:47:11 UTC, Adam D. Ruppe 
wrote:
On Saturday, 23 November 2013 at 23:30:09 UTC, Jeroen Bollen 
wrote:
I added the code to my GitHub repo; there don't seem to be 
any uncommon associative arrays:


Yea, it is the immutable string[string], I used the same 
pattern in my cgi.d and saw that too (sometimes, like I said, 
it is randomly there or not. it seems to be the outer 
immutable that triggers the problem.


BTW, my cgi.d has fastcgi support too
https://github.com/adamdruppe/misc-stuff-including-D-programming-language-web-stuff/blob/master/cgi.d

compile with -version=fastcgi. It uses the C libfcgi in that 
mode. Feel free to copy any of my code you want if it is 
helpful to you.


Adam, does it support multiplexing? Looks like people do not 
care much about that FastCGI feature... :(


My library does but it doesn't have an interface for requests yet 
so you'll have to manually 'build' them using the records.


Re: Read Byte Array to Integer

2013-11-23 Thread Jeroen Bollen

On Friday, 22 November 2013 at 23:12:25 UTC, Ali Çehreli wrote:
That means that the slice itself cannot be modified, meaning 
that it cannot be consumed by read. Can't work... :)


Why does read need to be able to change the byte array?


Re: Read Byte Array to Integer

2013-11-23 Thread Jeroen Bollen

On Saturday, 23 November 2013 at 15:21:02 UTC, Ali Çehreli wrote:

On 11/23/2013 04:08 AM, Jeroen Bollen wrote:

On Friday, 22 November 2013 at 23:12:25 UTC, Ali Çehreli wrote:
That means that the slice itself cannot be modified, meaning 
that it

cannot be consumed by read. Can't work... :)


Why does read need to be able to change the byte array?


From the documentation: The T.sizeof bytes which are read are 
consumed from the range.


  http://dlang.org/phobos/std_bitmanip.html#.read

When it comes to arrays, only slices that support popFront() 
are ranges.


Ali


So if I have a byte array [0, 0, 1, 0], and I read a ushort from 
it twice, I will get this?


ubyte[] arr = [0, 0, 1, 0];
arr.read!(ushort, Endian.littleEndian); // == 0
arr.read!(ushort, Endian.littleEndian); // == 1
arr.length; // == 0


undefined reference to `_D16TypeInfo_HAyayAa6__initZ'

2013-11-23 Thread Jeroen Bollen
I am getting this weird linker error when compiling my code; what 
does it mean?




Re: undefined reference to `_D16TypeInfo_HAyayAa6__initZ'

2013-11-23 Thread Jeroen Bollen

On Saturday, 23 November 2013 at 21:32:13 UTC, bearophile wrote:

Jeroen Bollen:

I am getting this weird linker error when compiling my code; 
what does it mean?


If your code used to work, and you have just tried dmd 2.064 
then as try to compile with -allinst.


Bye,
bearophile


No luck with that flag.


Re: undefined reference to `_D16TypeInfo_HAyayAa6__initZ'

2013-11-23 Thread Jeroen Bollen

On Saturday, 23 November 2013 at 22:34:54 UTC, bearophile wrote:

Jeroen Bollen:

I am getting this weird linker error when compiling my code; 
what does it mean?


Is your code not compiling since switching to a newer compiler? 
What system and compilers are you using? How many modules are 
in your program, and what build strategy/software are you using?


Bye,
bearophile


It's the first time I compiled it. I am using a regular compile 
command



dmd -m64 -of../Build/main (lots of files here)


Linux 64 bits


Re: undefined reference to `_D16TypeInfo_HAyayAa6__initZ'

2013-11-23 Thread Jeroen Bollen
On Saturday, 23 November 2013 at 22:49:54 UTC, Adam D. Ruppe 
wrote:
On Saturday, 23 November 2013 at 21:05:59 UTC, Jeroen Bollen 
wrote:
I am getting this weird linker error when compiling my code; 
what does it mean?


I saw this on stackoverflow first and answered there, let me 
link it:


http://stackoverflow.com/questions/20168136/linker-error-cannot-link-d16typeinfo-hayayaa6-initz/20168874#20168874

I've been seeing this problem on and off for years now, but can 
never get it minimized to a good test case. I think the order 
of files on the compile command line matter along with other 
hard to track down factors. So I just hack around it and move 
on.


Not sure if the type in there is right, I demangled it by 
eyeball (why wouldn't the core.demangle work on that? it isn't 
even that complex of a type, if I'm right...)


Flagged as Answer


Re: undefined reference to `_D16TypeInfo_HAyayAa6__initZ'

2013-11-23 Thread Jeroen Bollen
I added the code to my GitHub repo; there don't seem to be any 
uncommon associative arrays: 
https://github.com/SanePumpkins/FastCGI.D


Re: undefined reference to `_D16TypeInfo_HAyayAa6__initZ'

2013-11-23 Thread Jeroen Bollen
On Saturday, 23 November 2013 at 23:47:11 UTC, Adam D. Ruppe 
wrote:
On Saturday, 23 November 2013 at 23:30:09 UTC, Jeroen Bollen 
wrote:
I added the code to my GitHub repo; there don't seem to be any 
uncommon associative arrays:


Yea, it is the immutable string[string], I used the same 
pattern in my cgi.d and saw that too (sometimes, like I said, 
it is randomly there or not. it seems to be the outer immutable 
that triggers the problem.


BTW, my cgi.d has fastcgi support too
https://github.com/adamdruppe/misc-stuff-including-D-programming-language-web-stuff/blob/master/cgi.d

compile with -version=fastcgi. It uses the C libfcgi in that 
mode. Feel free to copy any of my code you want if it is 
helpful to you.


Your work actually inspired mine. I saw it used some external 
code so I am basically writing it without those. Somewhere in 
progress of that I managed to completely throw over the structure 
of the code, and well yeah, now I ended up with that. :P


Re: undefined reference to `_D16TypeInfo_HAyayAa6__initZ'

2013-11-23 Thread Jeroen Bollen
On Saturday, 23 November 2013 at 23:47:11 UTC, Adam D. Ruppe 
wrote:
On Saturday, 23 November 2013 at 23:30:09 UTC, Jeroen Bollen 
wrote:
I added the code to my GitHub repo; there don't seem to be any 
uncommon associative arrays:


Yea, it is the immutable string[string], I used the same 
pattern in my cgi.d and saw that too (sometimes, like I said, 
it is randomly there or not. it seems to be the outer immutable 
that triggers the problem.


BTW, my cgi.d has fastcgi support too
https://github.com/adamdruppe/misc-stuff-including-D-programming-language-web-stuff/blob/master/cgi.d

compile with -version=fastcgi. It uses the C libfcgi in that 
mode. Feel free to copy any of my code you want if it is 
helpful to you.


Does yHAyaAa mean:


immutable (immutable char)[char[]]


Itt seems pretty odd. :s


Re: MSG_WAITALL for Sockets

2013-11-20 Thread Jeroen Bollen

On Tuesday, 19 November 2013 at 23:36:57 UTC, Rob T wrote:
On Tuesday, 19 November 2013 at 18:35:08 UTC, Jeroen Bollen 
wrote:
Is there a way I can call a receive method on a socket with 
MSG_WAITALL as a flag? There doesn't seem to be an enum for 
that.


module core.sys.posix.sys.socket;

enum : uint
{
MSG_CTRUNC  = 0x08,
MSG_DONTROUTE   = 0x04,
MSG_EOR = 0x80,
MSG_OOB = 0x01,
MSG_PEEK= 0x02,
MSG_TRUNC   = 0x20,
MSG_WAITALL = 0x100
}


Use SocketFlags to set the flag.

If using Windows, you can set up your own enum, as I don't 
think one is pre-defined.


--rt


Thanks! I don't really get how this is working though, isn't the 
point of using an enum as a type, preventing any values that's 
not listed in the enum definition?


Re: Class References

2013-11-20 Thread Jeroen Bollen

On Monday, 18 November 2013 at 19:12:03 UTC, Ali Çehreli wrote:

On 11/18/2013 10:28 AM, Jeroen Bollen wrote:

Is it possible to do something like:

TestInterface testi = new classReferenceList[integer];


We still don't know what the use case is :) but it is possible 
to store types in a TypeTuple:


import std.stdio;
import std.typetuple;

interface I
{}

class C1 : I
{}

class C2 : I
{}

I makeObject(T)()
{
return new T();
}

I[] makeObjects(Ts...)()
{
I[] objects;

foreach (T; Ts) {
objects ~= makeObject!T();
}

return objects;
}

void main()
{
alias typeList = TypeTuple!(C1, C2);

auto objects = makeObjects!typeList();
writeln(objects);
}

The output:

[deneme.C1, deneme.C2]

Ali


I was more looking for a way to just access a type/class by 
specifying an index... I don't really get your code.


Class Array in D?

2013-11-20 Thread Jeroen Bollen

is there a way I can pass a TypeTulip to a function?
Something like:

Can I create a class array in D? Something like:

interface A {}
class AA: A {}
class AB: A {}
class AC: A {}

ClassList!A list = new ClassList!A {AA, AB, AC};

void testf(ulong testv) {
A a = new list[testv];
}

I know about TypeTuple but that doesn't allow setting a 
requirement does it?


Re: Class Array in D?

2013-11-20 Thread Jeroen Bollen

On Wednesday, 20 November 2013 at 18:23:37 UTC, Ali Çehreli wrote:

On 11/20/2013 10:12 AM, Jeroen Bollen wrote:

 is there a way I can pass a TypeTulip to a function?

alias TypeTulip = TypeTuple;

;)

 Something like:

 Can I create a class array in D? Something like:

 interface A {}
 class AA: A {}
 class AB: A {}
 class AC: A {}

 ClassList!A list = new ClassList!A {AA, AB, AC};

 void testf(ulong testv) {
  A a = new list[testv];
 }

 I know about TypeTuple but that doesn't allow setting a
requirement does
 it?

import std.stdio;
import std.typetuple;

interface A {}
class AA: A {}
class AB: A {}
class AC: A {}

alias TypeTulip = TypeTuple;
alias list = TypeTuple!(AA, AB, AC);

void testf(ulong testv) {
// NOTE: This is a compile-time foreach
foreach (i, Type; list) {
if (i == testv) {
A a = new Type();
writefln(I made it: %s, a);
}
}
}

void main()
{
testf(1);
}

Note that the foreach loop above is not a loop that gets 
executed at run time. Its body is expanded inline as code 
multiple times as needed. I try to explain this a little under 
the Compile-time foreach and foreach with TypeTuple 
sections here:


  http://ddili.org/ders/d.en/tuples.html

Ali


That doesn't allow specifying a base class all members should be 
a part of though, or does it?


How does noexcept work?

2013-11-19 Thread Jeroen Bollen

If I have a function:
@safe pure void functionName() {
return;
}
Where do I put the noexcept?


Re: How does noexcept work?

2013-11-19 Thread Jeroen Bollen

On Tuesday, 19 November 2013 at 18:09:29 UTC, Namespace wrote:
On Tuesday, 19 November 2013 at 18:01:19 UTC, Jeroen Bollen 
wrote:

If I have a function:
@safe pure void functionName() {
return;
}
Where do I put the noexcept?


Did you mean nothrow?
You can put it unfortunately on both sides.
left:

@safe pure nothrow void functionName() {
return;
}

right:
@safe pure void functionName() nothrow {
return;
}


Thanks, don't mind me being stupid. I was getting confused with 
C++. *facepalm*


MSG_WAITALL for Sockets

2013-11-19 Thread Jeroen Bollen
Is there a way I can call a receive method on a socket with 
MSG_WAITALL as a flag? There doesn't seem to be an enum for that.


Re: Cannot pass by reference

2013-11-18 Thread Jeroen Bollen

On Saturday, 16 November 2013 at 16:34:31 UTC, Ali Çehreli wrote:
The problem with your example is that unlike main.c in my 
example, what you pass is an rvalue, which may not be bound to 
the ref parameter.

Thanks, this is what I needed!


Re: Class References

2013-11-18 Thread Jeroen Bollen

Is it possible to do something like:

TestInterface testi = new classReferenceList[integer];


Calling Base Class Overriden Methods

2013-11-18 Thread Jeroen Bollen

How do I call a parent class's overidden method?

module test;

abstract class SuperClass {
public pure void methodA() {

}
}

class SubClass {
public override pure void methodB() {
// How do I call the parent methodA() from here?
}
}


Re: Calling Base Class Overriden Methods

2013-11-18 Thread Jeroen Bollen

On Monday, 18 November 2013 at 19:34:56 UTC, Adam D. Ruppe wrote:
On Monday, 18 November 2013 at 19:32:39 UTC, Jeroen Bollen 
wrote:

How do I call a parent class's overidden method?


super.method

so

abstract class SuperClass {
public pure void methodA() {

}
}

class SubClass : SuperClass {
public override pure void methodA() {
// calls the parents
super.methodA();
}
}


To do it from outside the class, you write the class name:


void main() {
auto obj = new SubClass();
obj.SuperClass.methodA(); // calls the specific super 
method

}


Thanks! :D

Why aren't these things in the documentation? :/


Cannot pass by reference

2013-11-16 Thread Jeroen Bollen

I cannot seem to pass values to functions by referece.

--
@safe public nothrow this(ref Socket socket) {
// Inside class modulename.classname
this.socket = socket;
}
--
void main() {
auto variablename = new modulename.classname(
cast(Socket) new TcpSocket() // main.d line 5
);
}
--

This code gives me a compile error:

main.d(5): Error: constructor modulename.classname.this (ref 
Socket socket) is not callable using argument types (Socket)

main.d(5): Error: no constructor for classname

Why is that?


Re: Cannot pass by reference

2013-11-16 Thread Jeroen Bollen

On Saturday, 16 November 2013 at 14:28:45 UTC, bearophile wrote:

Jeroen Bollen:


Why is that?


It's caused by the cast. The solution is to use an auxiliary 
value inside the main, or remove the cast.


Bye,
bearophile


Same error, but is not callable using argument types 
(TcpSocket)...


Array Defenitions

2013-11-13 Thread Jeroen Bollen
I feel there is a lack of resources/documentation on array 
definitions. I cannot believe the official documentation tries to 
explain how D handles arrays without defining an array a single 
time.


http://dlang.org/arrays.html


Re: Embed JavaScript into D

2013-11-04 Thread Jeroen Bollen

On Monday, 4 November 2013 at 19:45:23 UTC, Dicebot wrote:

On Monday, 4 November 2013 at 19:35:55 UTC, Jeroen Bollen wrote:
Is there a way I can embed javascript into my D application? I 
basically want to create a modular application which allows 
adding and removing plugins by dragging and dropping them into 
a folder. I love the idea of them being editable on the fly.


Don't know about JavaScript but there is a well-maintained Lua 
integration library : https://github.com/JakobOvrum/LuaD


Also with dmd compilation speeds you actually can just compiler 
shared library binaries of the fly from D plugin sources and 
get pretty much the same thing with pure D.


I would still prefer to use a scripting language though because 
of a lot of removed complexity for simple tasks.


Re: Embed JavaScript into D

2013-11-04 Thread Jeroen Bollen

On Monday, 4 November 2013 at 20:43:46 UTC, John Colvin wrote:

On Monday, 4 November 2013 at 20:18:19 UTC, Jeroen Bollen wrote:

On Monday, 4 November 2013 at 19:45:23 UTC, Dicebot wrote:
On Monday, 4 November 2013 at 19:35:55 UTC, Jeroen Bollen 
wrote:
Is there a way I can embed javascript into my D application? 
I basically want to create a modular application which 
allows adding and removing plugins by dragging and dropping 
them into a folder. I love the idea of them being editable 
on the fly.


Don't know about JavaScript but there is a well-maintained 
Lua integration library : https://github.com/JakobOvrum/LuaD


Also with dmd compilation speeds you actually can just 
compiler shared library binaries of the fly from D plugin 
sources and get pretty much the same thing with pure D.


I would still prefer to use a scripting language though 
because of a lot of removed complexity for simple tasks.


LuaD is great. There is also 
https://bitbucket.org/ariovistus/pyd/


The reason I'm not picking up any of these is purely based on my 
opinion, I hate developping in LUA or Python. Are there no 
JavaScript / PHP bindings available yet?


Re: Embed JavaScript into D

2013-11-04 Thread Jeroen Bollen

On Monday, 4 November 2013 at 22:22:32 UTC, Max Klyga wrote:

On 2013-11-04 21:20:46 +, Adam D. Ruppe said:

On Monday, 4 November 2013 at 19:35:55 UTC, Jeroen Bollen 
wrote:

Is there a way I can embed javascript into my D application?


You could use any C javascript lib too, but for ones already 
wrapped or something, I know there's a few D implementations 
of javascript: dmdscript 
http://www.digitalmars.com/dscript/index.html (written in D1 
but there's two or three ports out there to D2)


D1 version is now on github:
https://github.com/DigitalMars/DMDScript

D2 version:
http://dsource.org/projects/dmdscript-2/
pretty sure it will need tweaks to compile with current DMD 
version


You could rather easyly embed Mozilla Spidermonkey engine, as 
it provides a C api and D work great with C


I'm probably going with spidermonkey then. Didn't really know it 
had a C API... Thanks. :P