Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.

Commit bfdd655

Browse files
committed
[[ ExternalsApiV5 ]] Further changes to get (Java) Android external working.
1 parent 0e6c30a commit bfdd655

File tree

16 files changed

+3921
-103
lines changed

16 files changed

+3921
-103
lines changed

engine/src/dispatch.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1549,6 +1549,8 @@ bool MCDispatch::loadexternal(const char *p_external)
15491549
char *t_filename;
15501550
#if defined(TARGET_SUBPLATFORM_ANDROID)
15511551
extern bool revandroid_loadExternalLibrary(const char *p_external, char*& r_filename);
1552+
if (strrchr(p_external, '/') != nil)
1553+
p_external = strrchr(p_external, '/') + 1;
15521554
if (!revandroid_loadExternalLibrary(p_external, t_filename))
15531555
return false;
15541556

lcidlc/lcidlc.xcodeproj/project.pbxproj

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77
objects = {
88

99
/* Begin PBXBuildFile section */
10+
4D332C41178D7959005DFE92 /* EncodedJavaSupport.c in Sources */ = {isa = PBXBuildFile; fileRef = 4D332C3F178D7959005DFE92 /* EncodedJavaSupport.c */; };
11+
4D332C42178D7959005DFE92 /* EncodedSupport.c in Sources */ = {isa = PBXBuildFile; fileRef = 4D332C40178D7959005DFE92 /* EncodedSupport.c */; };
1012
4D4051A3176B2D340097F2D6 /* NativeType.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4D4051A1176B2D340097F2D6 /* NativeType.cpp */; };
11-
4D9036A21398FC0800CBC7F6 /* EncodedSupport.c in Sources */ = {isa = PBXBuildFile; fileRef = 4D9036901398FC0800CBC7F6 /* EncodedSupport.c */; };
1213
4D9036A31398FC0800CBC7F6 /* Error.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4D9036911398FC0800CBC7F6 /* Error.cpp */; };
1314
4D9036A41398FC0800CBC7F6 /* Interface.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4D9036931398FC0800CBC7F6 /* Interface.cpp */; };
1415
4D9036A51398FC0800CBC7F6 /* InterfaceGenerate.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4D9036951398FC0800CBC7F6 /* InterfaceGenerate.cpp */; };
@@ -21,7 +22,6 @@
2122
4D99EA3D1363A92A0056938B /* libcore.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 4D99EA3C1363A9220056938B /* libcore.a */; };
2223
4D99EA5B1363AA530056938B /* CoreFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4D99EA5A1363AA530056938B /* CoreFoundation.framework */; };
2324
4DBA0E7E136799A3006EEA7D /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4DBA0E7D136799A3006EEA7D /* Foundation.framework */; };
24-
4DED6F09176233B0001DEF0C /* EncodedJavaSupport.c in Sources */ = {isa = PBXBuildFile; fileRef = 4DED6F08176233A2001DEF0C /* EncodedJavaSupport.c */; };
2525
/* End PBXBuildFile section */
2626

2727
/* Begin PBXContainerItemProxy section */
@@ -42,12 +42,13 @@
4242
/* End PBXContainerItemProxy section */
4343

4444
/* Begin PBXFileReference section */
45+
4D332C3F178D7959005DFE92 /* EncodedJavaSupport.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = EncodedJavaSupport.c; path = src/EncodedJavaSupport.c; sourceTree = "<group>"; };
46+
4D332C40178D7959005DFE92 /* EncodedSupport.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = EncodedSupport.c; path = src/EncodedSupport.c; sourceTree = "<group>"; };
4547
4D3B10121367E35D00E00C1E /* Release.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Release.xcconfig; path = ../rules/Release.xcconfig; sourceTree = SOURCE_ROOT; };
4648
4D4051A1176B2D340097F2D6 /* NativeType.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = NativeType.cpp; path = src/NativeType.cpp; sourceTree = "<group>"; };
4749
4D4051A2176B2D340097F2D6 /* NativeType.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = NativeType.h; path = src/NativeType.h; sourceTree = "<group>"; };
4850
4D40538D176B43090097F2D6 /* LiveCode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = LiveCode.h; path = include/LiveCode.h; sourceTree = "<group>"; };
4951
4D57DF461338F14B0044FFEC /* lcidlc */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = lcidlc; sourceTree = BUILT_PRODUCTS_DIR; };
50-
4D9036901398FC0800CBC7F6 /* EncodedSupport.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = EncodedSupport.c; path = src/EncodedSupport.c; sourceTree = "<group>"; };
5152
4D9036911398FC0800CBC7F6 /* Error.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Error.cpp; path = src/Error.cpp; sourceTree = "<group>"; };
5253
4D9036921398FC0800CBC7F6 /* Error.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Error.h; path = src/Error.h; sourceTree = "<group>"; };
5354
4D9036931398FC0800CBC7F6 /* Interface.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Interface.cpp; path = src/Interface.cpp; sourceTree = "<group>"; };
@@ -73,7 +74,6 @@
7374
4DE553EC13A4D9E200C99D11 /* lclink.sh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.sh; path = lclink.sh; sourceTree = "<group>"; };
7475
4DE553ED13A4D9E200C99D11 /* lclinktest.sh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.sh; path = lclinktest.sh; sourceTree = "<group>"; };
7576
4DED6D131760ECD5001DEF0C /* Support.java */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.java; name = Support.java; path = src/Support.java; sourceTree = "<group>"; };
76-
4DED6F08176233A2001DEF0C /* EncodedJavaSupport.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = EncodedJavaSupport.c; path = src/EncodedJavaSupport.c; sourceTree = "<group>"; };
7777
/* End PBXFileReference section */
7878

7979
/* Begin PBXFrameworksBuildPhase section */
@@ -153,8 +153,8 @@
153153
4D9036AE1398FC1600CBC7F6 /* Derived Sources */ = {
154154
isa = PBXGroup;
155155
children = (
156-
4DED6F08176233A2001DEF0C /* EncodedJavaSupport.c */,
157-
4D9036901398FC0800CBC7F6 /* EncodedSupport.c */,
156+
4D332C3F178D7959005DFE92 /* EncodedJavaSupport.c */,
157+
4D332C40178D7959005DFE92 /* EncodedSupport.c */,
158158
);
159159
name = "Derived Sources";
160160
sourceTree = "<group>";
@@ -192,6 +192,7 @@
192192
buildConfigurationList = 4D57DF4B1338F14B0044FFEC /* Build configuration list for PBXNativeTarget "lcidlc" */;
193193
buildPhases = (
194194
4DBA0EB113679A08006EEA7D /* Encode Support */,
195+
4D332C1B178D78ED005DFE92 /* Encode Java Support */,
195196
4D57DF431338F14B0044FFEC /* Sources */,
196197
4D57DF441338F14B0044FFEC /* Frameworks */,
197198
);
@@ -247,23 +248,38 @@
247248
/* End PBXReferenceProxy section */
248249

249250
/* Begin PBXShellScriptBuildPhase section */
251+
4D332C1B178D78ED005DFE92 /* Encode Java Support */ = {
252+
isa = PBXShellScriptBuildPhase;
253+
buildActionMask = 2147483647;
254+
files = (
255+
);
256+
inputPaths = (
257+
"$(SRCROOT)/src/Support.java",
258+
);
259+
name = "Encode Java Support";
260+
outputPaths = (
261+
"$(SRCROOT)/src/EncodedJavaSupport.c",
262+
);
263+
runOnlyForDeploymentPostprocessing = 0;
264+
shellPath = /bin/sh;
265+
shellScript = "\"$SOLUTION_DIR/prebuilt/bin/Revolution.osx\" \"$SRCROOT/encode_source.rev\" \"$SRCROOT/src/Support.java\" \"$SRCROOT/src/EncodedJavaSupport.c\" \"g_java_support_template\"\n";
266+
showEnvVarsInLog = 0;
267+
};
250268
4DBA0EB113679A08006EEA7D /* Encode Support */ = {
251269
isa = PBXShellScriptBuildPhase;
252270
buildActionMask = 2147483647;
253271
files = (
254272
);
255273
inputPaths = (
256-
"$(SRCROOT)/Support.cpp",
257-
"$(SRCROOT)/Support.java",
274+
"$(SRCROOT)/src/Support.mm",
258275
);
259276
name = "Encode Support";
260277
outputPaths = (
261-
"$(SRCROOT)/EncodedSupport.c",
262-
"$(SRCROOT)/EncodedJavaSupport.c",
278+
"$(SRCROOT)/src/EncodedSupport.c",
263279
);
264280
runOnlyForDeploymentPostprocessing = 0;
265281
shellPath = /bin/sh;
266-
shellScript = "\"$SOLUTION_DIR/prebuilt/bin/Revolution.osx\" \"$SRCROOT/encode_source.rev\" \"$SRCROOT/src/Support.mm\" \"$SRCROOT/src/EncodedSupport.c\" \"g_support_template\"\n\"$SOLUTION_DIR/prebuilt/bin/Revolution.osx\" \"$SRCROOT/encode_source.rev\" \"$SRCROOT/src/Support.java\" \"$SRCROOT/src/EncodedJavaSupport.c\" \"g_java_support_template\"\n";
282+
shellScript = "\"$SOLUTION_DIR/prebuilt/bin/Revolution.osx\" \"$SRCROOT/encode_source.rev\" \"$SRCROOT/src/Support.mm\" \"$SRCROOT/src/EncodedSupport.c\" \"g_support_template\"\n";
267283
showEnvVarsInLog = 0;
268284
};
269285
/* End PBXShellScriptBuildPhase section */
@@ -273,8 +289,6 @@
273289
isa = PBXSourcesBuildPhase;
274290
buildActionMask = 2147483647;
275291
files = (
276-
4DED6F09176233B0001DEF0C /* EncodedJavaSupport.c in Sources */,
277-
4D9036A21398FC0800CBC7F6 /* EncodedSupport.c in Sources */,
278292
4D9036A31398FC0800CBC7F6 /* Error.cpp in Sources */,
279293
4D9036A41398FC0800CBC7F6 /* Interface.cpp in Sources */,
280294
4D9036A51398FC0800CBC7F6 /* InterfaceGenerate.cpp in Sources */,
@@ -285,6 +299,8 @@
285299
4D9036AA1398FC0800CBC7F6 /* Support.mm in Sources */,
286300
4D9036AB1398FC0800CBC7F6 /* Value.cpp in Sources */,
287301
4D4051A3176B2D340097F2D6 /* NativeType.cpp in Sources */,
302+
4D332C41178D7959005DFE92 /* EncodedJavaSupport.c in Sources */,
303+
4D332C42178D7959005DFE92 /* EncodedSupport.c in Sources */,
288304
);
289305
runOnlyForDeploymentPostprocessing = 0;
290306
};

lcidlc/src/InterfaceGenerate.cpp

Lines changed: 46 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1134,29 +1134,56 @@ static bool InterfaceGenerateExports(InterfaceRef self, CoderRef p_coder)
11341134
CoderWriteLine(p_coder, "JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved)");
11351135
CoderWriteLine(p_coder, "{");
11361136
CoderWriteLine(p_coder, "\ts_java_vm = vm;");
1137-
CoderWriteLine(p_coder, "\tJavaEnv *t_java_env; s_java_vm -> GetEnv((void **)&t_java_env, JNI_VERSION_1_2);");
1138-
CoderWriteLine(p_coder, "\ts_java_class = (jclass)t_java_env -> NewGlobalRef(t_java_env -> FindClass(\"%s\"));", t_java_class_name);
1137+
CoderWriteLine(p_coder, "\tJNIEnv *t_java_env; s_java_vm -> GetEnv((void **)&t_java_env, JNI_VERSION_1_2);");
1138+
CoderWriteLine(p_coder, "\ts_java_class = (jclass)t_java_env -> NewGlobalRef(t_java_env -> FindClass(\"%s/%s\"));", t_java_class_name, NameGetCString(self -> name));
11391139
CoderWriteLine(p_coder, "");
11401140
CoderWriteLine(p_coder, "\treturn JNI_VERSION_1_2;");
11411141
CoderWriteLine(p_coder, "}");
1142+
free(t_java_class_name);
11421143

1143-
#ifdef NOT_USED
1144+
static struct { const char *name; const char *result; const char *signature; const char *args; } s_java_exports[] =
1145+
{
1146+
{ "InterfaceQueryActivity", "jobject", nil, nil },
1147+
{ "InterfaceQueryContainer", "jobject", nil, nil },
1148+
{ "ObjectResolve", "jlong", "jobject chunk", "chunk" },
1149+
{ "ObjectRetain", "void", "jlong object", "object" },
1150+
{ "ObjectRelease", "void", "jlong object", "object" },
1151+
{ "ObjectExists", "jboolean", "jlong object", "object" },
1152+
{ "ObjectSend", "void", "jlong object, jobject message, jobject signature, jobject arguments", "object, message, signature, arguments" },
1153+
{ "ObjectPost", "void", "jlong object, jobject message, jobject signature, jobject arguments", "object, message, signature, arguments" },
1154+
{ "ContextMe", "jlong", nil, nil },
1155+
{ "ContextTarget", "jlong", nil, nil },
1156+
};
1157+
t_java_class_name = strdup(NameGetCString(self -> qualified_name));
11441158
for(uint32_t i = 0; t_java_class_name[i] != '\0'; i++)
1145-
if (t_java_class_name[i] == '/')
1159+
if (t_java_class_name[i] == '.')
11461160
t_java_class_name[i] = '_';
1147-
CoderWriteLine(p_coder, "extern \"C\" JNIEXPORT jobject JNICALL Java_%s_getActivity(JNIEnv *env, jobject obj) __attribute((visibility(\"default\")));", t_java_class_name);
1148-
CoderWriteLine(p_coder, "JNIEXPORT jobject JNICALL Java_%s_getActivity(JNIEnv *env, jobject obj)");
1149-
CoderWriteLine(p_coder, "{");
1150-
CoderWriteLine(p_coder, "\treturn java__get_activity();");
1151-
CoderWriteLine(p_coder, "}");
1152-
CoderWriteLine(p_coder, "extern \"C\" JNIEXPORT jobject JNICALL Java_%s_getContainer(JNIEnv *env, jobject obj) __attribute((visibility(\"default\")));", t_java_class_name);
1153-
CoderWriteLine(p_coder, "JNIEXPORT jobject JNICALL Java_%s_getContainer(JNIEnv *env, jobject obj)");
1154-
CoderWriteLine(p_coder, "{");
1155-
CoderWriteLine(p_coder, "\treturn java__get_container();");
1156-
CoderWriteLine(p_coder, "}");
1161+
for(unsigned int i = 0; i < sizeof(s_java_exports) / sizeof(s_java_exports[0]); i++)
1162+
{
1163+
if (s_java_exports[i] . signature == nil)
1164+
{
1165+
CoderWriteLine(p_coder, "extern \"C\" JNIEXPORT %s JNICALL Java_%s_LC__1_1%s(JNIEnv *env, jobject obj) __attribute((visibility(\"default\")));", s_java_exports[i] . result, t_java_class_name, s_java_exports[i] . name);
1166+
CoderWriteLine(p_coder, "JNIEXPORT %s JNICALL Java_%s_LC__1_1%s(JNIEnv *env, jobject obj)", s_java_exports[i] . result, t_java_class_name, s_java_exports[i] . name);
1167+
CoderWriteLine(p_coder, "{");
1168+
if (strcmp(s_java_exports[i] . result, "void") == 0)
1169+
CoderWriteLine(p_coder, " java_lcapi_%s(env);", s_java_exports[i] . name);
1170+
else
1171+
CoderWriteLine(p_coder, " return java_lcapi_%s(env);", s_java_exports[i] . name);
1172+
}
1173+
else
1174+
{
1175+
CoderWriteLine(p_coder, "extern \"C\" JNIEXPORT %s JNICALL Java_%s_LC__1_1%s(JNIEnv *env, jobject obj, %s) __attribute((visibility(\"default\")));", s_java_exports[i] . result, t_java_class_name, s_java_exports[i] . name, s_java_exports[i] . signature);
1176+
CoderWriteLine(p_coder, "JNIEXPORT %s JNICALL Java_%s_LC__1_1%s(JNIEnv *env, jobject obj, %s)", s_java_exports[i] . result, t_java_class_name, s_java_exports[i] . name, s_java_exports[i] . signature);
1177+
CoderWriteLine(p_coder, "{");
1178+
if (strcmp(s_java_exports[i] . result, "void") == 0)
1179+
CoderWriteLine(p_coder, " java_lcapi_%s(env, %s);", s_java_exports[i] . name, s_java_exports[i] . args);
1180+
else
1181+
CoderWriteLine(p_coder, " return java_lcapi_%s(env, %s);", s_java_exports[i] . name, s_java_exports[i] . args);
1182+
}
1183+
CoderWriteLine(p_coder, "}");
1184+
}
11571185
free(t_java_class_name);
1158-
#endif
1159-
1186+
11601187
CoderWriteLine(p_coder, "#endif");
11611188

11621189
return true;
@@ -1175,7 +1202,8 @@ static bool InterfaceGenerateJava(InterfaceRef self, CoderRef p_coder)
11751202
{
11761203
CoderWriteLine(p_coder, "package %s;", NameGetCString(self -> qualified_name));
11771204

1178-
// CoderWrite(p_coder, "%s", strchr(g_java_support_template, '\n') + 1);
1205+
for(unsigned int i = 1; g_java_support_template[i] != nil; i++)
1206+
CoderWrite(p_coder, "%s", g_java_support_template[i]);
11791207

11801208
return true;
11811209
}
@@ -1193,7 +1221,7 @@ bool InterfaceGenerate(InterfaceRef self, const char *p_output)
11931221
char *t_native_output_filename, *t_java_output_filename;
11941222
if (MCCStringEndsWith(p_output, "/"))
11951223
{
1196-
MCCStringFormat(t_native_output_filename, "%s%s.lcidlc.cpp", p_output, NameGetCString(self -> name));
1224+
MCCStringFormat(t_native_output_filename, "%s%s.lcidl.cpp", p_output, NameGetCString(self -> name));
11971225
MCCStringFormat(t_java_output_filename, "%sLC.java", p_output);
11981226
}
11991227
else

0 commit comments

Comments
 (0)