Exemplo n.º 1
0
/**
 * Called when the JavaObject is invoked as a function.
 * We ignore the JSObject* argument, which is the 'this' context, which is
 * usually the window object. The JavaObject instance is in argv[-2].
 *
 * Returns a JS array, with the first element being a boolean indicating that
 * an exception occured, and the second element is either the return value or
 * the exception which was thrown.  In this case, we always return false and
 * raise the exception ourselves.
 */
JSBool JavaObject::call(JSContext* ctx, JSObject*, uintN argc, jsval* argv,
    jsval* rval) {
  // Get the JavaObject called as a function
  JSObject* obj = JSVAL_TO_OBJECT(argv[-2]);
  if (argc < 2 || !JSVAL_IS_INT(argv[0]) ||
#ifdef JSVAL_IS_OBJECT
  !JSVAL_IS_OBJECT(argv[1])) {
#else
    (JSVAL_IS_PRIMITIVE(argv[1]) && !JSVAL_IS_NULL(argv[1]))) {
#endif
    Debug::log(Debug::Error) << "JavaObject::call incorrect arguments" << Debug::flush;
    return JS_FALSE;
  }
  int dispId = JSVAL_TO_INT(argv[0]);
  if (Debug::level(Debug::Spam)) {
    Debug::DebugStream& dbg = Debug::log(Debug::Spam) << "JavaObject::call oid="
        << JavaObject::getObjectId(ctx, obj) << ",dispId=" << dispId << " (";
    for (unsigned i = 2; i < argc; ++i) {
      if (i > 2) {
        dbg << ", ";
      }
      dbg << dumpJsVal(ctx, argv[i]);
    }
    dbg << ")" << Debug::flush;
  }

  SessionData* data = JavaObject::getSessionData(ctx, obj);
  if (!data) {
    *rval = JSVAL_VOID;
    return JS_TRUE;
  }
  Debug::log(Debug::Spam) << "Data = " << data << Debug::flush;

  gwt::Value javaThis;
  if (!JSVAL_IS_NULL(argv[1])) {
    JSObject* thisObj = JSVAL_TO_OBJECT(argv[1]);
    if (isJavaObject(ctx, thisObj)) {
      javaThis.setJavaObject(getObjectId(ctx, thisObj));
    } else {
      data->makeValueFromJsval(javaThis, ctx, argv[1]);
    }
  } else {
    int oid = getObjectId(ctx, obj);
    javaThis.setJavaObject(oid);
  }
  return invokeJava(ctx, data, javaThis, dispId, argc - 2, &argv[2], rval);
}
Exemplo n.º 2
0
int jGetStaticMethodID(lua_State * L)
{
	lua_Number stateIndex;
	jobject *userData;
	jclass clazz;
	jmethodID method;
	const char *methodName;
	const char *sign;
	JNIEnv *javaEnv;

	if (!isJavaObject(L, 1))
	{
		lua_pushstring(L, "Not a valid java class.");
		lua_error(L);
	}

	/* Gets the JNI Environment */
	javaEnv = getEnvFromState(L);
	if (javaEnv == NULL)
	{
		lua_pushstring(L, "Invalid JNI Environment.");
		lua_error(L);
	}

	sign = lua_tostring(L, 3);
	methodName = lua_tostring(L, 2);
	userData = (jobject *) lua_touserdata(L, 1);
	clazz = (jclass) * userData;

	method = (*javaEnv)->GetStaticMethodID(javaEnv, clazz, methodName, sign);
	checkError(javaEnv, L);
	if (method == NULL)
	{
		lua_pushstring(L, "method no such");
		lua_error(L);
    }
	userData = (jobject *) lua_newuserdata(L, sizeof(method));
	*userData = method;
	return 1;
}
Exemplo n.º 3
0
int gc(lua_State * L)
{
	jobject *pObj;
	JNIEnv *javaEnv;

	if (!isJavaObject(L, 1))
	{
		return 0;
	}

	pObj = (jobject *) lua_touserdata(L, 1);

	/* Gets the JNI Environment */
	javaEnv = getEnvFromState(L);
	if (javaEnv == NULL)
	{
		lua_pushstring(L, "Invalid JNI Environment.");
		lua_error(L);
	}

	(*javaEnv)->DeleteGlobalRef(javaEnv, *pObj);

	return 0;
}