Intelligent enums

2017-01-18 Thread Ignacious via Digitalmars-d-learn
I have the need to create an enum flag like structure to specify 
certain properties of a type easily.


e.g.,

enum properties
{
   Red,
   Blue,
   Hot,
   Sexy,
   Active,
   ...
}

But some properties will be mutually exclusive. I would like to 
contain all those rules for in the enum itself for obvious 
reasons(encapsulation).


I guess I'm going to be told to use static and structs, but I'm 
hoping for a more elegant solution.





Re: alias not valid with ~

2017-01-18 Thread Ignacious via Digitalmars-d-learn
On Thursday, 19 January 2017 at 02:51:03 UTC, rikki cattermole 
wrote:

On 19/01/2017 3:35 PM, Ignacious wrote:
On Thursday, 19 January 2017 at 02:25:44 UTC, Adam D. Ruppe 
wrote:
On Thursday, 19 January 2017 at 02:15:04 UTC, rikki 
cattermole wrote:

On 19/01/2017 3:08 PM, Ignacious wrote:


class Y
{
   int y;
   alias y this;
}

class X
{
   Y[] x;
   alias x this;
}



This should not fail:

X x = new X;
x ~= 3;



Yes, it should fail. 3 is not implicitly convertible to Y 
under any

circumstance. D does not support implicit constructors.

alias this only works if you ALREADY HAVE a Y, then it will 
implicitly

convert Y to int. It will never go the other way around.


Huh?

But this is alias this, the whole point of alias this is to 
treat the

type as as the alias?

You are saying it basically only works one way, seems to make 
alias this
quite useless(50% at least). Is there any real reason why this 
doesn't

work?

X x;
Y y;
y = 3;

x ~= y; works fine
x ~= 3; fails.

Yet, logically, 3 is convertible to Y(3rd line above) and Y is
appendable to X.

Seems to me that D simply hasn't added the logic to handle the 
case for

implicit construction for alias this, why not add it?


It is not implicitly convertible in any form.
An integer is just a value, probably stored in a register or 
directly encoded into an instruction.




so? An integer is just a type. Where it is stored or how is 
irrelevant.



A class instance is always allocated into memory, in pretty 
much all cases the heap (stack is explicit in D). So what 
you're suggesting would require an allocation + calling of a 
constructor to make it equal.




So.

Now, lets say Y was a struct, then yeah it can work. Because a 
struct is nothing more than a set of values that go together. 
Which are commonly allocated on the stack and for smaller ones, 
be passed around by only registers.


So. If it worked for a struct as you suggest it should for for 
any type.


What you are suggesting is that the compiler(or maybe the 
compiler programmer) is not able to create a rewrite rule. It 
obviously can. So your reasons are flawed.


The reason question you should ask yourself is is there any 
reason not to do it, instead of trying to find reasons it can't 
be done(sounds more like you are grasping at straws/guessing).


You should realize any time one can program something explicit 
the compiler can be made to do it implicit. The question is the 
consequences of such actions. In this case, regardless if we use 
3 and convert explicitly or not ~ requires an allocation, so 
allocations alone are not enough to prevent it.






Re: alias not valid with ~

2017-01-18 Thread Ignacious via Digitalmars-d-learn

On Thursday, 19 January 2017 at 02:25:44 UTC, Adam D. Ruppe wrote:
On Thursday, 19 January 2017 at 02:15:04 UTC, rikki cattermole 
wrote:

On 19/01/2017 3:08 PM, Ignacious wrote:


class Y
{
   int y;
   alias y this;
}

class X
{
   Y[] x;
   alias x this;
}



This should not fail:

X x = new X;
x ~= 3;



Yes, it should fail. 3 is not implicitly convertible to Y under 
any circumstance. D does not support implicit constructors.


alias this only works if you ALREADY HAVE a Y, then it will 
implicitly convert Y to int. It will never go the other way 
around.


Huh?

But this is alias this, the whole point of alias this is to treat 
the type as as the alias?


You are saying it basically only works one way, seems to make 
alias this quite useless(50% at least). Is there any real reason 
why this doesn't work?


X x;
Y y;
y = 3;

x ~= y; works fine
x ~= 3; fails.

Yet, logically, 3 is convertible to Y(3rd line above) and Y is 
appendable to X.


Seems to me that D simply hasn't added the logic to handle the 
case for implicit construction for alias this, why not add it?




alias not valid with ~

2017-01-18 Thread Ignacious via Digitalmars-d-learn


class Y
{
   int y;
   alias y this;
}

class X
{
   Y[] x;
   alias x this;
}


Yet X ~= 3; fails.

3 should be implicitly convertible to Y and then ~ should assign 
it.


?





writeln and ~

2017-01-14 Thread Ignacious via Digitalmars-d-learn

string concatenation is weird.

We can do stuff like

writeln(x);

where x is, say a struct and it prints fine

but when we do

writeln(x ~ " ok");

it fails and requires us to convert x!

Why can't string concatenation automatically try to convert the 
arguments? Is there any reason this is bad behavior?


How bout then having writeln parse the arguments as a string(take 
an alias or something first) and then automatically convert them?


Seems like there is no real excuse to add such obfuscation...

Obviously I can roll my own but that is not an acceptable answer.





Re: switch to member

2017-01-14 Thread Ignacious via Digitalmars-d-learn

On Saturday, 14 January 2017 at 11:32:10 UTC, Marc Schütz wrote:
You can utilize a little-known `switch` syntax trick in 
combination with `foreach`. Because a `foreach` over tuples is 
unrolled at compile time, it works even if your fields don't 
have exactly the same types:


--

struct Foo {
int x, y;
long a, b, c;
short i, j, k;
}

enum Which {
x, y, a, b, c, i, j, k,
}

void assignValue(ref Foo q, Which member, short e) {
import std.traits : EnumMembers;
import std.conv : to;

final switch(member) {
// foreach over a tuple is unrolled at compile time
foreach(w; EnumMembers!Which) {
case w:
// expands to: q.x, q.y, ...
mixin("q." ~ w.to!string) = e;
break;
}
}
}

void main() {
import std.stdio : writeln;
Foo q;
writeln("before: ", q);
assignValue(q, Which.a, 42);
assignValue(q, Which.x, 1);
writeln("after: ", q);
}


Cool, pretty straightforward and somewhat easy to use. I suppose 
it might be easier to mark the enum members with an attribute 
though and use that rather than having two enums? I didn't know 
about the foreach in the switch, cool idea!


Thanks.



Re: switch to member

2017-01-14 Thread Ignacious via Digitalmars-d-learn

On Saturday, 14 January 2017 at 08:30:04 UTC, Meta wrote:
On Saturday, 14 January 2017 at 05:29:49 UTC, Nicholas Wilson 
wrote:

enum XX
{
X = Q.X.offsetof,
Y = Q.Y.offsetof
//ect.
}

and then

*(cast(void*)(this) + x) = e; //if inside struct/class

or
*(cast(void*)(q) + x) = e; // if outside

Unfortunately this loses you `@safe`ty, but as long as you 
trust

the value of x then it should be safe to `@trusted` that code.

If you are trying to avoid code duplication the enum 
declaration of X

could also be done with a string mixin.


IMO this is massive overkill to save some typing. To the OP, 
it's not really worth it to go to so much trouble. Just write 
some slightly duplicated code and move on.


Go join the Nazi Youth group, you OSS Sympathizer!


switch to member

2017-01-13 Thread Ignacious via Digitalmars-d-learn
When doing common functionality for a switch, is there any way to 
optimize:


switch(x)
{
case X:
 q.X = e;
 break;
case Y:
 q.Y = e;
 break
etc...
}

e is basically a value that, depending on the what kind(x), we 
assign it to a field in q. The name of the field and the case 
label are identical(in fact, it wouldn't hurt to do it either 
automatically(if x's enum name, if exists, matches a field, auto 
assign) or create the field in the class q automatically if the 
label matches a certain range or set).


Basically the idea is to avoid duplicating a lot of code.

I imagine one could write a string mixin that generates the cases 
and assignments but I'm hoping for a more elegant solution.


Re: Auto recursive function

2017-01-11 Thread Ignacious via Digitalmars-d-learn

On Wednesday, 11 January 2017 at 19:23:10 UTC, Razvan Nitu wrote:

Hi,

I am currently trying to create a function 
makeMultidimensionalArray which allocates memory for a 
multidimensional array. It is very similar with [1],

the difference being that it is uninitialized. Here is the code:

auto makeMultidimensionalArray(T, Allocator)(auto ref Allocator 
alloc, size_t[] lengths)

{
if (lengths.length == 1)
{
return makeArray!T(alloc, lengths[0]);
}
else
{
alias E = typeof(makeMultidimensionalArray!T(alloc, 
lengths[1..$]));

auto ret = makeArray!E(alloc, lengths[0]);
foreach (ref e; ret)
e = makeMultidimensionalArray!T(alloc, 
lengths[1..$]);

return ret;
}
}

The lengths[] specifies the lengths for each dimension. The 
problem with this code is that auto is going to be evaluated to 
T[] for the first time and when it
recurs, creating T[][] I get the error "mismatched function 
return type inference of T[][] and T[]". Is there a way to 
surpass that? I saw that in [1]
the recursive call is done by prefixing the function name with 
a '.'; I tried that but it doesn't work. I must be missing 
something, any ideas?


Thanks,
RazvanN

[1] 
https://github.com/dlang/phobos/blob/master/std/experimental/ndslice/slice.d#L834



If you change the return type to a void* your code basically 
works.



void* makeMultidimensionalArray(T, Allocator)(auto ref Allocator 
alloc, size_t[] lengths)

{
if (lengths.length == 1)
{
int x = 0x01FEEF01;
return cast(void*)makeArray!T(alloc, lengths[0], x);
}
else
{
alias E = typeof(makeMultidimensionalArray!T(alloc, 
lengths[1..$]));


auto ret = makeArray!E(alloc, lengths[0]);
foreach (ref e; ret)
e = makeMultidimensionalArray!T(alloc, lengths[1..$]);
return cast(void*)ret;
}
}

The problem is that then you need to cast back and that 
essentially results in the original problem. Can be done but 
probably gonna have to use string mixins.


Re: Android Status

2017-01-11 Thread Ignacious via Digitalmars-d-learn

On Wednesday, 11 January 2017 at 03:49:42 UTC, Joakim wrote:

On Tuesday, 10 January 2017 at 18:48:17 UTC, Ignacious wrote:

[...]


It's probably not easier, and in any case, android-x86 won't be 
supported, largely because I don't have any working x86 devices.


[...]


Ok, well the x86 thing wasn't my idea! It seems I was using the 
wrong build command for trying to compile the examples.


In any case, I'll just wait until things get working a bit 
better. I'd suggest you put, in the title of the page, a bit more 
information. I didn't realize I was looking at an old 
version(which looks too similar to the new one).




Re: Auto recursive function

2017-01-11 Thread Ignacious via Digitalmars-d-learn

On Wednesday, 11 January 2017 at 19:23:10 UTC, Razvan Nitu wrote:

Hi,

I am currently trying to create a function 
makeMultidimensionalArray which allocates memory for a 
multidimensional array. It is very similar with [1],

the difference being that it is uninitialized. Here is the code:

auto makeMultidimensionalArray(T, Allocator)(auto ref Allocator 
alloc, size_t[] lengths)

{
if (lengths.length == 1)
{
return makeArray!T(alloc, lengths[0]);
}
else
{
alias E = typeof(makeMultidimensionalArray!T(alloc, 
lengths[1..$]));

auto ret = makeArray!E(alloc, lengths[0]);
foreach (ref e; ret)
e = makeMultidimensionalArray!T(alloc, 
lengths[1..$]);

return ret;
}
}

The lengths[] specifies the lengths for each dimension. The 
problem with this code is that auto is going to be evaluated to 
T[] for the first time and when it
recurs, creating T[][] I get the error "mismatched function 
return type inference of T[][] and T[]". Is there a way to 
surpass that? I saw that in [1]
the recursive call is done by prefixing the function name with 
a '.'; I tried that but it doesn't work. I must be missing 
something, any ideas?


Thanks,
RazvanN

[1] 
https://github.com/dlang/phobos/blob/master/std/experimental/ndslice/slice.d#L834



This is probably not possible. You are trying to have multiple 
return types for the same function. You are thinking that each 
recursive call is a new template but that doesn't seem to be the 
case.



Instead, maybe try using string mixins to generate the 
allocations. Should be quite easy and will work.


You could also try to use a helper function that you pass the 
fully declared array(all dimensions) and the helper function then 
allocates each dimension recursively... The difference is that 
you are not passing around/returning sub-arrays so you don't have 
to worry about type mismatches.








Re: Android Status

2017-01-10 Thread Ignacious via Digitalmars-d-learn

Well, I posed a reply but I guess it didn't get though ;/

I'm only suing android-x86 because I thought it would be easier 
to test/debug. My device is a cortex-arm7.


Two questions I have:

1. In the command lines present there is a lot of use of `x86`. I 
used them to compile the hello world for my device and it worked 
so I'm a bit confused. I realize there is the x86 binaries for 
compiling and then the binaries that are compiled to but not sure 
what is what.


2. I downloaded the native_app_glue.d and tried to compile it. It 
imports jni.d which I found in hello-jni and I copied that to the 
android folder and was able to compile it using effectively the 
same command line I used to compile the working hello world code.


but when I try to then use it to compile the hello-jni sample I 
get that it is an invalid format and many ELF relocation errors.


Could you send me your working native_app_glue.o(if for the 
cortex-arm7 or try to compile it for both cortex-arm7 and 
x86/x64) or explain to me what is the issue with linking it in 
and how to fix it?



cmdline that compiles android_native_app_glue.d
bin/ldc2 -m32 -shared  -Iandroid -c android_native_app_glue.d

(tried with -m64 and without either)

cmdline trying to compile hello-jni.

 $NDK/toolchains/llvm/prebuilt/linux-x86_64/bin/clang 
-Wl,-soname,libhello-jni.so -shared 
--sysroot=$NDK/platforms/android-9/arch-x86 
../obj/local/x86/objs-debug/hello-jni/hello-jni.o 
../android_native_app_glue.o -lgcc  -gcc-toolchain  
$NDK/toolchains/x86-4.8/prebuilt/linux-x86 -target 
i686-none-linux-android -no-canonical-prefixes  
-Wl,--no-undefined -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now  
-L$NDK/platforms/android-9/arch-x86/usr/lib -llog -landroid -lEGL 
-lGLESv1_CM -llog -lc -lm -fuse-ld=bfd 
-L../../../phobos/generated/linux/release/32 -l:libphobos2.a -o 
../libs/libhello-jni.so


which gives the errors


/usr/bin/ld.bfd: ../android_native_app_glue.o: Relocations in 
generic ELF (EM: 40)
/usr/bin/ld.bfd: ../android_native_app_glue.o: Relocations in 
generic ELF (EM: 40)
/usr/bin/ld.bfd: ../android_native_app_glue.o: Relocations in 
generic ELF (EM: 40)
../android_native_app_glue.o: error adding symbols: File in wrong 
format
clang: error: linker command failed with exit code 1 (use -v to 
see invocation)


It might be better to wait for you to finish your build setup 
which might resolve all these problems and be more robust(I'd 
like to be able to easily build for different platforms(for 
testing on VM and device). But if all I need to do is get the 
android_native_app_glue to work to run full fledged apps, then It 
seems I'm close? (just need to compile it to the correct format?)



Thanks for all the help!


Re: Android Status

2017-01-09 Thread Ignacious via Digitalmars-d-learn

How difficult is it to build for x86/x64?

Would be nice to be able to use something like

http://www.android-x86.org/

as a test instead of an actual device.

Does one simply have to use the proper ldc2/dmd and link in the 
correct libs? or is it more complex?


Also, I'm a bit confused on how to compile the source 
examples(working it out and trying to explain the solutions as I 
type)


https://wiki.dlang.org/Build_DMD_for_Android

(set $NDK permanently)
I have done(easy, find the file and modify)

rt_init();
android_main(android_app);
rt_term();

Clean up and compile as before:

$NDK/ndk-build clean
NDK_TOOLCHAIN_VERSION=clang $NDK/ndk-build V=1

But no error. Object files for various architectures are created 
though, it seems. (rt_ errors do no exist contrary to what is 
said in the docs)



But the following seems need updating/explaining. I am using 
prebuilt ldc2 for android from some link you provided. -android 
doesn't seem to work and I can't find sensor.d (not sure if it is 
needed anymore)?


../../../dmd/src/dmd -android -I../.. 
-ofobj/local/x86/objs/native-activity main.o -c jni/main.d 
../../android/sensor.d


I had to change to use ldc2, remove -android, and obviously 
change the file names and such(and download the android dir from 
github).


$NDK/toolchains/llvm-3.5/prebuilt/linux-x86/bin/clang 
-Wl,-soname,libnative-activity.so -shared 
--sysroot=$NDK/platforms/android-9/arch-x86 
./obj/local/x86/objs/native-activity/main.o 
./obj/local/x86/libandroid_native_app_glue.a -lgcc  
-gcc-toolchain  $NDK/toolchains/x86-4.8/prebuilt/linux-x86 
-target i686-none-linux-android -no-canonical-prefixes  
-Wl,--no-undefined -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now  
-L$NDK/platforms/android-9/arch-x86/usr/lib -llog -landroid -lEGL 
-lGLESv1_CM -llog -lc -lm -fuse-ld=bfd
-L../../../phobos/generated/linux/release/32 -l:libphobos2.a -o 
./libs/x86/libnative-activity.so


Seems a lot of the paths are wrong/different than what I have

$NDK/toolchains/llvm-3.5/prebuilt/linux-x86/bin/clang 
-Wl,-soname,libhello-jni.so -shared 
--sysroot=$NDK/platforms/android-9/arch-x86 
./obj/local/x86/objs-debug/hello-jni/main.o 
./obj/local/x86/libandroid_native_app_glue.a -lgcc  
-gcc-toolchain  $NDK/toolchains/x86-4.8/prebuilt/linux-x86 
-target i686-none-linux-android -no-canonical-prefixes  
-Wl,--no-undefined -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now  
-L$NDK/platforms/android-9/arch-x86/usr/lib -llog -landroid -lEGL 
-lGLESv1_CM -llog -lc -lm -fuse-ld=bfd 
-L../../../phobos/generated/linux/release/32 -l:libphobos2.a -o 
./libs/x86/libhello-jni.so



I am going to zip of what I have so you can see how the paths are 
laid out: http://www.filedropper.com/ldc2android


There seems to be no obj file generated except for debug, that 
was probably intentional but the given command line doesn't 
represent that if so.



It is a bit confusing for the beginner to come along and try to 
get all this to work when there is contradictory information. The 
reason being is simple in that a beginner won't know what is used 
for what and the docs essentially are give as "plug and play" yet 
don't actually work... rather than being descriptive and 
explaining exactly what is what(some of it should be obvious but 
not all will be to someone that isn't versed in linux and android 
development or used to windows which abstracts everything).


What would be nice, at a minim, is a bash script that allows one 
to adjust different variables for different situations and then 
it can be used to compile. (e.g., set the obj path, ndk path, 
ldc2 path, etc)


What really needs to be done, IMO, is to have a simple set of 
tools(scripts or whatever) that can be configured easily and 
abstracts the complexity. (I've done that for the test script I 
made


#!/bin/bash

/mnt/c/dlang/ldc2Android/bin/ldc2 -c $1.d

$NDK/toolchains/llvm/prebuilt/linux-x86_64/bin/clang 
-Wl,-z,nocopyreloc --sysroot=$NDK/platforms/android-9/arch-arm 
-lgcc -gcc-toolchain 
$NDK/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64 
-target armv7-none-linux-androideabi -no-canonical-prefixes 
-fuse-ld=bfd -Wl,--fix-cortex-a8 -Wl,--no-undefined 
-Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now -fPIE -pie -mthumb 
-Wl,--export-dynamic -lc -lm $1.o lib/libphobos2-ldc.a 
lib/libdruntime-ldc.a -o $1



which does the compiling for me without having to type all that 
junk in each time.. pretty simple but does the job, a more 
advanced concept could be used to help make it easier on people

)

If you want, and you can accomplish this, if there was an 
ldc2/dmd2 for android that runs on windows I could work on 
getting it working for windows(as I prefer it rather than linux, 
which I have no real experience with). I'm thinking everything 
more or less would work similarly(since sdk/ndk exists for 
windows). It would just be a matter of translating paths and 
such. I could easily write a wrapper to reduce the complexity.



The main problem I seem to be having are 

Re: Android Status

2017-01-09 Thread Ignacious via Digitalmars-d-learn

On Monday, 9 January 2017 at 08:28:04 UTC, Joakim wrote:

On Monday, 9 January 2017 at 00:40:35 UTC, Ignacious wrote:

On Sunday, 8 January 2017 at 22:19:31 UTC, Joakim wrote:

On Sunday, 8 January 2017 at 21:52:01 UTC, Ignacious wrote:
Not sure what is going on, of course ;) So much BS just to 
do something that is suppose to be simple ;)



test.d



void main()
{

}

here is test.o

http://pastebin.com/NRrKgKtb

Any ideas?


Oh, that's easy: install the NDK too, as shown on the wiki.  
You need the linker that supports ARM from the NDK.  Follow 
the instructions from the wiki to compile and link the 
binary, simply having ldc do everything won't work.




Ok, after executing

$NDK/toolchains/llvm/prebuilt/linux-x86_64/bin/clang 
-Wl,-z,nocopyreloc --sysroot=$NDK/platforms/android-9/arch-arm 
-lgcc -gcc-toolchain 
$NDK/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64 -target armv7-none-linux-androideabi -no-canonical-prefixes -fuse-ld=bfd -Wl,--fix-cortex-a8 -Wl,--no-undefined -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now -fPIE -pie -mthumb -Wl,--export-dynamic -lc -lm test.o lib/libphobos2-ldc.a lib/libdruntime-ldc.a -o test


I get a test elf file with no errors(although 2.5MB for a 
hello world).


I had to do the chmod 755 test

then

./test

to get any output. Before that no output and no errors so 
wasn't sure what as going on.


Looks like everything is working! ;)


Good to hear it finally works. :D

Seems like someone really needs to put some time in to getting 
all this stuff organized and situated


Maybe the D language foundation can push some money towards it 
to get it started off on the right foot?


I'll try to get some of the opengl examples on your repository 
to see if they work soon.


I don't think money is the issue as much as people like you 
trying it on your own platform and documenting any problems you 
find.


ssshhh! Don't say that! Money always help!!! ;)



Cross-compiler toolchains are never simple, consider yourself 
lucky for having gotten off easy. :)


I realize things are difficult but it's people that make it 
that way ;) Life would be so much simpler if people would just 
properly document stuff exactly(or, rather, do what they are 
suppose to do). (Even windows seems to love to forget to put 
in descriptions of services, tasks, application descriptions, 
etc).


I've tried to write up detailed instructions on the wiki.  I'm 
still improving those and plan to spin off those two sections I 
linked you, on how to just build the samples, into their own 
page.  You can contribute any steps you had to take with 
Bash/Ubuntu on Windows with the prebuilt linux/x64 
cross-compiler there, once I put the page up.



Yeah, I found it a bit confusing though. It seems like it is 
written up by someone that is working on the core rather than a 
newb! ;)



The main problem I have had seems to be that UoW uses ver 14. 
Somehow I was able to upgrade by following docs online(wasn't 
easy but eventually got there and everything seems to work... 
I should have documented ;) but I wasn't sure if the process 
would work. Supposedly ver 16 exists by one has to be part of 
the dev team or something.


If you know all the steps to upgrade Ubuntu on Windows, you may 
want to document them on the wiki page I will put up or link to 
a good resource that shows how to do it.



I don't because it was all new to me(I didn't know there was even 
such a thing as UoW.  I simply searched for the errors I got and 
tried different solutions until it worked. Luckily the outcome 
worked... which is not always the case.


I think that it would be a boon for D to have some type of well 
defined and well planned Android development suite rather than 
what seems to be hacked/cobbled together. This would bring not 
only more developers to D for android but also to D in general.


I'm gonna try the opengl examples and hopefully the work. The 
main problem I see is how to actually write "commercial" apps 
using D for android. Can it be done successfully? Nobody knows 
because there isn't a history. What are the exact steps, say, to 
add ads, or interface with the subsystem? I saw that there is 
some way to call some java stuff from D but seems like nothing is 
thoroughly tested(most of the work as been just trying to get 
things up and running).


I will try to do a better job of documenting my progress now that 
I have some faith ;) But right now I'm more of the horse rather 
than the guy trying to show him where the water is.













Re: Android Status

2017-01-08 Thread Ignacious via Digitalmars-d-learn

On Sunday, 8 January 2017 at 22:19:31 UTC, Joakim wrote:

On Sunday, 8 January 2017 at 21:52:01 UTC, Ignacious wrote:
Not sure what is going on, of course ;) So much BS just to do 
something that is suppose to be simple ;)



test.d



void main()
{

}

here is test.o

http://pastebin.com/NRrKgKtb

Any ideas?


Oh, that's easy: install the NDK too, as shown on the wiki.  
You need the linker that supports ARM from the NDK.  Follow the 
instructions from the wiki to compile and link the binary, 
simply having ldc do everything won't work.




Ok, after executing

$NDK/toolchains/llvm/prebuilt/linux-x86_64/bin/clang 
-Wl,-z,nocopyreloc --sysroot=$NDK/platforms/android-9/arch-arm 
-lgcc -gcc-toolchain 
$NDK/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64 
-target armv7-none-linux-androideabi -no-canonical-prefixes 
-fuse-ld=bfd -Wl,--fix-cortex-a8 -Wl,--no-undefined 
-Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now -fPIE -pie -mthumb 
-Wl,--export-dynamic -lc -lm test.o lib/libphobos2-ldc.a 
lib/libdruntime-ldc.a -o test


I get a test elf file with no errors(although 2.5MB for a hello 
world).


I had to do the chmod 755 test

then

./test

to get any output. Before that no output and no errors so wasn't 
sure what as going on.


Looks like everything is working! ;)

Seems like someone really needs to put some time in to getting 
all this stuff organized and situated


Maybe the D language foundation can push some money towards it to 
get it started off on the right foot?


I'll try to get some of the opengl examples on your repository to 
see if they work soon.



Cross-compiler toolchains are never simple, consider yourself 
lucky for having gotten off easy. :)


I realize things are difficult but it's people that make it that 
way ;) Life would be so much simpler if people would just 
properly document stuff exactly(or, rather, do what they are 
suppose to do). (Even windows seems to love to forget to put in 
descriptions of services, tasks, application descriptions, etc).


The main problem I have had seems to be that UoW uses ver 14. 
Somehow I was able to upgrade by following docs online(wasn't 
easy but eventually got there and everything seems to work... I 
should have documented ;) but I wasn't sure if the process would 
work. Supposedly ver 16 exists by one has to be part of the dev 
team or something.




Re: Android Status

2017-01-08 Thread Ignacious via Digitalmars-d-learn

On Sunday, 8 January 2017 at 20:34:21 UTC, Joakim wrote:

On Sunday, 8 January 2017 at 19:58:06 UTC, Ignacious wrote:
I suppose it will be easier to install a real ubuntu distro 
rather than relying on windows? All these issues seem to be 
related to outdated versions?


Distributor ID: Ubuntu
Description:Ubuntu 14.04.5 LTS
Release:14.04
Codename:   trusty


I doubt that'd work either as Debian just uses older packages.  
Your best bet may be to just compile ldc yourself, by following 
the instructions on the wiki.


Well, I finally got it to upgrade to 16.. when I run ldc2 or 
ldmd2 I get the following errors


/usr/bin/ld: test.o: Relocations in generic ELF (EM: 40)
/usr/bin/ld: test.o: Relocations in generic ELF (EM: 40)
/usr/bin/ld: test.o: Relocations in generic ELF (EM: 40)
/usr/bin/ld: test.o: Relocations in generic ELF (EM: 40)
/usr/bin/ld: test.o: Relocations in generic ELF (EM: 40)
/usr/bin/ld: test.o: Relocations in generic ELF (EM: 40)
/usr/bin/ld: test.o: Relocations in generic ELF (EM: 40)
test.o: error adding symbols: File in wrong format
collect2: error: ld returned 1 exit status
Error: /usr/bin/gcc failed with status: 1

test is just a simple hello world.



root@:/mnt/b/DLang/ldc2Android# gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/5/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 
5.4.0-6ubuntu1~16.04.4' 
--with-bugurl=file:///usr/share/doc/gcc-5/README.Bugs 
--enable-languages=c,ada,c++,java,go,d,fortran,objc,obj-c++ 
--prefix=/usr --program-suffix=-5 --enable-shared 
--enable-linker-build-id --libexecdir=/usr/lib 
--without-included-gettext --enable-threads=posix 
--libdir=/usr/lib --enable-nls --with-sysroot=/ 
--enable-clocale=gnu --enable-libstdcxx-debug 
--enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new 
--enable-gnu-unique-object --disable-vtable-verify 
--enable-libmpx --enable-plugin --with-system-zlib 
--disable-browser-plugin --enable-java-awt=gtk --enable-gtk-cairo 
--with-java-home=/usr/lib/jvm/java-1.5.0-gcj-5-amd64/jre 
--enable-java-home 
--with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-5-amd64 
--with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-5-amd64 
--with-arch-directory=amd64 
--with-ecj-jar=/usr/share/java/eclipse-ecj.jar --enable-objc-gc 
--enable-multiarch --disable-werror --with-arch-32=i686 
--with-abi=m64 --with-multilib-list=m32,m64,mx32 
--enable-multilib --with-tune=generic --enable-checking=release 
--build=x86_64-linux-gnu --host=x86_64-linux-gnu 
--target=x86_64-linux-gnu

Thread model: posix
gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.4)


Not sure what is going on, of course ;) So much BS just to do 
something that is suppose to be simple ;)



test.d



void main()
{

}

here is test.o

http://pastebin.com/NRrKgKtb

Any ideas?




Re: Android Status

2017-01-08 Thread Ignacious via Digitalmars-d-learn


Yeah, not a good idea to build from source yourself.  Try the 
advice here, ie see if you can install a package with that 
library or just symlink to the older library if not:


http://askubuntu.com/questions/771047/erlang-error-while-loading-shared-libraries-libncursesw-so-6



Well, the only way to get it to work is rename 5.9 ver to 6.0, 
but then now I get the error


root@DESKTOP:/mnt/b/DLang/ldc2Android# bin/ldmd2 test.d
bin/ldmd2: error while loading shared libraries: 
libncursesw.so.6: cannot open shared object file: No such file or 
directory

root@DESKTOP:/mnt/b/DLang/ldc2Android# bin/ldmd2 test.d
bin/ldmd2: error while loading shared libraries: 
libncursesw.so.6: cannot open shared object file: No such file or 
directory

root@DESKTOP:/mnt/b/DLang/ldc2Android# bin/ldmd2 test.d
bin/ldmd2: /usr/lib/x86_64-linux-gnu/libstdc++.so.6: version 
`GLIBCXX_3.4.21' not found (required by bin/ldmd2)

root@DESKTOP:/mnt/b/DLang/ldc2Android# bin/ldc2 test.d
bin/ldc2: /usr/lib/x86_64-linux-gnu/libstdc++.so.6: version 
`GLIBCXX_3.4.20' not found (required by bin/ldc2)
bin/ldc2: /usr/lib/x86_64-linux-gnu/libstdc++.so.6: version 
`GLIBCXX_3.4.21' not found (required by bin/ldc2)


I followed this page:

http://askubuntu.com/questions/575505/glibcxx-3-4-20-not-found-how-to-fix-this-error

and now I get the error


bin/ldc2: relocation error: bin/ldc2: symbol 
_ZNKSt3_V214error_category10_M_messageB5cxx11Ei, version 
GLIBCXX_3.4.21 not defined in file libstdc++.so.6 with link time 
reference


even though

strings /usr/lib/x86_64-linux-gnu/libstdc++.so.6 | grep GLIBCXX
GLIBCXX_3.4
GLIBCXX_3.4.1
GLIBCXX_3.4.2
GLIBCXX_3.4.3
GLIBCXX_3.4.4
GLIBCXX_3.4.5
GLIBCXX_3.4.6
GLIBCXX_3.4.7
GLIBCXX_3.4.8
GLIBCXX_3.4.9
GLIBCXX_3.4.10
GLIBCXX_3.4.11
GLIBCXX_3.4.12
GLIBCXX_3.4.13
GLIBCXX_3.4.14
GLIBCXX_3.4.15
GLIBCXX_3.4.16
GLIBCXX_3.4.17
GLIBCXX_3.4.18
GLIBCXX_3.4.19
GLIBCXX_3.4.20
GLIBCXX_3.4.21
GLIBCXX_3.4.22
GLIBCXX_DEBUG_MESSAGE_LENGTH

I suppose it will be easier to install a real ubuntu distro 
rather than relying on windows? All these issues seem to be 
related to outdated versions?


Distributor ID: Ubuntu
Description:Ubuntu 14.04.5 LTS
Release:14.04
Codename:   trusty



String characters not extended

2017-01-02 Thread Ignacious via Digitalmars-d-learn
when one prints out a string with some extended(I guess it's 
unicode), writeln prints out the ascii versions that do not 
correspond to what they really are. e.g., an umlaut is printed 
out as 1/2 or something.


how to get it to print the correct codes?


Re: Android Status

2017-01-02 Thread Ignacious via Digitalmars-d-learn

On Monday, 2 January 2017 at 03:08:10 UTC, Joakim wrote:

On Sunday, 1 January 2017 at 09:34:24 UTC, Ignacious wrote:


Can you try

sudo apt-get install libconfig9

I don't know if that will install something different, but 
it's the command I see others using online.  Otherwise, check 
if the libconfig++9 package you installed included 
libconfig.so.9, which is what ldc is linked against.  If not, 
install the package that provides that library.  The wiki 
mentions installing libconfig-dev, you could always just 
install that if nothing else works.





That is what I used to get it on there in the first place... 
but the ldc compiler still could not find it.


The problem seems to be where ldc2 is looking for 
libconfig.so.9 rather than it being installed or not.


How do I either know where it is looking for where to put it?


You said you installed libconfig++9, which an apt search shows 
me is a different package than libconfig9, that includes a 
library named differently.  As I said, are you sure that 
particular libconfig.so.9 library is installed?


If it is, manually adding its path to LD_LIBRARY_PATH is the 
way to make sure it's found.


Ok, I didn't realize they were different packages.

I now get the error

./bin/ldmd2: error while loading shared libraries: 
libncursesw.so.6: cannot open shared object file: No such file or 
directory


and trying to install libncursesw is missing. I tried installing 
libncurses5 and it worked, but, of course, not version 6 or 
whatever. tried various things... nothing works.


./bin/ldc2: error while loading shared libraries: 
libncursesw.so.6: cannot open shared object file: No such file or 
directory


I downloaded the sources. I had to install gcc, make, then I did 
./configure --enable-widec 
(http://arstechnica.com/civis/viewtopic.php?f=20=1161942), then 
ran make.. I end up getting the errors


make[1]: Leaving directory `/mnt/b/c/test'
cd misc && make DESTDIR="" all
make[1]: Entering directory `/mnt/b/c/misc'
WHICH_XTERM=xterm-new \
ticdir=/usr/share/terminfo \
/bin/sh ./gen_edit.sh >run_tic.sed
echo '** adjusting tabset paths'
** adjusting tabset paths
sed -f run_tic.sed ../misc/terminfo.src >terminfo.tmp
make[1]: Leaving directory `/mnt/b/c/misc'
cd c++ && make DESTDIR="" all
make[1]: Entering directory `/mnt/b/c/c++'
cp ./etip.h.in etip.h
sh ./edit_cfg.sh ../include/ncurses_cfg.h etip.h
substituting autoconf'd values from ../include/ncurses_cfg.h into 
etip.h

... CPP_HAS_PARAM_INIT 0
... CPP_HAS_STATIC_CAST 0
... ETIP_NEEDS_MATH_EXCEPTION 0
... ETIP_NEEDS_MATH_H 0
... HAVE_BUILTIN_H 0
... HAVE_GPP_BUILTIN_H 0
... HAVE_GXX_BUILTIN_H 0
... HAVE_IOSTREAM 0
... HAVE_TYPEINFO 0
... HAVE_VALUES_H 0
... IOSTREAM_NAMESPACE 0
cd ../objects;   -I../c++ -I../include -I. -DHAVE_CONFIG_H  
-D_GNU_SOURCE -DNDEBUG -I. -I../include  -c ../c++/cursesf.cc

/bin/sh: 1: -I../c++: not found
make[1]: *** [../objects/cursesf.o] Error 127
make[1]: Leaving directory `/mnt/b/c/c++'
make: *** [all] Error 2

So, now I do not know what to do next.


Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package libncurses6

(This is why I hate working linux, so much obfuscation... so many 
potential points of failure)


Also, once I go through all this trouble, I have to do it again 
for the arm verson(using x86-64 ldc)? Can I install on the same 
system or will the libraries conflict and I'll have to go through 
all this mess again?





Re: Android Status

2017-01-01 Thread Ignacious via Digitalmars-d-learn


Can you try

sudo apt-get install libconfig9

I don't know if that will install something different, but it's 
the command I see others using online.  Otherwise, check if the 
libconfig++9 package you installed included libconfig.so.9, 
which is what ldc is linked against.  If not, install the 
package that provides that library.  The wiki mentions 
installing libconfig-dev, you could always just install that if 
nothing else works.





That is what I used to get it on there in the first place... but 
the ldc compiler still could not find it.


The problem seems to be where ldc2 is looking for libconfig.so.9 
rather than it being installed or not.


How do I either know where it is looking for where to put it?


Re: Reducing visual clutter.

2016-12-31 Thread Ignacious via Digitalmars-d-learn
On Saturday, 31 December 2016 at 12:31:07 UTC, Nicholas Wilson 
wrote:
On Saturday, 31 December 2016 at 11:39:39 UTC, Nicholas Wilson 
wrote:

[...]


Oh and `kernel` could be a template function that would need 
its args forwarded to it.


Alias it away using a wrapper?


Re: Android Status

2016-12-31 Thread Ignacious via Digitalmars-d-learn

On Thursday, 29 December 2016 at 10:14:53 UTC, Joakim wrote:

On Wednesday, 28 December 2016 at 23:33:57 UTC, Ignacious wrote:
What is the current status for building android apps in D? I 
would like to create simple graphic based apps but don't wanna 
get bogged down in trying to get car moving without any wheels.


Should all work, but nothing other than small apps have been 
tested.  Try the latest beta, which I just put up:


http://forum.dlang.org/post/xetfqojxijgobisfa...@forum.dlang.org

If you want something more substantive than my ports of the 
NDK's sample apps, check out Vadim's Tetris app, which I spent 
half an hour playing on my phone, :) or his minecraft-like demo 
(click on the sourceforge link from his forum post to get the 
apps):


http://forum.dlang.org/thread/cdekkumjynhqoxvmg...@forum.dlang.org

Let me know if you have any questions or problems.


Ok, so I installed
ldc2-android-arm-1.1.0-beta4-linux-x86_64.tar.xz

in to ldcandroid

and tried running

./bin/ldc2 -c test.d

I get the error.

./bin/ldc2: error while loading shared libraries: libconfig.so.9: 
cannot open shared object file: No such file or directory


Searched the file system for libconfig and found nothing so I did

sudo apt-get install libconfig++9

which installed it under lxss\rootfs\usr\lib\x86_64-linux-gnu

It shows up when I do

sudo ldconfig -v

/usr/lib/x86_64-linux-gnu:
libconfig++.so.9 -> libconfig++.so.9.1.3

I tried adding this:

export LD_LIBRARY_PATH=/usr/lib/x86_64-linux-gnu

But still same issue.

Any ideas how to fix this?




Re: Android Status

2016-12-30 Thread Ignacious via Digitalmars-d-learn

On Saturday, 31 December 2016 at 06:33:10 UTC, Ignacious wrote:

On Saturday, 31 December 2016 at 05:52:00 UTC, Ignacious wrote:

On Thursday, 29 December 2016 at 10:14:53 UTC, Joakim wrote:

[...]


Is there any way to get a package that works for windows? 
While the steps don't seem too difficult to do, things never 
go well for me(something always breaks... always!)


did install the linux subsystem but... seems like it would be 
easier for you to compile a binary and upload it... since you 
know what you are doing and have everything at hand already...


At least that gives me(and others) the ability to try to build 
the examples and see how it works and all that... then I can 
go through all the trouble of building the compiler myself if 
it seems worth it rather than wasting time.


I see these:

https://github.com/joakim-noah/android/releases

Seems the two archives are identical though except the libs?

Is this what I use to compile the examples?


nvm mind, I guess I accidentally extracted the same archive 
thinking it was the other.


so, essentially these are the two different compilers for the two 
different android architectures?




Re: Android Status

2016-12-30 Thread Ignacious via Digitalmars-d-learn

On Saturday, 31 December 2016 at 05:52:00 UTC, Ignacious wrote:

On Thursday, 29 December 2016 at 10:14:53 UTC, Joakim wrote:

[...]


Is there any way to get a package that works for windows? While 
the steps don't seem too difficult to do, things never go well 
for me(something always breaks... always!)


did install the linux subsystem but... seems like it would be 
easier for you to compile a binary and upload it... since you 
know what you are doing and have everything at hand already...


At least that gives me(and others) the ability to try to build 
the examples and see how it works and all that... then I can go 
through all the trouble of building the compiler myself if it 
seems worth it rather than wasting time.


I see these:

https://github.com/joakim-noah/android/releases

Seems the two archives are identical though except the libs?

Is this what I use to compile the examples?


Re: Android Status

2016-12-30 Thread Ignacious via Digitalmars-d-learn

On Thursday, 29 December 2016 at 10:14:53 UTC, Joakim wrote:

On Wednesday, 28 December 2016 at 23:33:57 UTC, Ignacious wrote:
What is the current status for building android apps in D? I 
would like to create simple graphic based apps but don't wanna 
get bogged down in trying to get car moving without any wheels.


Should all work, but nothing other than small apps have been 
tested.  Try the latest beta, which I just put up:


http://forum.dlang.org/post/xetfqojxijgobisfa...@forum.dlang.org

If you want something more substantive than my ports of the 
NDK's sample apps, check out Vadim's Tetris app, which I spent 
half an hour playing on my phone, :) or his minecraft-like demo 
(click on the sourceforge link from his forum post to get the 
apps):


http://forum.dlang.org/thread/cdekkumjynhqoxvmg...@forum.dlang.org

Let me know if you have any questions or problems.


Is there any way to get a package that works for windows? While 
the steps don't seem too difficult to do, things never go well 
for me(something always breaks... always!)


did install the linux subsystem but... seems like it would be 
easier for you to compile a binary and upload it... since you 
know what you are doing and have everything at hand already...


At least that gives me(and others) the ability to try to build 
the examples and see how it works and all that... then I can go 
through all the trouble of building the compiler myself if it 
seems worth it rather than wasting time.


Re: Android Status

2016-12-29 Thread Ignacious via Digitalmars-d-learn

On Thursday, 29 December 2016 at 10:14:53 UTC, Joakim wrote:

On Wednesday, 28 December 2016 at 23:33:57 UTC, Ignacious wrote:
What is the current status for building android apps in D? I 
would like to create simple graphic based apps but don't wanna 
get bogged down in trying to get car moving without any wheels.


Should all work, but nothing other than small apps have been 
tested.  Try the latest beta, which I just put up:


http://forum.dlang.org/post/xetfqojxijgobisfa...@forum.dlang.org

If you want something more substantive than my ports of the 
NDK's sample apps, check out Vadim's Tetris app, which I spent 
half an hour playing on my phone, :) or his minecraft-like demo 
(click on the sourceforge link from his forum post to get the 
apps):


http://forum.dlang.org/thread/cdekkumjynhqoxvmg...@forum.dlang.org

Let me know if you have any questions or problems.


Thanks, hopefully it works. Had to upgrade to win10 aniversary 
and it destroyed my system so I am now in the process of getting 
it back to normal. Hopefully this Bash on Ubuntu is worth it and 
everything works as advertised...


Android Status

2016-12-28 Thread Ignacious via Digitalmars-d-learn
What is the current status for building android apps in D? I 
would like to create simple graphic based apps but don't wanna 
get bogged down in trying to get car moving without any wheels.