Move emulator-base native code into its own non-Gradle directory.
[SquirrelJME.git] / emulators / emulator-base-native / headers / squirreljme.h
blob656b38195e1e20c1c857e1b40d04119c4db7217f
1 /* -*- Mode: C++; indent-tabs-mode: t; tab-width: 4 -*-
2 // ---------------------------------------------------------------------------
3 // SquirrelJME
4 // Copyright (C) Stephanie Gawroriski <xer@multiphasicapps.net>
5 // ---------------------------------------------------------------------------
6 // SquirrelJME is under the Mozilla Public License Version 2.0.
7 // See license.mkd for licensing and copyright information.
8 // -------------------------------------------------------------------------*/
10 #ifndef __SQUIRRELJME_H__
11 #define __SQUIRRELJME_H__
13 #include "jni.h"
15 /** Initializing methods. */
16 jint JNICALL mleDebugInit(JNIEnv* env, jclass classy);
17 jint JNICALL mleFormInit(JNIEnv* env, jclass classy);
18 jint JNICALL mleJarInit(JNIEnv* env, jclass classy);
19 jint JNICALL mleMathInit(JNIEnv* env, jclass classy);
20 jint JNICALL mleMidiInit(JNIEnv* env, jclass classy);
21 jint JNICALL mleNativeArchiveInit(JNIEnv* env, jclass classy);
22 jint JNICALL mleObjectInit(JNIEnv* env, jclass classy);
23 jint JNICALL mlePencilInit(JNIEnv* env, jclass classy);
24 jint JNICALL mleReflectionInit(JNIEnv* env, jclass classy);
25 jint JNICALL mleRuntimeInit(JNIEnv* env, jclass classy);
26 jint JNICALL mleTaskInit(JNIEnv* env, jclass classy);
27 jint JNICALL mleTerminalInit(JNIEnv* env, jclass classy);
28 jint JNICALL mleTypeInit(JNIEnv* env, jclass classy);
29 jint JNICALL mleThreadInit(JNIEnv* env, jclass classy);
31 /** Useful macros, structures, and functions for forwarding. */
32 // Stores forwarded information
33 typedef struct forwardMethod
35 jclass xclass;
36 jmethodID xmeth;
37 } forwardMethod;
39 // Find forwarded method
40 forwardMethod JNICALL findForwardMethod(JNIEnv* env,
41 const char* const classy, const char* const name, const char* const type);
43 // Call static methods
44 void JNICALL forwardCallStaticVoid(JNIEnv* env,
45 const char* const classy, const char* const name, const char* const type,
46 ...);
47 jint JNICALL forwardCallStaticInteger(JNIEnv* env,
48 const char* const classy, const char* const name, const char* const type,
49 ...);
50 jlong JNICALL forwardCallStaticLong(JNIEnv* env,
51 const char* const classy, const char* const name, const char* const type,
52 ...);
53 jobject JNICALL forwardCallStaticObject(JNIEnv* env,
54 const char* const classy, const char* const name, const char* const type,
55 ...);
56 jboolean JNICALL forwardCallStaticBoolean(JNIEnv* env,
57 const char* const classy, const char* const name, const char* const type,
58 ...);
60 #define FORWARD_init(funcName, forwardFuncs) \
61 jint JNICALL funcName(JNIEnv* env, jclass classy) \
62 { \
63 return (*env)->RegisterNatives(env, \
64 (*env)->FindClass(env, FORWARD_CLASS), \
65 forwardFuncs, sizeof(forwardFuncs) / sizeof(JNINativeMethod)); \
68 #define FORWARD_stringy(x) #x
70 #define FORWARD_paste(x, y) x ## y
72 #define FORWARD_from(x) x
74 #define FORWARD_list(className, methodName) \
75 {FORWARD_stringy(methodName), \
76 FORWARD_from(FORWARD_paste(FORWARD_DESC_, methodName)), \
77 (void*)Impl_mle_ ## className ## _ ## methodName}
79 #define FORWARD_IMPL_none()
81 #define FORWARD_IMPL_args(...) , __VA_ARGS__
83 #define FORWARD_IMPL_pass(...) , __VA_ARGS__
85 #define FORWARD_IMPL_none()
87 #define FORWARD_IMPL_VOID(className, methodName, args, pass) \
88 JNIEXPORT void JNICALL Impl_mle_ ## className ## _ ## methodName( \
89 JNIEnv* env, jclass classy args) \
90 { \
91 forwardCallStaticVoid(env, FORWARD_NATIVE_CLASS, \
92 FORWARD_stringy(methodName), \
93 FORWARD_from(FORWARD_paste(FORWARD_DESC_, methodName)) \
94 pass); \
97 #define FORWARD_IMPL(className, methodName, rtype, rjava, args, pass) \
98 JNIEXPORT rtype JNICALL Impl_mle_ ## className ## _ ## methodName( \
99 JNIEnv* env, jclass classy args) \
101 return FORWARD_paste(forwardCallStatic, rjava)(env, \
102 FORWARD_NATIVE_CLASS, \
103 FORWARD_stringy(methodName), \
104 FORWARD_from(FORWARD_paste(FORWARD_DESC_, methodName)) \
105 pass); \
108 #define DESC_ARRAY(x) "[" x
109 #define DESC_CLASS(x) "L" x ";"
110 #define DESC_BOOLEAN "Z"
111 #define DESC_BYTE "B"
112 #define DESC_SHORT "S"
113 #define DESC_CHAR "C"
114 #define DESC_INT "I"
115 #define DESC_LONG "J"
116 #define DESC_FLOAT "F"
117 #define DESC_DOUBLE "D"
118 #define DESC_VOID "V"
119 #define DESC_STRING DESC_CLASS("java/lang/String")
121 #endif /* __SQUIRRELJME_H__ */