org.luaj.vm2.LuaDouble Java Examples

The following examples show how to use org.luaj.vm2.LuaDouble. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source Project: VideoOS-Android-SDK   Author: VideoOS   File: MathLib.java    License: GNU General Public License v3.0 5 votes vote down vote up
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;
}
 
Example #2
Source Project: VideoOS-Android-SDK   Author: VideoOS   File: MathLib.java    License: GNU General Public License v3.0 5 votes vote down vote up
/** 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) );
}
 
Example #3
Source Project: VideoOS-Android-SDK   Author: VideoOS   File: FuncState.java    License: GNU General Public License v3.0 5 votes vote down vote up
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);
}
 
Example #4
Source Project: VideoOS-Android-SDK   Author: VideoOS   File: LuaUtil.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #5
Source Project: XPrivacyLua   Author: M66B   File: MathLib.java    License: GNU General Public License v3.0 5 votes vote down vote up
/** 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;
}
 
Example #6
Source Project: XPrivacyLua   Author: M66B   File: MathLib.java    License: GNU General Public License v3.0 5 votes vote down vote up
/** 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) );
}
 
Example #7
Source Project: XPrivacyLua   Author: M66B   File: FuncState.java    License: GNU General Public License v3.0 5 votes vote down vote up
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);
}
 
Example #8
Source Project: HtmlNative   Author: hsllany   File: MathLib.java    License: Apache License 2.0 5 votes vote down vote up
/** 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;
}
 
Example #9
Source Project: HtmlNative   Author: hsllany   File: MathLib.java    License: Apache License 2.0 5 votes vote down vote up
/** 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) );
}
 
Example #10
Source Project: HtmlNative   Author: hsllany   File: FuncState.java    License: Apache License 2.0 5 votes vote down vote up
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);
}
 
Example #11
Source Project: luaj   Author: luaj   File: MathLib.java    License: MIT License 5 votes vote down vote up
/** 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;
}
 
Example #12
Source Project: luaj   Author: luaj   File: MathLib.java    License: MIT License 5 votes vote down vote up
/** 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) );
}
 
Example #13
Source Project: luaj   Author: luaj   File: FuncState.java    License: MIT License 5 votes vote down vote up
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);
}
 
Example #14
Source Project: VideoOS-Android-SDK   Author: VideoOS   File: CoerceJavaToLua.java    License: GNU General Public License v3.0 4 votes vote down vote up
public LuaValue coerce(Object javaValue) {
    Number n = (Number) javaValue;
    return LuaDouble.valueOf(n.doubleValue());
}
 
Example #15
Source Project: XPrivacyLua   Author: M66B   File: CoerceJavaToLua.java    License: GNU General Public License v3.0 4 votes vote down vote up
public LuaValue coerce( Object javaValue ) {
	Number n = (Number) javaValue;
	return LuaDouble.valueOf( n.doubleValue() );
}
 
Example #16
Source Project: HtmlNative   Author: hsllany   File: CoerceJavaToLua.java    License: Apache License 2.0 4 votes vote down vote up
public LuaValue coerce( Object javaValue ) {
	Number n = (Number) javaValue;
	return LuaDouble.valueOf( n.doubleValue() );
}
 
Example #17
Source Project: luaj   Author: luaj   File: CoerceJavaToLua.java    License: MIT License 4 votes vote down vote up
public LuaValue coerce( Object javaValue ) {
	Number n = (Number) javaValue;
	return LuaDouble.valueOf( n.doubleValue() );
}