當前位置: 首頁>>代碼示例>>Java>>正文


Java LuaConversion類代碼示例

本文整理匯總了Java中ethanjones.cubes.core.lua.convert.LuaConversion的典型用法代碼示例。如果您正苦於以下問題:Java LuaConversion類的具體用法?Java LuaConversion怎麽用?Java LuaConversion使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


LuaConversion類屬於ethanjones.cubes.core.lua.convert包,在下文中一共展示了LuaConversion類的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: invokeFor

import ethanjones.cubes.core.lua.convert.LuaConversion; //導入依賴的package包/類
private void invokeFor(Class[] parameters, Object[] param, Varargs args, Method method) {
	try {
		for (int i = 0; i < parameters.length; i++) {

			param[i] = LuaConversion.convertToJava(parameters[i], args.arg(i + 1));
		}
	} catch (Exception ignored) {
		continue;
	}
	try {
		Object invoke = method.invoke(null, param);
		return LuaConversion.convertToLua(invoke);
	} catch (Exception e) {
		throw new LuaError(e);
	}
}
 
開發者ID:RedTroop,項目名稱:Cubes_2,代碼行數:17,代碼來源:LuaMethod.java

示例2: luaTable1

import ethanjones.cubes.core.lua.convert.LuaConversion; //導入依賴的package包/類
private void luaTable1() {
	LuaTable metatable = new LuaTable();
	metatable.rawset("__index", new TwoArgFunction() {
		@Override
		public LuaValue call(LuaValue arg1, LuaValue arg2) {
			String s = arg2.tojstring();
			try {
				Field field = c.getField(s);
				int modifiers = field.getModifiers();
				if (Modifier.isStatic(modifiers) && field.getAnnotation(LuaExclude.class) == null) {
					return LuaConversion.convertToLua(field.get(null));
				}
			} catch (Exception ignored) {
			}
			
			luaTableTry( s);
			
			error("No such field or method: " + s);
			return null;
		}
	});
}
 
開發者ID:RedTroop,項目名稱:Cubes_2,代碼行數:23,代碼來源:LuaClass.java

示例3: method

import ethanjones.cubes.core.lua.convert.LuaConversion; //導入依賴的package包/類
@RuntimeType
public Object method(@Origin Method aMethod, @This Object o, @AllArguments Object[] objects,
		@SuperCall Callable supercall) {
	LuaValue value = delegations.get(aMethod.getName());
	if (value.isnil()) {
		try {
			return supercall.call();
		} catch (Exception e) {
			throw new DynamicDelegationError("Supercall threw exception - no delegation supplied", e);
		}
	}
	if (value.isfunction()) {
		LuaFunction function = value.checkfunction();
		LuaValue[] parameters = convertParamsToLua(o, objects, supercall);
		Varargs invoke = function.invoke(parameters);
		if (aMethod.getReturnType() == Void.class || invoke.narg() == 0)
			return null;
		return LuaConversion.convertToJava(aMethod.getReturnType(), invoke.checkvalue(1));
	} else {
		return LuaConversion.convertToJava(aMethod.getReturnType(), value);
	}
}
 
開發者ID:RedTroop,項目名稱:Cubes_2,代碼行數:23,代碼來源:LuaGeneration.java

示例4: convertParamsToLua

import ethanjones.cubes.core.lua.convert.LuaConversion; //導入依賴的package包/類
public static LuaValue[] convertParamsToLua(Object instance, Object[] objects, final Callable supercall) {
	LuaValue[] parameters = new LuaValue[objects.length + 2];
	parameters[0] = LuaConversion.convertToLua(instance);
	for (int i = 0; i < objects.length; i++) {
		parameters[i + 1] = LuaConversion.convertToLua(objects[i]);
	}
	parameters[parameters.length - 1] = new VarArgFunction() {
		@Override
		public Varargs invoke(Varargs args) {
			try {
				Object o = supercall.call();
				return LuaConversion.convertToLua(o);
			} catch (Exception e) {
				throw new DynamicDelegationError("Supercall threw exception - called from supplied delegation", e);
			}
		}
	};
	return parameters;
}
 
開發者ID:RedTroop,項目名稱:Cubes_2,代碼行數:20,代碼來源:LuaGeneration.java

示例5: convertParamsToLua

import ethanjones.cubes.core.lua.convert.LuaConversion; //導入依賴的package包/類
public static LuaValue[] convertParamsToLua(Object instance, Object[] objects, final Callable supercall) {
  LuaValue[] parameters = new LuaValue[objects.length + 2];
  parameters[0] = LuaConversion.convertToLua(instance);
  for (int i = 0; i < objects.length; i++) {
    parameters[i + 1] = LuaConversion.convertToLua(objects[i]);
  }
  parameters[parameters.length - 1] = new VarArgFunction() {
    @Override
    public Varargs invoke(Varargs args) {
      try {
        Object o = supercall.call();
        return LuaConversion.convertToLua(o);
      } catch (Exception e) {
        throw new DynamicDelegationError("Supercall threw exception - called from supplied delegation", e);
      }
    }
  };
  return parameters;
}
 
開發者ID:RedTroop,項目名稱:Cubes,代碼行數:20,代碼來源:LuaGeneration.java

示例6: luaTable3

import ethanjones.cubes.core.lua.convert.LuaConversion; //導入依賴的package包/類
private void luaTable3() {
	metatable.rawset("__call", new VarArgFunction() {

		@Override
		public Varargs invoke(Varargs args) {
			Constructor[] constructors = c.getConstructors();
			if (constructors.length == 0)
				error("No constructors");
			for (Constructor constructor : constructors) {
				if (constructor.getAnnotation(LuaExclude.class) != null)
					continue;
				Class[] parameters = constructor.getParameterTypes();
				if (parameters.length + 1 != args.narg())
					continue;
				Object[] param = new Object[parameters.length];

				for (int i = 0; i < parameters.length; i++) {
					try {
						param[i] = LuaConversion.convertToJava(parameters[i], args.arg(i + 2));
					} catch (Exception ignored) {
						continue;
					}
				}

				try {
					return LuaConversion.convertToLua(constructor.newInstance(param));
				} catch (Exception e) {
					throw new LuaError(e);
				}
			}
			argerror(Arrays.toString(constructors));
			return null;
		}
	});
}
 
開發者ID:RedTroop,項目名稱:Cubes_2,代碼行數:36,代碼來源:LuaClass.java

示例7: LuaClass

import ethanjones.cubes.core.lua.convert.LuaConversion; //導入依賴的package包/類
public LuaClass(final Class c) {
	super(new Object());
	this.c = c;

	luaTable1();

	metatable.rawset("__newindex", new ThreeArgFunction() {
		@Override
		public LuaValue call(LuaValue arg1, LuaValue arg2, LuaValue arg3) {
			String s = arg2.tojstring();
			try {
				Field field = c.getField(s);
				int modifiers = field.getModifiers();
				if (Modifier.isStatic(modifiers) && !Modifier.isFinal(modifiers)
						&& field.getAnnotation(LuaExclude.class) == null) {
					Class<?> type = field.getType();
					Object o = LuaConversion.convertToJava(type, arg3);
					field.set(null, o);
					return NIL;
				}
			} catch (Exception e) {
				if (e instanceof ConversionError)
					throw (ConversionError) e;
			}
			error("No such field: " + s);
			return null;
		}
	});

	luaTable3();

	metatable.rawset("__tostring", new ZeroArgFunction() {
		@Override
		public LuaValue call() {
			return LuaValue.valueOf("[JClass: " + LuaClass.this.c.getName() + "]");
		}
	});
	metatable.rawset("__metatable", LuaValue.FALSE);
	setmetatable(metatable);
}
 
開發者ID:RedTroop,項目名稱:Cubes_2,代碼行數:41,代碼來源:LuaClass.java

示例8: GlobalIf2

import ethanjones.cubes.core.lua.convert.LuaConversion; //導入依賴的package包/類
private LuaConversion GlobalIf2(LiaValue args) {
	if (args.narg() <= 1 || (args.narg() == 2 && args.arg1().isnil()))
		throw new LuaError("Invalid extend arguments: " + args.toString());
	LuaTable delegations = args.arg(args.narg()).checktable();
	Class extend = args.arg1().isnil() ? Object.class : convertToClass(args.arg1());
	Class[] inherit = new Class[args.narg() - 2];
	for (int i = 0; i < inherit.length; i++) {
		inherit[i] = convertToClass(args.arg(i + 2));
	}
	Class c = LuaGeneration.extendClass(extend, delegations, inherit);
	return LuaConversion.convertToLua(c);
}
 
開發者ID:RedTroop,項目名稱:Cubes_2,代碼行數:13,代碼來源:CubesLua.java

示例9: GlobalIf3

import ethanjones.cubes.core.lua.convert.LuaConversion; //導入依賴的package包/類
private LuaConversion GlobalIf3(LuaValue args) {
	if (args.narg() == 1) {
		Log.info(tostring.call(args.arg1()).strvalue().tojstring());
	} else {
		StringBuilder out = new StringBuilder();
		for (int i = 1, n = args.narg(); i <= n; i++) {
			if (i > 1)
				out.append("\t");
			out.append(tostring.call(args.arg(i)).strvalue().tojstring());
		}
		Log.info(out.toString());
	}
}
 
開發者ID:RedTroop,項目名稱:Cubes_2,代碼行數:14,代碼來源:CubesLua.java


注:本文中的ethanjones.cubes.core.lua.convert.LuaConversion類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。