Java Code Examples for org.luaj.vm2.LuaString#valueOf()

The following examples show how to use org.luaj.vm2.LuaString#valueOf() . 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: RedisBinding.java    From claudb with MIT License 5 votes vote down vote up
private LuaValue toLuaString(UnknownRedisToken value) {
  SafeString string = value.getValue();
  if (string == null) {
    return LuaValue.NIL;
  }
  return LuaString.valueOf(string.getBytes());
}
 
Example 2
Source File: StringLib.java    From VideoOS-Android-SDK with GNU General Public License v3.0 5 votes vote down vote up
/**
 * string.dump (function)
 * <p>
 * Returns a string containing a binary representation of the given function,
 * so that a later loadstring on this string returns a copy of the function.
 * function must be a Lua function without upvalues.
 * <p>
 * TODO: port dumping code as optional add-on
 */
static LuaValue dump(LuaValue arg) {
    LuaValue f = arg.checkfunction();
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    try {
        DumpState.dump(((LuaClosure) f).p, baos, true);
        return LuaString.valueOf(baos.toByteArray());
    } catch (IOException e) {
        return error(e.getMessage());
    }
}
 
Example 3
Source File: StringLib.java    From VideoOS-Android-SDK with GNU General Public License v3.0 5 votes vote down vote up
/**
 * string.rep (s, n)
 * <p>
 * Returns a string that is the concatenation of n copies of the string s.
 */
static Varargs rep(Varargs args) {
    LuaString s = args.checkstring(1);
    int n = args.checkint(2);
     byte[] bytes = new byte[s.length() * n];
    int len = s.length();
    for (int offset = 0; offset < bytes.length; offset += len) {
        s.copyInto(0, bytes, offset, len);
    }
    return LuaString.valueOf(bytes);
}
 
Example 4
Source File: StringLib.java    From VideoOS-Android-SDK with GNU General Public License v3.0 5 votes vote down vote up
/**
 * string.reverse (s)
 * <p>
 * Returns a string that is the string s reversed.
 */
static LuaValue reverse(LuaValue arg) {
    LuaString s = arg.checkstring();
    int n = s.length();
    byte[] b = new byte[n];
    for (int i = 0, j = n - 1; i < n; i++, j--)
        b[j] = (byte) s.luaByte(i);
    return LuaString.valueOf(b);
}
 
Example 5
Source File: LexState.java    From VideoOS-Android-SDK with GNU General Public License v3.0 5 votes vote down vote up
void gotostat(int pc) {
    int line = linenumber;
    LuaString label;
    int g;
    if (testnext(TK_GOTO))
        label = str_checkname();
    else {
        next();  /* skip break */
        label = LuaString.valueOf("break");
    }
    g = newlabelentry(dyd.gt = LuaC.grow(dyd.gt, dyd.n_gt + 1), dyd.n_gt++, label, line, pc);
    findlabel(g);  /* close it if label already defined */
}
 
Example 6
Source File: DebugLib.java    From XPrivacyLua with GNU General Public License v3.0 5 votes vote down vote up
static LuaString findupvalue(LuaClosure c, int up) {
	if ( c.upValues != null && up > 0 && up <= c.upValues.length ) {
		if ( c.p.upvalues != null && up <= c.p.upvalues.length )
			return c.p.upvalues[up-1].name;
		else
			return LuaString.valueOf( "."+up );
	}
	return null;
}
 
Example 7
Source File: LexState.java    From luaj with MIT License 5 votes vote down vote up
void gotostat(int pc) {
	int line = linenumber;
	LuaString label;
	int g;
	if (testnext(TK_GOTO))
		label = str_checkname();
	else {
		next();  /* skip break */
		label = LuaString.valueOf("break");
	}
	g = newlabelentry(dyd.gt =grow(dyd.gt, dyd.n_gt+1), dyd.n_gt++, label, line, pc);
	findlabel(g);  /* close it if label already defined */
}
 
Example 8
Source File: LexState.java    From XPrivacyLua with GNU General Public License v3.0 5 votes vote down vote up
void gotostat(int pc) {
	int line = linenumber;
	LuaString label;
	int g;
	if (testnext(TK_GOTO))
		label = str_checkname();
	else {
		next();  /* skip break */
		label = LuaString.valueOf("break");
	}
	g = newlabelentry(dyd.gt =grow(dyd.gt, dyd.n_gt+1), dyd.n_gt++, label, line, pc);
	findlabel(g);  /* close it if label already defined */
}
 
Example 9
Source File: DebugLib.java    From HtmlNative with Apache License 2.0 5 votes vote down vote up
static LuaString findupvalue(LuaClosure c, int up) {
	if ( c.upValues != null && up > 0 && up <= c.upValues.length ) {
		if ( c.p.upvalues != null && up <= c.p.upvalues.length )
			return c.p.upvalues[up-1].name;
		else
			return LuaString.valueOf( "."+up );
	}
	return null;
}
 
Example 10
Source File: RedisBinding.java    From claudb with MIT License 5 votes vote down vote up
private LuaValue toLuaString(StatusRedisToken value) {
  String string = value.getValue();
  if (string == null) {
    return LuaValue.NIL;
  }
  return LuaString.valueOf(string);
}
 
Example 11
Source File: Str.java    From VideoOS-Android-SDK with GNU General Public License v3.0 4 votes vote down vote up
public static LuaString quoteString(String image) {
	String s = image.substring(1, image.length()-1);
	byte[] bytes = unquote(s);
	return LuaString.valueOf(bytes);
}
 
Example 12
Source File: Str.java    From VideoOS-Android-SDK with GNU General Public License v3.0 4 votes vote down vote up
public static LuaString charString(String image) {
	String s = image.substring(1, image.length()-1);
	byte[] bytes = unquote(s);
	return LuaString.valueOf(bytes);
}
 
Example 13
Source File: Str.java    From VideoOS-Android-SDK with GNU General Public License v3.0 4 votes vote down vote up
public static LuaString longString(String image) {
	int i = image.indexOf('[', image.indexOf('[')+1)+1;
	String s = image.substring(i,image.length()-i);
	byte[] b = iso88591bytes(s);
	return LuaString.valueOf(b);
}
 
Example 14
Source File: CoerceJavaToLua.java    From VideoOS-Android-SDK with GNU General Public License v3.0 4 votes vote down vote up
public LuaValue coerce(Object javaValue) {
    return LuaString.valueOf(javaValue.toString());
}
 
Example 15
Source File: LexState.java    From VideoOS-Android-SDK with GNU General Public License v3.0 4 votes vote down vote up
void breaklabel() {
    LuaString n = LuaString.valueOf("break");
    int l = newlabelentry(dyd.label = LuaC.grow(dyd.label, dyd.n_label + 1), dyd.n_label++, n, 0, fs.pc);
    findgotos(dyd.label[l]);
}
 
Example 16
Source File: CoerceJavaToLua.java    From XPrivacyLua with GNU General Public License v3.0 4 votes vote down vote up
public LuaValue coerce( Object javaValue ) {
	return LuaString.valueOf( javaValue.toString() );
}
 
Example 17
Source File: CoerceJavaToLua.java    From HtmlNative with Apache License 2.0 4 votes vote down vote up
public LuaValue coerce( Object javaValue ) {
	return LuaString.valueOf( javaValue.toString() );
}
 
Example 18
Source File: LexState.java    From HtmlNative with Apache License 2.0 4 votes vote down vote up
void breaklabel () {
	LuaString n = LuaString.valueOf("break");
	int l = newlabelentry(dyd.label=grow(dyd.label, dyd.n_label+1), dyd.n_label++, n, 0, fs.pc);
	findgotos(dyd.label[l]);
}
 
Example 19
Source File: LexState.java    From luaj with MIT License 4 votes vote down vote up
void breaklabel () {
	LuaString n = LuaString.valueOf("break");
	int l = newlabelentry(dyd.label=grow(dyd.label, dyd.n_label+1), dyd.n_label++, n, 0, fs.pc);
	findgotos(dyd.label[l]);
}
 
Example 20
Source File: StringLib.java    From VideoOS-Android-SDK with GNU General Public License v3.0 3 votes vote down vote up
/**
 * string.char (...)
 * <p>
 * Receives zero or more integers. Returns a string with length equal
 * to the number of arguments, in which each character has the internal
 * numerical code equal to its corresponding argument.
 * <p>
 * Note that numerical codes are not necessarily portable across platforms.
 *
 * @param args the calling VM
 */
public static Varargs char_(Varargs args) {
    int n = args.narg();
    byte[] bytes = new byte[n];
    for (int i = 0, a = 1; i < n; i++, a++) {
        int c = args.checkint(a);
        if (c < 0 || c >= 256) argerror(a, "invalid value");
        bytes[i] = (byte) c;
    }
    return LuaString.valueOf(bytes);
}