Re: Discord bot written in D

2020-04-07 Thread Meta via Digitalmars-d-learn

On Monday, 6 April 2020 at 21:23:22 UTC, Quantium wrote:
Are there any libraries to creade a simple discord bot using D? 
And if you know these libraries, could you day me their pros 
and cons?


I've used https://github.com/b1naryth1ef/dscord to build a 
Discord bot, a little over a year ago. However, it didn't even 
seem that actively maintained back then; I had to patch over at 
least one bug. Other than that, though, it worked smoothly and 
was easy to get started with.


To get memory from another process.

2020-04-07 Thread Quantium via Digitalmars-d-learn
Could you advise me how to do these steps on D? Which libs should 
I import?

1. My programm gets a path to exe file
2. My programm starts that exe file and writes into it 2 commands
3. Programm gets access to exe file memory
4. Programm gets data from process memory and writes it into 
data.bin file which is in the same directory.
As I said, which libs do I need and how to get access to other 
process memory.
Also, can I make this as a driver, but if yes, how to code driver 
on D?


Re: D on android and d_android

2020-04-07 Thread burt via Digitalmars-d-learn

On Tuesday, 7 April 2020 at 12:29:57 UTC, Adam D. Ruppe wrote:

On Tuesday, 7 April 2020 at 11:45:24 UTC, burt wrote:
I managed to get it to compile. I had to add __bss_end__ 
symbol myself and set the value to the value of the `_end` 
symbol or it wouldn't work. A PR to the LDC druntime is wat 
caused the __bss_end__ symbol to be missing [0].


Blargh it was supposed to just work without main() on the new 
ldc but I only actually ran stuff with 1.19 on actual android.



However, when I added a MainActivity class in D using 
arsd.jni, the app crashes whenever one of the @Exported 
methods is called.


What does the android studio debugger say about it? Missing 
method or another link problem?


And a callback method for a button in Java called dFunction 
with the appropriate parameters. I noticed that the generated 
.so file didn't contain a 
`Java_com_mypackage_myapplication_MainActivity_dFunction` 
symbol. Any help on this would be appreciated.


Yeah, it uses a private name and registers that in a static 
module constructor (this allows it to support overloads more 
easily), so that specific name not being there isn't wrong, but 
it could be the registration function never got called again.


Error is as follows according to the logs:

java.lang.IllegalStateException: Could not execute method for 
android:onClick

at [etc.]
Caused by: java.lang.reflect.InvocationTargetException
at [etc.]
Caused by: java.lang.UnsatisfiedLinkError: No implementation 
found for void 
com.mypackage.myapplication.MainActivity.dFunction(android.widget.TextView, android.widget.TextView, android.widget.TextView) (tried Java_com_mypackage_myapplication_MainActivity_dFunction and Java_com_mypackage_myapplication_MainActivity_dFunction__Landroid_widget_TextView_2Landroid_widget_TextView_2Landroid_widget_TextView_2)

at [etc.]

So yes, it cannot find the function. How can I check if the 
module constructor is actually run?




Re: D on android and d_android

2020-04-07 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Apr 07, 2020 at 03:06:16PM +, Adam D. Ruppe via Digitalmars-d-learn 
wrote:
> On Tuesday, 7 April 2020 at 14:51:15 UTC, H. S. Teoh wrote:
> > 1) Follow LDC wiki to build an Android cross-compiler and
> >cross-compiled LDC libraries (this may already be prepackaged
> >with the latest LDC releases).
> 
> They are - this is all automatic just-works now (if you download the
> right versions - my android-setup.d will grab the appropriate binaries
> from ldc repo for you).

Nice!  I'm totally loving how the LDC maintainers have been packaging
everything in such a convenient, easy-to-use way.  I've been doing
cross-compilation to Windows, and it's been great, I don't even need a
Windows machine, just cross-compile to Windows with the right triple and
library paths set in ldc2.conf, and it Just Works(tm).


> > 6) Cross-compile D code with LDC:
> 
> And my android-setup.d also changes the ldc config file to automate
> most this - you just set the mtriple (and optionally, mcpu) and the
> rest is automatic too.

Very nice!


[...]
> I've had more bugs than time so the full-on "just works" promise is
> "your mileage may vary" but it is really getting simplified for these
> two steps.

The rest are Android-specific, but in theory easily scriptable (in fact,
I typed it up by copy-n-pasting from the output of my SCons build script
:P).  So in theory, one *could* write a script that does it all in one
go.


T

-- 
People say I'm arrogant, and I'm proud of it.


Re: Discord bot written in D

2020-04-07 Thread Quantium via Digitalmars-d-learn

On Tuesday, 7 April 2020 at 11:43:46 UTC, JN wrote:

On Monday, 6 April 2020 at 21:23:22 UTC, Quantium wrote:
Are there any libraries to creade a simple discord bot using 
D? And if you know these libraries, could you day me their 
pros and cons?


There are four Discord API related libraries on code.dlang.org. 
Have you checked those?


Yes, I've seen 2 or 3, but there isn't a good documentation. Also 
I don't know which of packages is better.


Re: D on android and d_android

2020-04-07 Thread Adam D. Ruppe via Digitalmars-d-learn

On Tuesday, 7 April 2020 at 14:51:15 UTC, H. S. Teoh wrote:
1) Follow LDC wiki to build an Android cross-compiler and 
cross-compiled
   LDC libraries (this may already be prepackaged with the 
latest LDC

   releases).



They are - this is all automatic just-works now (if you download 
the right versions - my android-setup.d will grab the appropriate 
binaries from ldc repo for you).




6) Cross-compile D code with LDC:


And my android-setup.d also changes the ldc config file to 
automate most this - you just set the mtriple (and optionally, 
mcpu) and the rest is automatic too.




I've had more bugs than time so the full-on "just works" promise 
is "your mileage may vary" but it is really getting simplified 
for these two steps.


Re: D on android and d_android

2020-04-07 Thread Jan Hönig via Digitalmars-d-learn

On Tuesday, 7 April 2020 at 14:51:15 UTC, H. S. Teoh wrote:
On Tue, Apr 07, 2020 at 12:43:20PM +, Adam D. Ruppe via 
Digitalmars-d-learn wrote:

On Monday, 6 April 2020 at 08:38:03 UTC, Jan Hönig wrote:
> Is there some "Hello World!" example for D on Android?

[...]

> However there is just so much to know.
> It is really overwhelming.

no kidding, I spent several weekends just trying to understand 
the setup and build process. And I still basically don't 
really know, which is why my thing there builds the D code 
externally and copies the files where gradle can find them 
instead of actually changing the gradle config.


I managed to build APKs without Gradle (yes, I'm crazy like 
that). There are several steps, and you do need some tools from 
the Android SDK/NDK, namely aapt, apksigner, dx (called 
dalvik-exchange on some distros), zipalign, and a Java 1.7 
compiler (the last time I checked; maybe they support 1.8 now, 
I don't know).


I haven't tried a native app so far, so the way I set it up is 
to create a dummy Java wrapper that contains main() that calls 
native methods that are implemented in D.  You can use Adam's 
jni.d to generate implementations for your native methods.


Steps:

1) Follow LDC wiki to build an Android cross-compiler and 
cross-compiled
   LDC libraries (this may already be prepackaged with the 
latest LDC
   releases). Most important thing you need is the path to the 
droid32
   or droid64 directories containing the libraries 
libdruntime-ldc.a,
   libphobos2-ldc.a, libdruntime-ldc-debug.a, 
libphobos2-ldc-debug.a.


DROID32_PATH=/usr/src/d/android/droid32/lib # for example

2) Generate R.java:

TARGET_API_LEVEL=23 # for example
	/usr/bin/aapt package -f -m -M AndroidManifest.xml -S res -I 
${PATH_TO_ANDROID_SDK}/platforms/android-${TARGET_API_LEVEL}/android.jar -J ${PATH_TO_JAVA_SOURCE_CODE}


3) Compile Java sources:

	/usr/bin/javac -source 1.7 -target 1.7 -bootclasspath 
${PATH_TO_ANDROID_SDK}/platforms/android-${TARGET_API_LEVEL}/android.jar -d obj -sourcepath src ${JAVA_SOURCE_FILES (including R.java)}


4) Generate classes.dex (on some systems dalvik-exchange might 
be called

simply 'dx'):

	/usr/bin/dalvik-exchange --dex --output=classes.dex 
${PATH_TO_OBJ_DIR}


5) Setup linker config file (for optimizing apk size):

LINKER_VERSION_FILE=lib${YOUR_APP_NAME}.version
cat > $LINKER_VERSION_FILE
LIBGAME_1.0 {
global:
Java_*;
local:
*;
};

6) Cross-compile D code with LDC:

	${PATH_TO_LDC}/bin/ldmd2 -c 
-mtriple=armv7-none-linux-androideabi -mcpu=cortex-a8 
-L-L${DROID32_PATH}/lib -Xcc=-fpie -Xcc=-pie 
-Xcc=--sysroot=${PATH_TO_ANDROID_NDK}/platforms/android-${TARGET_API_LEVEL}/arch-arm -Xcc=-fuse-ld=bfd -Xcc=-gcc-toolchain -Xcc=${PATH_TO_ANDROID_NDK}/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64 -Xcc=-target -Xcc=armv7-none-linux-androideabi -O4 -inline -Isrc/d -od${PATH_TO_OBJ_DIR} ${D_SOURCE_FILES}

${PATH_TO_ANDROID_NDK}/toolchains/llvm/prebuilt/linux-x86_64/bin/clang 
-Wl,-soname,lib${YOUR_APP_NAME}.so -shared -Wl,--gc-sections 
-Wl,--version-script=${LINKER_VERSION_FILE} -llog -landroid -lEGL -lGLESv2 
--sysroot=${PATH_TO_ANDROID_NDK}/platforms/android-${TARGET_API_LEVEL}/arch-arm 
-fuse-ld=bfd -gcc-toolchain 
${PATH_TO_ANDROID_NDK}/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64
 -target armv7-none-linux-androideabi ${D_OBJECT_FILES} 
${DROID32_PATH}/lib/libphobos2-ldc.a ${DROID32_PATH}/lib/libdruntime-ldc.a -o 
lib/armeabi-v7a/lib${YOUR_APP_NAME}.so

7) Create unaligned APK:
	/usr/bin/aapt package -f -m -M AndroidManifest.xml -S res -I 
${PATH_TO_ANDROID_SDK}/platforms/android-${TARGET_API_LEVEL}/android.jar -F bin/${YOUR_APP_NAME}.unaligned.apk
	/usr/bin/aapt add bin/${YOUR_APP_NAME}.unaligned.apk 
classes.dex
	/usr/bin/aapt add bin/${YOUR_APP_NAME}.unaligned.apk 
lib/armeabi-v7a/lib${YOUR_APP_NAME}.so


8) Sign the APK:
	/usr/bin/apksigner sign --ks-pass 
file:${YOUR_SIGNING_KEY_PASSWORD_FILE} --ks 
${YOUR_SIGNING_KEY_STORE_FILE} 
bin/${YOUR_APP_NAME}.unaligned.apk


9) Align the APK:
	/usr/bin/zipalign -f 4 bin/${YOUR_APP_NAME}.unaligned.apk 
bin/${YOUR_APP_NAME}.apk


10) Copy bin/${YOUR_APP_NAME}.apk to your device and install it.


T


Thanks for the effort. I will try the "easy" way frist :D


Re: D on android and d_android

2020-04-07 Thread Jan Hönig via Digitalmars-d-learn

On Tuesday, 7 April 2020 at 12:43:20 UTC, Adam D. Ruppe wrote:

On Monday, 6 April 2020 at 08:38:03 UTC, Jan Hönig wrote:

Is there some "Hello World!" example for D on Android?


So I did a tiny thing in the repo:

https://github.com/adamdruppe/d_android/tree/master/android-dub-test

if you open that in android studio it should load up, and the 
makefile is commented, but tells you the 8 commands (4 dub 
builds, 4 file copies, just doing the same things for each of 
the 4 android architecture targets) to do a full add.



Thanks a lot. I was blind not finding it in your repo.


Re: D on android and d_android

2020-04-07 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Apr 07, 2020 at 12:43:20PM +, Adam D. Ruppe via Digitalmars-d-learn 
wrote:
> On Monday, 6 April 2020 at 08:38:03 UTC, Jan Hönig wrote:
> > Is there some "Hello World!" example for D on Android?
[...]
> > However there is just so much to know.
> > It is really overwhelming.
> 
> no kidding, I spent several weekends just trying to understand the
> setup and build process. And I still basically don't really know,
> which is why my thing there builds the D code externally and copies
> the files where gradle can find them instead of actually changing the
> gradle config.

I managed to build APKs without Gradle (yes, I'm crazy like that). There
are several steps, and you do need some tools from the Android SDK/NDK,
namely aapt, apksigner, dx (called dalvik-exchange on some distros),
zipalign, and a Java 1.7 compiler (the last time I checked; maybe they
support 1.8 now, I don't know).

I haven't tried a native app so far, so the way I set it up is to create
a dummy Java wrapper that contains main() that calls native methods that
are implemented in D.  You can use Adam's jni.d to generate
implementations for your native methods.

Steps:

1) Follow LDC wiki to build an Android cross-compiler and cross-compiled
   LDC libraries (this may already be prepackaged with the latest LDC
   releases). Most important thing you need is the path to the droid32
   or droid64 directories containing the libraries libdruntime-ldc.a,
   libphobos2-ldc.a, libdruntime-ldc-debug.a, libphobos2-ldc-debug.a.

DROID32_PATH=/usr/src/d/android/droid32/lib # for example

2) Generate R.java:

TARGET_API_LEVEL=23 # for example
/usr/bin/aapt package -f -m -M AndroidManifest.xml -S res -I 
${PATH_TO_ANDROID_SDK}/platforms/android-${TARGET_API_LEVEL}/android.jar -J 
${PATH_TO_JAVA_SOURCE_CODE}

3) Compile Java sources:

/usr/bin/javac -source 1.7 -target 1.7 -bootclasspath 
${PATH_TO_ANDROID_SDK}/platforms/android-${TARGET_API_LEVEL}/android.jar -d obj 
-sourcepath src ${JAVA_SOURCE_FILES (including R.java)}

4) Generate classes.dex (on some systems dalvik-exchange might be called
simply 'dx'):

/usr/bin/dalvik-exchange --dex --output=classes.dex ${PATH_TO_OBJ_DIR}

5) Setup linker config file (for optimizing apk size):

LINKER_VERSION_FILE=lib${YOUR_APP_NAME}.version
cat > $LINKER_VERSION_FILE
LIBGAME_1.0 {
global:
Java_*;
local:
*;
};

6) Cross-compile D code with LDC:

${PATH_TO_LDC}/bin/ldmd2 -c -mtriple=armv7-none-linux-androideabi 
-mcpu=cortex-a8 -L-L${DROID32_PATH}/lib -Xcc=-fpie -Xcc=-pie 
-Xcc=--sysroot=${PATH_TO_ANDROID_NDK}/platforms/android-${TARGET_API_LEVEL}/arch-arm
 -Xcc=-fuse-ld=bfd -Xcc=-gcc-toolchain 
-Xcc=${PATH_TO_ANDROID_NDK}/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64
 -Xcc=-target -Xcc=armv7-none-linux-androideabi -O4 -inline -Isrc/d 
-od${PATH_TO_OBJ_DIR} ${D_SOURCE_FILES}
${PATH_TO_ANDROID_NDK}/toolchains/llvm/prebuilt/linux-x86_64/bin/clang 
-Wl,-soname,lib${YOUR_APP_NAME}.so -shared -Wl,--gc-sections 
-Wl,--version-script=${LINKER_VERSION_FILE} -llog -landroid -lEGL -lGLESv2 
--sysroot=${PATH_TO_ANDROID_NDK}/platforms/android-${TARGET_API_LEVEL}/arch-arm 
-fuse-ld=bfd -gcc-toolchain 
${PATH_TO_ANDROID_NDK}/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64
 -target armv7-none-linux-androideabi ${D_OBJECT_FILES} 
${DROID32_PATH}/lib/libphobos2-ldc.a ${DROID32_PATH}/lib/libdruntime-ldc.a -o 
lib/armeabi-v7a/lib${YOUR_APP_NAME}.so

7) Create unaligned APK:
/usr/bin/aapt package -f -m -M AndroidManifest.xml -S res -I 
${PATH_TO_ANDROID_SDK}/platforms/android-${TARGET_API_LEVEL}/android.jar -F 
bin/${YOUR_APP_NAME}.unaligned.apk
/usr/bin/aapt add bin/${YOUR_APP_NAME}.unaligned.apk classes.dex
/usr/bin/aapt add bin/${YOUR_APP_NAME}.unaligned.apk 
lib/armeabi-v7a/lib${YOUR_APP_NAME}.so

8) Sign the APK:
/usr/bin/apksigner sign --ks-pass 
file:${YOUR_SIGNING_KEY_PASSWORD_FILE} --ks ${YOUR_SIGNING_KEY_STORE_FILE} 
bin/${YOUR_APP_NAME}.unaligned.apk

9) Align the APK:
/usr/bin/zipalign -f 4 bin/${YOUR_APP_NAME}.unaligned.apk 
bin/${YOUR_APP_NAME}.apk

10) Copy bin/${YOUR_APP_NAME}.apk to your device and install it.


T

-- 
The two rules of success: 1. Don't tell everything you know. -- YHL


Re: D on android and d_android

2020-04-07 Thread Adam D. Ruppe via Digitalmars-d-learn

On Monday, 6 April 2020 at 08:38:03 UTC, Jan Hönig wrote:

Is there some "Hello World!" example for D on Android?


So I did a tiny thing in the repo:

https://github.com/adamdruppe/d_android/tree/master/android-dub-test

if you open that in android studio it should load up, and the 
makefile is commented, but tells you the 8 commands (4 dub 
builds, 4 file copies, just doing the same things for each of the 
4 android architecture targets) to do a full add.


The main program is still in Java - there's a way to do pure D, 
the NDK's NativeActivity, but I never tried it personally (tbh 
I've only actually done hello world in android at all, i have 
zero interest in mobile dev, i just did it cuz someone had to do 
something and the JNI meta code was kinda cool) - but then you 
can call to/from D/java with native methods.




However there is just so much to know.
It is really overwhelming.


no kidding, I spent several weekends just trying to understand 
the setup and build process. And I still basically don't really 
know, which is why my thing there builds the D code externally 
and copies the files where gradle can find them instead of 
actually changing the gradle config.


Re: D on android and d_android

2020-04-07 Thread Adam D. Ruppe via Digitalmars-d-learn

On Tuesday, 7 April 2020 at 11:45:24 UTC, burt wrote:
I managed to get it to compile. I had to add __bss_end__ symbol 
myself and set the value to the value of the `_end` symbol or 
it wouldn't work. A PR to the LDC druntime is wat caused the 
__bss_end__ symbol to be missing [0].


Blargh it was supposed to just work without main() on the new ldc 
but I only actually ran stuff with 1.19 on actual android.



However, when I added a MainActivity class in D using arsd.jni, 
the app crashes whenever one of the @Exported methods is called.


What does the android studio debugger say about it? Missing 
method or another link problem?


And a callback method for a button in Java called dFunction 
with the appropriate parameters. I noticed that the generated 
.so file didn't contain a 
`Java_com_mypackage_myapplication_MainActivity_dFunction` 
symbol. Any help on this would be appreciated.


Yeah, it uses a private name and registers that in a static 
module constructor (this allows it to support overloads more 
easily), so that specific name not being there isn't wrong, but 
it could be the registration function never got called again.



sorry I've been so unresponsive on all this, I've had a lot other 
surprise/emergency stuff going on irl so I'm barely keeping up 
with my email.


Re: D on android and d_android

2020-04-07 Thread burt via Digitalmars-d-learn

On Thursday, 2 April 2020 at 12:13:27 UTC, Adam D. Ruppe wrote:

On Thursday, 2 April 2020 at 11:29:24 UTC, burt wrote:
Anyway, I don't think this fails to work because of an error 
in the d_android library. If you find anything else that may 
cause it, I am glad to know, but thank you for your help.


Well, it is supposed to be a "just works" setup helper, so 
anything in it is a problem! There was an off-by-one bug in the 
downloader, maybe that missing byte made ldc ignore the 
corrupted library file.


I managed to get it to compile. I had to add __bss_end__ symbol 
myself and set the value to the value of the `_end` symbol or it 
wouldn't work. A PR to the LDC druntime is wat caused the 
__bss_end__ symbol to be missing [0]. However, when I added a 
MainActivity class in D using arsd.jni, the app crashes whenever 
one of the @Exported methods is called. My code looked like this:


```
import arsd.jni;

final class TextView : IJavaObject
{
mixin IJavaObjectImplementation!(false);
mixin JavaPackageId!("android.widget", "TextView");
}
mixin ImportExportImpl!TextView;

final class MainActivity : IJavaObject
{
@Export void dFunction(TextView input, TextView output, 
TextView historyItem)

{
// ...
}

mixin IJavaObjectImplementation!(false);
mixin JavaPackageId!("com.mypackage.myapplication", 
"MainActivity");

}
mixin ImportExportImpl!MainActivity;
```

And a callback method for a button in Java called dFunction with 
the appropriate parameters. I noticed that the generated .so file 
didn't contain a 
`Java_com_mypackage_myapplication_MainActivity_dFunction` symbol. 
Any help on this would be appreciated.


Thanks.

[0] https://github.com/ldc-developers/druntime/pull/178


Re: Discord bot written in D

2020-04-07 Thread JN via Digitalmars-d-learn

On Monday, 6 April 2020 at 21:23:22 UTC, Quantium wrote:
Are there any libraries to creade a simple discord bot using D? 
And if you know these libraries, could you day me their pros 
and cons?


There are four Discord API related libraries on code.dlang.org. 
Have you checked those?


Vibe.d and shared data synchronization

2020-04-07 Thread Christian Köstlin via Digitalmars-d-learn

Hi,

I wrote a very small vibe.d based URL-shortener.
It has an in memory database that is in theory shared across request 
threads. At the moment I do not distribute over the vibe.d threadpool 
(https://vibed.org/features#multi-threading), but I would like to.


What would be the best way to share this database?
Is there something like a many readers, one writer implementation for dlang?
Is it somehow enforced by vibe.d so that only shared objects can be shared?

The code is located at https://github.com/gizmomogwai/shortened


Kind regards,
Christian