Java Code Examples for org.luaj.vm2.LuaValue#islong()

The following examples show how to use org.luaj.vm2.LuaValue#islong() . 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 File: Utilities.java    From Lukkit with MIT License 6 votes vote down vote up
/**
 * Gets the Java object from a LuaValue.
 *
 * @param value the LuaValue
 * @return the Java object
 */
public static Object getObjectFromLuavalue(LuaValue value) {
    if (value.istable()) {
        return convertTable(value.checktable());
    } else if (value.isint()) {
        return value.checkint();
    } else if (value.islong()) {
        return value.checklong();
    } else if (value.isnumber()) {
        return value.checkdouble();
    } else if (value.isstring()) {
        return value.checkjstring();
    } else if (value.isboolean()) {
        return value.checkboolean();
    } else if (value.isnil()) {
        return null;
    } else {
        return value.checkuserdata();
    }
}
 
Example 2
Source File: MathLib.java    From luaj with MIT License 5 votes vote down vote up
public Varargs invoke(Varargs args) {
	LuaValue n = args.arg1();
	/* number is its own integer part, no fractional part */
	if (n.islong()) return varargsOf(n, valueOf(0.0));
	double x = n.checkdouble();
	/* integer part (rounds toward zero) */
	double intPart = ( x > 0 ) ? Math.floor( x ) : Math.ceil( x );
	/* fractional part (test needed for inf/-inf) */
	double fracPart = x == intPart ? 0.0 : x - intPart;
	return varargsOf( valueOf(intPart), valueOf(fracPart) );
}
 
Example 3
Source File: MathLib.java    From luaj with MIT License 4 votes vote down vote up
public LuaValue call(LuaValue xv, LuaValue yv) {
	if (xv.islong() && yv.islong()) {
		return valueOf(xv.tolong() % yv.tolong());
	}
	return valueOf(xv.checkdouble() % yv.checkdouble());
}