MCPcopy Create free account
hub / github.com/Ahmeth4n/renef / lua_java_new

Function lua_java_new

src/agent/lua/api_java.c:752–788  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

750}
751
752static int lua_java_new(lua_State* L) {
753 JavaClassWrapper** ud = (JavaClassWrapper**)luaL_checkudata(L, 1, JAVA_WRAPPER_MT);
754 JavaClassWrapper* wrapper = *ud;
755 const char* sig = luaL_optstring(L, 2, "()V");
756
757 JNIEnv* env = get_jni_env();
758 if (!env) {
759 lua_pushnil(L);
760 lua_pushstring(L, "Failed to get JNIEnv");
761 return 2;
762 }
763
764
765 jvalue args[MAX_PARAMS];
766 memset(args, 0, sizeof(args));
767
768 ParsedSignature parsed = parse_signature(sig);
769 lua_to_jvalue(env, L, &parsed, args, 3);
770
771 jobject instance = java_new(env, wrapper, sig, args);
772 if (!instance) {
773 lua_pushnil(L);
774 lua_pushstring(L, "Failed to create instance");
775 return 2;
776 }
777
778 jobject global_instance = (*env)->NewGlobalRef(env, instance);
779 (*env)->DeleteLocalRef(env, instance);
780
781 jobject* inst_ud = (jobject*)lua_newuserdata(L, sizeof(jobject));
782 *inst_ud = global_instance;
783
784 luaL_getmetatable(L, JAVA_INSTANCE_MT);
785 lua_setmetatable(L, -2);
786
787 return 1;
788}
789
790static int lua_java_call_static(lua_State* L) {
791 JavaClassWrapper** ud = (JavaClassWrapper**)luaL_checkudata(L, 1, JAVA_WRAPPER_MT);

Callers

nothing calls this directly

Calls 4

get_jni_envFunction · 0.85
parse_signatureFunction · 0.85
lua_to_jvalueFunction · 0.85
java_newFunction · 0.85

Tested by

no test coverage detected