Re: using dub to compile plugins

2018-12-19 Thread Codifies via Digitalmars-d-learn

On Wednesday, 19 December 2018 at 16:31:57 UTC, Andre Pany wrote:

On Wednesday, 19 December 2018 at 14:08:10 UTC, Codifies wrote:
On Wednesday, 19 December 2018 at 13:14:20 UTC, Andre Pany 
wrote:
On Wednesday, 19 December 2018 at 12:57:14 UTC, Codifies 
wrote:

[...]


You can use dub sub packages. Each plugin will be a dub 
package with its own dub descriptor (sdl) file.

For your main dub sdl you set targetType to None.

Kind regards
Andre


how could I have multiple dub files in the same directory for 
each plugin ???


You have sub folders in which you create the dub.sdl files. In 
your main dub.sdl you include these folders as sub packages.


Regarding the automatic logic you ideally want to have: there 
is the plan to add dub extension plugins. Unfortunately a hero 
is needed to implement it.


Kind regards
Andre


I was planning to have all the plugin sources in one directory 
otherwise I'd have loads of folders all over the place...


I think Make is the way forward!


Re: using dub to compile plugins

2018-12-19 Thread Codifies via Digitalmars-d-learn

On Wednesday, 19 December 2018 at 13:14:20 UTC, Andre Pany wrote:

On Wednesday, 19 December 2018 at 12:57:14 UTC, Codifies wrote:

[...]


You can use dub sub packages. Each plugin will be a dub package 
with its own dub descriptor (sdl) file.

For your main dub sdl you set targetType to None.

Kind regards
Andre


how could I have multiple dub files in the same directory for 
each plugin ???


Re: using dub to compile plugins

2018-12-19 Thread Codifies via Digitalmars-d-learn
oh forgot to add just for extra pain while the main 
application won't need gtk, most of the plugins will...


using dub to compile plugins

2018-12-19 Thread Codifies via Digitalmars-d-learn

I am currently using this dub.sdl

name"runz80"
targetType  "executable"
lflags  "libz80/libz80.a"

however I will be creating a number of plugins, each plugin will 
consist of a single source file, I'd like the plugin source 
directory to be separate from main source directory and compile 
the plugins (.so) to a (binary) plugins directory


(the plugins will be dynamically loaded at runtime - I've 
previously done this in C so I don't anticipate any particular 
issues - famous last words!)


I could do this with a few simple rules in a Makefile, but I have 
no clue how to achieve this using dub.


can someone show me a concrete example of doing this ? Ideally 
just dropping a new source file into the plugins source folder 
should produce a new .so the next time dub is run, without having 
to explicitly add each plugin to the dub file...


Re: new returning the same memory....

2018-11-08 Thread Codifies via Digitalmars-d-learn

On Thursday, 8 November 2018 at 11:46:44 UTC, Codifies wrote:

when creating a new instance of a class

aclass a = new aclass();

I was under the impression that this created a new chunk of 
memory on the heap...


however I'm trying to create this class instance in another 
classes method, I also need to store a pointer to this newly 
created instance in the same method.


when I look at the actual value of the pointer, although it 
does change after multiple goes, frequently its the same value.


It almost looks like its allocating on the local stack and its 
made a new instance thats entirely local to the factory method.


do I need to manually allocate the memory ?? how do I do this? 
how can I allow the GC to clean this up?


I'm *really* discombobulated now, as new doesn't seem to be 
working how I thought it did!!!


I'll try to spin up a minimal example...


new returning the same memory....

2018-11-08 Thread Codifies via Digitalmars-d-learn

when creating a new instance of a class

aclass a = new aclass();

I was under the impression that this created a new chunk of 
memory on the heap...


however I'm trying to create this class instance in another 
classes method, I also need to store a pointer to this newly 
created instance in the same method.


when I look at the actual value of the pointer, although it does 
change after multiple goes, frequently its the same value.


It almost looks like its allocating on the local stack and its 
made a new instance thats entirely local to the factory method.


do I need to manually allocate the memory ?? how do I do this? 
how can I allow the GC to clean this up?


I'm *really* discombobulated now, as new doesn't seem to be 
working how I thought it did!!!


Re: is opOpAssign returning a value less than ideal ?

2018-11-08 Thread Codifies via Digitalmars-d-learn
On Thursday, 8 November 2018 at 06:01:57 UTC, Jonathan M Davis 
wrote:
On Wednesday, November 7, 2018 10:45:07 PM MST Jonathan M Davis 
via Digitalmars-d-learn wrote:

[...]


Rereading what you wrote, are you asking whether it's 
reasonable to return a value instead of a reference? 
Personally, I don't think that that's good design at all, but I 
also don't see any reason for the compiler to prevent it.


Personally, I think that the default design should be to return 
by ref. Returning void is less than ideal but isn't necessarily 
bad, depending on the situation (especially if we're not 
talking about a general purpose library). However, I expect 
that returning non-void by value rather than by ref is rarely 
-if ever - going to be a good design choice. It's just going to 
be confusing and not particularly useful.


- Jonathan M Davis


NB its not returning a ref to the list, its returning the newly 
created node when you use the operator you add a type to the 
list, so it possibly wouldn't be that much use for chaining?


is opOpAssign returning a value less than ideal ?

2018-11-07 Thread Codifies via Digitalmars-d-learn

I noticed that opOpAsign allows you to return a value...

this means I can do this (return a node from my list class when 
adding a new node)

```
anode = alist ~= &someData;
```
to me this looks a little unusual (but to be fair I can live with 
it)


being as when its used like this:
```
alist ~= &someData;
```
you need to find out what the ~ operator does anyway, I don't 
think it harms readability


any thoughts?



Re: expanding variadic into format

2018-10-31 Thread Codifies via Digitalmars-d-learn
On Wednesday, 31 October 2018 at 12:54:52 UTC, Stanislav Blinov 
wrote:

On Wednesday, 31 October 2018 at 12:13:57 UTC, Codifies wrote:

[...]



[...]


As rikki already explained, std.format is a variadic template, 
which gets expanded into argument list at compile time. That's 
why it can't be used with C-syle variadics: when you passed 
_arguments, the expansion treated that as a single argument 
instead of a tuple.
Therefore, to forward arguments to std.format, your 
`printValue` must also be a variadic.


[...]


thanks for this makes it a lot clearer, I'm guessing there is a 
mailing list backing this web forum, as I replied missing some 
other responses.


Re: expanding variadic into format

2018-10-31 Thread Codifies via Digitalmars-d-learn
On Wednesday, 31 October 2018 at 12:09:04 UTC, Stanislav Blinov 
wrote:

On Wednesday, 31 October 2018 at 11:53:52 UTC, Codifies wrote:


void printValue(Font fnt,float x, float y, string frmt, ...)
{
/* matrix math and other stuff removed for readability */
string message = format(frmt, _arguments);




is there some way to somehow transfer my input variadic into 
formats variadic ?



Just to confirm, format there is std.format:format right?
Because that isn't using C variadics, its using template 
variadics.


...as in:

```
void printValue(Args...)(Font fnt, float x, float y, string 
frmt, auto ref Args args) {

// ...
import std.functional : forward;
string message = format(frmt, forward!args);
// ...
}
```


thats fantastic thanks so much, can you explain a little more 
about whats going on here ?


Re: expanding variadic into format

2018-10-31 Thread Codifies via Digitalmars-d-learn
On Wednesday, 31 October 2018 at 11:56:31 UTC, rikki cattermole 
wrote:

On 01/11/2018 12:53 AM, Codifies wrote:

[...]


Just to confirm, format there is std.format:format right?

Because that isn't using C variadics, its using template 
variadics.


thought I was using core.vararg and std.format both using 
templates ??


expanding variadic into format

2018-10-31 Thread Codifies via Digitalmars-d-learn
I have a routine that was happily printing ASCII strings and 
values using opengl, however I want to improve it so it can be 
used in the same manner as some other languages printf function...


void printValue(Font fnt,float x, float y, string frmt, ...)
{
/* matrix math and other stuff removed for readability */
string message = format(frmt, _arguments);


no surprise this naive attempt causes a runtime error as its 
trying to format a range using the first format specifier in frmt


am I going to have to chop frmt into descrete chunks that have 
just one % symbol in them and then build up the formatted message 
string like that?


is there some way to somehow transfer my input variadic into 
formats variadic ?


Re: why is the default floating point value NAN ?

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

On Wednesday, 17 October 2018 at 15:48:16 UTC, Codifies wrote:

I'd have thought it ought to be 0.0 ?

So far I seen carefully considered and sensible reasons for 
doing things in D, so why NAN ?


okay I should have carried on reading the blog, its so 
uninitialized values stick out when debugging...


why is the default floating point value NAN ?

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

I'd have thought it ought to be 0.0 ?

So far I seen carefully considered and sensible reasons for doing 
things in D, so why NAN ?


ref tidy way to defreference or is something else going on ?

2018-10-16 Thread Codifies via Digitalmars-d-learn
I've a bunch of 4x4 matrix routines in C, in order to avoid 
copying around multiple 4x4 matrices I pass pointers...


I'm assuming that in D it would make sense to use ref ?

what's going on behind the scenes with ref is it just a nice way 
of passing pointers with automagical dereferencing or is 
something more going on?


Re: custom sorting of lists ?

2018-10-14 Thread Codifies via Digitalmars-d-learn
On Sunday, 14 October 2018 at 01:31:26 UTC, Jonathan M Davis 
wrote:


Unless there's something about the implementation that's tied 
to the list itself, I would think that it would make more sense 
to make it a generic algorithm, then it will work with any 
non-random-access range, and it avoids needing to reimplement 
it for similar circumstances. IMHO, it really only makes sense 
to tie it to the container if the implementation itself needs 
to be for some reason.


- Jonathan M Davis


I'm currently using this...

https://dpaste.dzfl.pl/09ea7fa8c58c

you can delete/insert from anywhere in the list, sort it, and 
even produce an array from it...




Re: ported a sortable list from my old C code

2018-10-13 Thread Codifies via Digitalmars-d-learn

On Saturday, 13 October 2018 at 11:28:08 UTC, Alex wrote:

Something is wrong with the link :(


https://dpaste.dzfl.pl/af9e6f6ce53e



Re: ported a sortable list from my old C code

2018-10-13 Thread Codifies via Digitalmars-d-learn

On Saturday, 13 October 2018 at 11:28:08 UTC, Alex wrote:

On Saturday, 13 October 2018 at 11:11:41 UTC, Codifies wrote:

https://run.dlang.io/gist/b8b03ce3246951b5356db064ab68b22e

its a bit fugly at the moment and I want to use something 
other than a void pointer (any?) (the whole thing was very 
pointer centric as everything was malloc'd...)


I'm not entirely sure it would benefit from turning into a 
class ?


Does anyone has any ideas on improving this sortable list


Something is wrong with the link :(


gutted  anywhere else I can post it?


ported a sortable list from my old C code

2018-10-13 Thread Codifies via Digitalmars-d-learn

https://run.dlang.io/gist/b8b03ce3246951b5356db064ab68b22e

its a bit fugly at the moment and I want to use something other 
than a void pointer (any?) (the whole thing was very pointer 
centric as everything was malloc'd...)


I'm not entirely sure it would benefit from turning into a class ?

Does anyone has any ideas on improving this sortable list


Re: custom sorting of lists ?

2018-10-13 Thread Codifies via Digitalmars-d-learn
On Saturday, 13 October 2018 at 07:48:04 UTC, Jacob Carlborg 
wrote:

On 2018-10-12 21:40, Codifies wrote:
a while ago I wrote a doubly linked list (in C), which has a 
compare callback to allow custom sorting for example


int cmpNodes(cnode_t* n1, cnode_t* n2)
{
   mapNode_t* rn1 = (mapNode_t*)(n1->data);
   mapNode_t* rn2 = (mapNode_t*)(n2->data);
   if (rn1->G + rn1->H > rn2->G + rn2->H) return 1;
   return 0;
}

would be called by

clistSort(openList, cmpNodes);

The list would then be ordered by G + H fields (or any other 
algorithm you code)



I notice there is a doubly linked list in the standard 
library, however it doesn't seem to allow for a custom 
compare, I'd rather not port my old C list code, can someone 
please give me some clues as to how I can reorder a list with 
a custom comparison...?


I don't think you can sort a list because sorting requires 
random access, which a list doesn't provide. Is there a reason 
you cannot use an array?


it to port my old C pathfinding code, at the start of the path 
you don't know how long it will be and it need to grow and shrink 
depending on the obstacles and different potential paths it 
finds, using a list is just easier, I've ended up porting my C 
doubly linked list that has its own simple bubble sort...


Re: custom sorting of lists ?

2018-10-12 Thread Codifies via Digitalmars-d-learn
On Friday, 12 October 2018 at 20:29:27 UTC, Steven Schveighoffer 
wrote:

On 10/12/18 3:40 PM, Codifies wrote:

[...]


Unfortunately, I can't find a way to sort a doubly linked list 
in phobos, so comparisons are somewhat moot.


However, if there *were* a sorting routine, generally the 
comparison function is done via whatever type you give it, or 
is given a custom comparison routine.


In my ancient dcollections library linked-list sorting is 
supported via a `less` parameter: 
https://github.com/schveiguy/dcollections/blob/82118cfd4faf3f1ad77df078d279f1b964f274e7/dcollections/LinkList.d#L997


-Steve


I think I'll look later and see if the links (in the dlist) are 
accessible, I could at least implement a bubble sort if I can 
swap two nodes


custom sorting of lists ?

2018-10-12 Thread Codifies via Digitalmars-d-learn
a while ago I wrote a doubly linked list (in C), which has a 
compare callback to allow custom sorting for example


int cmpNodes(cnode_t* n1, cnode_t* n2)
{
  mapNode_t* rn1 = (mapNode_t*)(n1->data);
  mapNode_t* rn2 = (mapNode_t*)(n2->data);
  if (rn1->G + rn1->H > rn2->G + rn2->H) return 1;
  return 0;
}

would be called by

clistSort(openList, cmpNodes);

The list would then be ordered by G + H fields (or any other 
algorithm you code)



I notice there is a doubly linked list in the standard library, 
however it doesn't seem to allow for a custom compare, I'd rather 
not port my old C list code, can someone please give me some 
clues as to how I can reorder a list with a custom comparison...?


Re: typo mapNode[6]* exits; instead of mapNode*[6] exits; but whats it mean ?

2018-10-10 Thread Codifies via Digitalmars-d-learn

On Wednesday, 10 October 2018 at 13:36:20 UTC, Simen Kjærås wrote:

mapNode[6]* can be read right-to-left as 'a pointer to an array


right... hence the failed attempt at an array copy... now I 
understand...


typo mapNode[6]* exits; instead of mapNode*[6] exits; but whats it mean ?

2018-10-10 Thread Codifies via Digitalmars-d-learn
I'm not sure I understand what mapNode[6]* means! (the second 
version is what I wanted an array of 6 pointers)


oddly when assigning a null to one element of the array it cause 
an error as it was trying to do an array copy... so what's going 
on and what does that definition actually mean ?