Java Code Examples for org.luaj.vm2.LuaValue#ZERO

The following examples show how to use org.luaj.vm2.LuaValue#ZERO . 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: LexState.java    From VideoOS-Android-SDK with GNU General Public License v3.0 5 votes vote down vote up
boolean str2d(String str, SemInfo seminfo) {
    if (str.indexOf('n') >= 0 || str.indexOf('N') >= 0)
        seminfo.r = LuaValue.ZERO;
    else if (str.indexOf('x') >= 0 || str.indexOf('X') >= 0)
        seminfo.r = strx2number(str, seminfo);
    else
        seminfo.r = LuaValue.valueOf(Double.parseDouble(str.trim()));
    return true;
}
 
Example 2
Source File: LexState.java    From XPrivacyLua with GNU General Public License v3.0 5 votes vote down vote up
boolean str2d(String str, SemInfo seminfo) {
	if (str.indexOf('n')>=0 || str.indexOf('N')>=0)
		seminfo.r = LuaValue.ZERO;
	else if (str.indexOf('x')>=0 || str.indexOf('X')>=0)
		seminfo.r = strx2number(str, seminfo);
	else
		seminfo.r = LuaValue.valueOf(Double.parseDouble(str.trim()));
	return true;
}
 
Example 3
Source File: LexState.java    From HtmlNative with Apache License 2.0 5 votes vote down vote up
boolean str2d(String str, SemInfo seminfo) {
	if (str.indexOf('n')>=0 || str.indexOf('N')>=0)
		seminfo.r = LuaValue.ZERO;
	else if (str.indexOf('x')>=0 || str.indexOf('X')>=0)
		seminfo.r = strx2number(str, seminfo);
	else
		seminfo.r = LuaValue.valueOf(Double.parseDouble(str.trim()));
	return true;
}
 
Example 4
Source File: LexState.java    From luaj with MIT License 5 votes vote down vote up
boolean str2d(String str, SemInfo seminfo) {
	if (str.indexOf('n')>=0 || str.indexOf('N')>=0)
		seminfo.r = LuaValue.ZERO;
	else if (str.indexOf('x')>=0 || str.indexOf('X')>=0)
		seminfo.r = strx2number(str, seminfo);
	else {
		try {
			seminfo.r = LuaValue.valueOf(Double.parseDouble(str.trim()));
		} catch (NumberFormatException e) {
			lexerror("malformed number (" + e.getMessage() + ")", TK_NUMBER);
		}
	}
	return true;
}
 
Example 5
Source File: LexState.java    From VideoOS-Android-SDK with GNU General Public License v3.0 4 votes vote down vote up
LuaValue strx2number(String str, SemInfo seminfo) {
    char[] c = str.toCharArray();
    int s = 0;
    while (s < c.length && isspace(c[s]))
        ++s;
    // Check for negative sign
    double sgn = 1.0;
    if (s < c.length && c[s] == '-') {
        sgn = -1.0;
        ++s;
    }
    /* Check for "0x" */
    if (s + 2 >= c.length)
        return LuaValue.ZERO;
    if (c[s++] != '0')
        return LuaValue.ZERO;
    if (c[s] != 'x' && c[s] != 'X')
        return LuaValue.ZERO;
    ++s;

    // read integer part.
    double m = 0;
    int e = 0;
    while (s < c.length && isxdigit(c[s]))
        m = (m * 16) + hexvalue(c[s++]);
    if (s < c.length && c[s] == '.') {
        ++s;  // skip dot
        while (s < c.length && isxdigit(c[s])) {
            m = (m * 16) + hexvalue(c[s++]);
            e -= 4;  // Each fractional part shifts right by 2^4
        }
    }
    if (s < c.length && (c[s] == 'p' || c[s] == 'P')) {
        ++s;
        int exp1 = 0;
        boolean neg1 = false;
        if (s < c.length && c[s] == '-') {
            neg1 = true;
            ++s;
        }
        while (s < c.length && isdigit(c[s]))
            exp1 = exp1 * 10 + c[s++] - '0';
        if (neg1)
            exp1 = -exp1;
        e += exp1;
    }
    return LuaValue.valueOf(sgn * m * MathLib.dpow_d(2.0, e));
}
 
Example 6
Source File: LexState.java    From XPrivacyLua with GNU General Public License v3.0 4 votes vote down vote up
LuaValue strx2number(String str, SemInfo seminfo) {
	char[] c = str.toCharArray();
	int s = 0;
	while ( s < c.length && isspace(c[s]))
		++s;
	// Check for negative sign
	double sgn = 1.0;
	if (s < c.length && c[s] == '-') {
		sgn = -1.0;
		++s;
	}
	/* Check for "0x" */
	if (s + 2 >= c.length )
		return LuaValue.ZERO;
	if (c[s++] != '0')
		return LuaValue.ZERO;
	if (c[s] != 'x' && c[s] != 'X')
		return LuaValue.ZERO;
	++s;

	// read integer part.
	double m = 0;
	int e = 0;
	while (s < c.length && isxdigit(c[s]))
		m = (m * 16) + hexvalue(c[s++]);
	if (s < c.length && c[s] == '.') {
		++s;  // skip dot
		while (s < c.length && isxdigit(c[s])) {
			m = (m * 16) + hexvalue(c[s++]);
			e -= 4;  // Each fractional part shifts right by 2^4
		}
	}
	if (s < c.length && (c[s] == 'p' || c[s] == 'P')) {
		++s;
		int exp1 = 0;
		boolean neg1 = false;
		if (s < c.length && c[s] == '-') {
			neg1 = true;
			++s;
		}
		while (s < c.length && isdigit(c[s]))
			exp1 = exp1 * 10 + c[s++] - '0';
		if (neg1)
			exp1 = -exp1;
		e += exp1;
	}
	return LuaValue.valueOf(sgn * m * MathLib.dpow_d(2.0, e));
}
 
Example 7
Source File: LexState.java    From HtmlNative with Apache License 2.0 4 votes vote down vote up
LuaValue strx2number(String str, SemInfo seminfo) {
	char[] c = str.toCharArray();
	int s = 0;
	while ( s < c.length && isspace(c[s]))
		++s;
	// Check for negative sign
	double sgn = 1.0;
	if (s < c.length && c[s] == '-') {
		sgn = -1.0;
		++s;
	}
	/* Check for "0x" */
	if (s + 2 >= c.length )
		return LuaValue.ZERO;
	if (c[s++] != '0')
		return LuaValue.ZERO;
	if (c[s] != 'x' && c[s] != 'X')
		return LuaValue.ZERO;
	++s;

	// read integer part.
	double m = 0;
	int e = 0;
	while (s < c.length && isxdigit(c[s]))
		m = (m * 16) + hexvalue(c[s++]);
	if (s < c.length && c[s] == '.') {
		++s;  // skip dot
		while (s < c.length && isxdigit(c[s])) {
			m = (m * 16) + hexvalue(c[s++]);
			e -= 4;  // Each fractional part shifts right by 2^4
		}
	}
	if (s < c.length && (c[s] == 'p' || c[s] == 'P')) {
		++s;
		int exp1 = 0;
		boolean neg1 = false;
		if (s < c.length && c[s] == '-') {
			neg1 = true;
			++s;
		}
		while (s < c.length && isdigit(c[s]))
			exp1 = exp1 * 10 + c[s++] - '0';
		if (neg1)
			exp1 = -exp1;
		e += exp1;
	}
	return LuaValue.valueOf(sgn * m * MathLib.dpow_d(2.0, e));
}
 
Example 8
Source File: LexState.java    From luaj with MIT License 4 votes vote down vote up
LuaValue strx2number(String str, SemInfo seminfo) {
	char[] c = str.toCharArray();
	int s = 0;
	while ( s < c.length && isspace(c[s]))
		++s;
	// Check for negative sign
	double sgn = 1.0;
	if (s < c.length && c[s] == '-') {
		sgn = -1.0;
		++s;
	}
	/* Check for "0x" */
	if (s + 2 >= c.length )
		return LuaValue.ZERO;
	if (c[s++] != '0')
		return LuaValue.ZERO;
	if (c[s] != 'x' && c[s] != 'X')
		return LuaValue.ZERO;
	++s;

	// read integer part.
	double m = 0;
	int e = 0;
	while (s < c.length && isxdigit(c[s]))
		m = (m * 16) + hexvalue(c[s++]);
	if (s < c.length && c[s] == '.') {
		++s;  // skip dot
		while (s < c.length && isxdigit(c[s])) {
			m = (m * 16) + hexvalue(c[s++]);
			e -= 4;  // Each fractional part shifts right by 2^4
		}
	}
	if (s < c.length && (c[s] == 'p' || c[s] == 'P')) {
		++s;
		int exp1 = 0;
		boolean neg1 = false;
		if (s < c.length && c[s] == '-') {
			neg1 = true;
			++s;
		}
		while (s < c.length && isdigit(c[s]))
			exp1 = exp1 * 10 + c[s++] - '0';
		if (neg1)
			exp1 = -exp1;
		e += exp1;
	}
	return LuaValue.valueOf(sgn * m * MathLib.dpow_d(2.0, e));
}