Examples of LuaString


Examples of org.luaj.vm2.LuaString

   * string.rep (s, n)
   *
   * 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 );
    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.valueOf( bytes );
  }
View Full Code Here

Examples of org.luaj.vm2.LuaString

   * string.reverse (s)
   *
   * 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 );
  }
View Full Code Here

Examples of org.luaj.vm2.LuaString

   * returns a prefix of s with length j, and
   *   string.sub(s, -i)
   * returns a suffix of s with length i.
   */
  static Varargs sub( Varargs args ) {
    final LuaString s = args.checkstring( 1 );
    final int l = s.length();
   
    int start = posrelat( args.checkint( 2 ), l );
    int end = posrelat( args.optint( 3, -1 ), l );
   
    if ( start < 1 )
      start = 1;
    if ( end > l )
      end = l;
   
    if ( start <= end ) {
      return s.substring( start-1 , end );
    } else {
      return EMPTYSTRING;
    }
  }
View Full Code Here

Examples of org.luaj.vm2.LuaString

 
  /**
   * This utility method implements both string.find and string.match.
   */
  static Varargs str_find_aux( Varargs args, boolean find ) {
    LuaString s = args.checkstring( 1 );
    LuaString pat = args.checkstring( 2 );
    int init = args.optint( 3, 1 );
   
    if ( init > 0 ) {
      init = Math.min( init - 1, s.length() );
    } else if ( init < 0 ) {
      init = Math.max( 0, s.length() + init );
    }
   
    boolean fastMatch = find && ( args.arg(4).toboolean() || pat.indexOfAny( SPECIALS ) == -1 );
   
    if ( fastMatch ) {
      int result = s.indexOf( pat, init );
      if ( result != -1 ) {
        return varargsOf( valueOf(result+1), valueOf(result+pat.length()) );
      }
    } else {
      MatchState ms = new MatchState( args, s, pat );
     
      boolean anchor = false;
      int poff = 0;
      if ( pat.luaByte( 0 ) == '^' ) {
        anchor = true;
        poff = 1;
      }
     
      int soff = init;
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.