Java源码示例:org.luaj.vm2.LuaDouble

示例1
public LuaValue call(LuaValue modname, LuaValue env) {
	LuaTable math = new LuaTable(0,30);
	math.set("abs", new abs());
	math.set("ceil", new ceil());
	math.set("cos", new cos());
	math.set("deg", new deg());
	math.set("exp", new exp(this));
	math.set("floor", new floor());
	math.set("fmod", new fmod());
	math.set("frexp", new frexp());
	math.set("huge", LuaDouble.POSINF );
	math.set("ldexp", new ldexp());
	math.set("max", new max());
	math.set("min", new min());
	math.set("modf", new modf());
	math.set("pi", Math.PI );
	math.set("pow", new pow());
	random r;
	math.set("random", r = new random());
	math.set("randomseed", new randomseed(r));
	math.set("rad", new rad());
	math.set("sin", new sin());
	math.set("sqrt", new sqrt());
	math.set("tan", new tan());
	env.set("math", math);
	env.get("package").get("loaded").set("math", math);
	return math;
}
 
示例2
/** compute power using installed math library, or default if there is no math library installed */
public static LuaValue dpow(double a, double b) {
	return LuaDouble.valueOf( 
			MATHLIB!=null?
			MATHLIB.dpow_lib(a,b):
			dpow_default(a,b) );
}
 
示例3
int numberK(LuaValue r) {
	if ( r instanceof LuaDouble ) {
		double d = r.todouble();
		int i = (int) d;
		if ( d == (double) i ) 
			r = LuaInteger.valueOf(i);
	}
	return this.addk(r);
}
 
示例4
/**
 * convert a table to map
 *
 * @param table
 * @return
 */
public static HashMap<String, String> toMap(LuaTable table) {
    if (table != null) {
        final HashMap<String, String> result = new HashMap<String, String>();
        final LuaValue[] keys = table.keys();
        for (LuaValue key : keys) {
            LuaValue luaValue = table.get(key);
            String value = null;
            if (luaValue.istable()) {
                value = JsonUtil.toString(luaValue);
            } else {
                if (luaValue instanceof LuaBoolean) {
                    value = String.valueOf(luaValue.optboolean(false));
                } else if (luaValue instanceof LuaInteger) {
                    value = String.valueOf(luaValue.optint(0));
                } else if (luaValue instanceof LuaDouble) {
                    value = String.valueOf(luaValue.optdouble(0));
                } else if (luaValue instanceof LuaString) {
                    value = String.valueOf(luaValue.optstring(null));
                } else {
                    value = String.valueOf(luaValue);
                }
            }
            if (value != null) {
                result.put(key.optjstring(null), value);
            }
        }
        return result;
    }
    return null;
}
 
示例5
/** Perform one-time initialization on the library by creating a table
 * containing the library functions, adding that table to the supplied environment,
 * adding the table to package.loaded, and returning table as the return value.
 * @param modname the module name supplied if this is loaded via 'require'.
 * @param env the environment to load into, typically a Globals instance.
 */
public LuaValue call(LuaValue modname, LuaValue env) {
	LuaTable math = new LuaTable(0,30);
	math.set("abs", new abs());
	math.set("ceil", new ceil());
	math.set("cos", new cos());
	math.set("deg", new deg());
	math.set("exp", new exp(this));
	math.set("floor", new floor());
	math.set("fmod", new fmod());
	math.set("frexp", new frexp());
	math.set("huge", LuaDouble.POSINF );
	math.set("ldexp", new ldexp());
	math.set("max", new max());
	math.set("min", new min());
	math.set("modf", new modf());
	math.set("pi", Math.PI );
	math.set("pow", new pow());
	random r;
	math.set("random", r = new random());
	math.set("randomseed", new randomseed(r));
	math.set("rad", new rad());
	math.set("sin", new sin());
	math.set("sqrt", new sqrt());
	math.set("tan", new tan());
	env.set("math", math);
	env.get("package").get("loaded").set("math", math);
	return math;
}
 
示例6
/** compute power using installed math library, or default if there is no math library installed */
public static LuaValue dpow(double a, double b) {
	return LuaDouble.valueOf( 
			MATHLIB!=null?
			MATHLIB.dpow_lib(a,b):
			dpow_default(a,b) );
}
 
示例7
int numberK(LuaValue r) {
	if ( r instanceof LuaDouble ) {
		double d = r.todouble();
		int i = (int) d;
		if ( d == (double) i ) 
			r = LuaInteger.valueOf(i);
	}
	return this.addk(r);
}
 
示例8
/** Perform one-time initialization on the library by creating a table
 * containing the library functions, adding that table to the supplied environment,
 * adding the table to package.loaded, and returning table as the return value.
 * @param modname the module name supplied if this is loaded via 'require'.
 * @param env the environment to load into, typically a Globals instance.
 */
public LuaValue call(LuaValue modname, LuaValue env) {
	LuaTable math = new LuaTable(0,30);
	math.set("abs", new abs());
	math.set("ceil", new ceil());
	math.set("cos", new cos());
	math.set("deg", new deg());
	math.set("exp", new exp(this));
	math.set("floor", new floor());
	math.set("fmod", new fmod());
	math.set("frexp", new frexp());
	math.set("huge", LuaDouble.POSINF );
	math.set("ldexp", new ldexp());
	math.set("max", new max());
	math.set("min", new min());
	math.set("modf", new modf());
	math.set("pi", Math.PI );
	math.set("pow", new pow());
	random r;
	math.set("random", r = new random());
	math.set("randomseed", new randomseed(r));
	math.set("rad", new rad());
	math.set("sin", new sin());
	math.set("sqrt", new sqrt());
	math.set("tan", new tan());
	env.set("math", math);
	env.get("package").get("loaded").set("math", math);
	return math;
}
 
示例9
/** compute power using installed math library, or default if there is no math library installed */
public static LuaValue dpow(double a, double b) {
	return LuaDouble.valueOf( 
			MATHLIB!=null?
			MATHLIB.dpow_lib(a,b):
			dpow_default(a,b) );
}
 
示例10
int numberK(LuaValue r) {
	if ( r instanceof LuaDouble ) {
		double d = r.todouble();
		int i = (int) d;
		if ( d == (double) i ) 
			r = LuaInteger.valueOf(i);
	}
	return this.addk(r);
}
 
示例11
/** Perform one-time initialization on the library by creating a table
 * containing the library functions, adding that table to the supplied environment,
 * adding the table to package.loaded, and returning table as the return value.
 * @param modname the module name supplied if this is loaded via 'require'.
 * @param env the environment to load into, typically a Globals instance.
 */
public LuaValue call(LuaValue modname, LuaValue env) {
	LuaTable math = new LuaTable(0,30);
	math.set("abs", new abs());
	math.set("ceil", new ceil());
	math.set("cos", new cos());
	math.set("deg", new deg());
	math.set("exp", new exp(this));
	math.set("floor", new floor());
	math.set("fmod", new fmod());
	math.set("frexp", new frexp());
	math.set("huge", LuaDouble.POSINF );
	math.set("ldexp", new ldexp());
	math.set("max", new max());
	math.set("min", new min());
	math.set("modf", new modf());
	math.set("pi", Math.PI );
	math.set("pow", new pow());
	random r;
	math.set("random", r = new random());
	math.set("randomseed", new randomseed(r));
	math.set("rad", new rad());
	math.set("sin", new sin());
	math.set("sqrt", new sqrt());
	math.set("tan", new tan());
	env.set("math", math);
	if (!env.get("package").isnil()) env.get("package").get("loaded").set("math", math);
	return math;
}
 
示例12
/** compute power using installed math library, or default if there is no math library installed */
public static LuaValue dpow(double a, double b) {
	return LuaDouble.valueOf(
			MATHLIB!=null?
			MATHLIB.dpow_lib(a,b):
			dpow_default(a,b) );
}
 
示例13
int numberK(LuaValue r) {
	if ( r instanceof LuaDouble ) {
		double d = r.todouble();
		int i = (int) d;
		if ( d == (double) i )
			r = LuaInteger.valueOf(i);
	}
	return this.addk(r);
}
 
示例14
public LuaValue coerce(Object javaValue) {
    Number n = (Number) javaValue;
    return LuaDouble.valueOf(n.doubleValue());
}
 
示例15
public LuaValue coerce( Object javaValue ) {
	Number n = (Number) javaValue;
	return LuaDouble.valueOf( n.doubleValue() );
}
 
示例16
public LuaValue coerce( Object javaValue ) {
	Number n = (Number) javaValue;
	return LuaDouble.valueOf( n.doubleValue() );
}
 
示例17
public LuaValue coerce( Object javaValue ) {
	Number n = (Number) javaValue;
	return LuaDouble.valueOf( n.doubleValue() );
}