Talk on D at DORS/CLUC
Hipreme
msnmancini at hotmail.com
Fri May 10 13:36:38 UTC 2024
On Friday, 10 May 2024 at 08:43:14 UTC, RazvanN wrote:
> Hello everyone,
>
> Next week I'm going to have a talk on D at an open source
> conference in Zagrab [1].
> This is a great opportunity to advertise D so I'm going to talk
> about D's strength's. However, the talk is only 30 minutes in
> length and there's a lot of things I could potentially touch on
> - templates, dynamic arrays, safety, C interoperability etc.
> What do you think that I should focus my talk on? Any
> suggestions or cool D snippets are welcome.
>
> Regards,
> RazvanN
>
> [1] https://www.dorscluc.org/
I have some cool features which is quite hard to see in other
languages:
```d
module hip.systems.input;
import hip.jni.jni;
import hip.jni.helper.jnicall;
///Setups an Android Package for HipremeEngine
alias HipAndroidInput =
javaGetPackage!("com.hipremeengine.app.HipInput");
alias HipAndroidRenderer =
javaGetPackage!("com.hipremeengine.app.Hip_GLES30_Renderer");
@JavaFunc!(HipAndroidInput) void
onMotionEventActionMove(int pointerId, float x, float y)
{
HipEventQueue.post(0,
HipEventQueue.EventType.touchMove,
HipEventQueue.Touch(cast(ushort)pointerId, x,y));
}
@JavaFunc!(HipAndroidInput) void
onMotionEventActionPointerDown(int pointerId, float x, float y)
{
HipEventQueue.post(0,
HipEventQueue.EventType.touchDown,
HipEventQueue.Touch(cast(ushort)pointerId, x,y));
}
mixin javaGenerateModuleMethodsForPackage!(HipAndroidInput,
hip.systems.input);
```
This code exposes functions on Java/Android, they iterate the
current module, looking for `@JavaFunc` (I could have written
ExternJava). They will generate based on the java package:
```d
// file com/hipremeengine/app/HipInput.java
public static class HipInput
{
public static native void onMotionEventActionMove(int
pointerId, float x, float y);
public static native void
onMotionEventActionPointerDown(int pointerId, float x, float y);
}
```
Not only that, but you can also pretty easily call Java functions
from D:
```d
alias HipAndroid =
javaGetPackage!("com.hipremeengine.app.HipremeEngine");
int[2] wsize = HipAndroid.javaCall!(int[2],
"getWindowSize");
AAssetManager* aaMgr =
cast(AAssetManager*)HipAndroid.javaCall!(Object,
"getAssetManager");
```
Beyond that, I have also written code that auto translates to Lua
and Objective-C. So D is quite flexible into that.
The main 2 packages I know from dub that does that are:
1. arsd.jni
2. objc_meta
More information about the Digitalmars-d
mailing list