snowkit / snow

A low level cross platform framework for Haxe. Mac, Windows, Linux, Android, iOS, WebGL.
http://snowkit.org/snow
MIT License
133 stars 35 forks source link

JNI; fix string argument #102

Closed bram-dingelstad closed 6 years ago

bram-dingelstad commented 6 years ago

Using luxe commit version 66bed0cf1a38e58355c65497f8b97de5732467c5 Using haxe version 3.4.4

I ran into this issue trying to use snow.api.JNI for a simple function thats executed from Java to Haxe using the @:build(JNI.native()) macro.

The issue was at first that the JNI.hx file was using haxe.macros.Context fields that didn't exist. Inspecting the Context.hx file shows that the entire class is only available in neko. On line 41 there is a compile time flag that only allows neko to use macros for some reason. I changed this to #if (neko || mobile) for my purposes, this seems to be an issue with Haxe however, which has been reported. See the haxe issue here

The second issue was an error saying:

/home/user/.haxe/snow/git/snow/api/JNI.hx:185: characters 17-36 : Only inline or read-only (default, never) fields can be used as a pattern

I changed the static fields to (default, never) to fix this.

The third issue was that I got an error saying:

/src/native/AndroidReceiver.cpp:33:42: error: 'nativeString' was not declared in this scope
    env->ReleaseStringUTFChars(jarg_test, nativeString);

I took a look at the JNI.hx file and corrected it to make sure it used a defined variable $name. The variable passed to the cpp version of my haxe code only accepted ::String, not char*. I added a simple conversion (first time c++, i'm sorry) and fixed the issue with that.

I there's anything that I can do to get this PR merged, let me know!

Cheers :smile:

ruby0x1 commented 6 years ago

Nope this looks good, thanks for digging into it!

bram-dingelstad commented 6 years ago

Nice! For anyone running into the issue with the Haxe standard library Context.hx, here's an easy shell script that fixes that issue for you!

#!/bin/bash
file=""
for location in $(whereis haxe | cut -d : -f2-); do
    file=$(find "$location" | grep macro\/Context.hx$)
    if [[ "$file" != "" ]]; then
        break
    fi
done

sudo sed -i 's/#if neko/#if (neko || mobile)/g' "$file"