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

The following examples show how to use org.luaj.vm2.LuaString#copyInto() . 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
public Object coerce(LuaValue value) {
    if (value.isnil())
        return null;
    if (targetType == TARGET_TYPE_STRING)
        return value.tojstring();
    LuaString s = value.checkstring();
    byte[] b = new byte[s.m_length];
    s.copyInto(0, b, 0, b.length);
    return b;
}
 
Example 2
/**
 * 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 3
public Object coerce(LuaValue value) {
	if ( value.isnil() )
		return null;
	if ( targetType == TARGET_TYPE_STRING )
		return value.tojstring();
	LuaString s = value.checkstring();
	byte[] b = new byte[s.m_length];
	s.copyInto(0, b, 0, b.length);
	return b;
}
 
Example 4
public Varargs invoke(Varargs args) {
	LuaString s = args.checkstring( 1 );
	int n = args.checkint( 2 );
	final 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.valueUsing( bytes );
}
 
Example 5
Source Project: HtmlNative   File: CoerceLuaToJava.java    License: Apache License 2.0 5 votes vote down vote up
public Object coerce(LuaValue value) {
	if ( value.isnil() )
		return null;
	if ( targetType == TARGET_TYPE_STRING )
		return value.tojstring();
	LuaString s = value.checkstring();
	byte[] b = new byte[s.m_length];
	s.copyInto(0, b, 0, b.length);
	return b;
}
 
Example 6
Source Project: HtmlNative   File: StringLib.java    License: Apache License 2.0 5 votes vote down vote up
public Varargs invoke(Varargs args) {
	LuaString s = args.checkstring( 1 );
	int n = args.checkint( 2 );
	final 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.valueUsing( bytes );
}
 
Example 7
Source Project: luaj   File: CoerceLuaToJava.java    License: MIT License 5 votes vote down vote up
public Object coerce(LuaValue value) {
	if ( value.isnil() )
		return null;
	if ( targetType == TARGET_TYPE_STRING )
		return value.tojstring();
	LuaString s = value.checkstring();
	byte[] b = new byte[s.m_length];
	s.copyInto(0, b, 0, b.length);
	return b;
}
 
Example 8
Source Project: luaj   File: StringLib.java    License: MIT License 5 votes vote down vote up
public Varargs invoke(Varargs args) {
	LuaString s = args.checkstring( 1 );
	int n = args.checkint( 2 );
	final 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.valueUsing( bytes );
}