Java Code Examples for org.luaj.vm2.LuaString#valueUsing()
The following examples show how to use
org.luaj.vm2.LuaString#valueUsing() .
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: IoLib.java From HtmlNative with Apache License 2.0 | 6 votes |
public static LuaValue freaduntil(File f,boolean lineonly) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); int c; try { if ( lineonly ) { loop: while ( (c = f.read()) > 0 ) { switch ( c ) { case '\r': break; case '\n': break loop; default: baos.write(c); break; } } } else { while ( (c = f.read()) > 0 ) baos.write(c); } } catch ( EOFException e ) { c = -1; } return ( c < 0 && baos.size() == 0 )? (LuaValue) NIL: (LuaValue) LuaString.valueUsing(baos.toByteArray()); }
Example 2
Source File: IoLib.java From luaj with MIT License | 6 votes |
public static LuaValue freaduntil(File f,boolean lineonly,boolean withend) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); int c; try { if ( lineonly ) { loop: while ( (c = f.read()) >= 0 ) { switch ( c ) { case '\r': if (withend) baos.write(c); break; case '\n': if (withend) baos.write(c); break loop; default: baos.write(c); break; } } } else { while ( (c = f.read()) >= 0 ) baos.write(c); } } catch ( EOFException e ) { c = -1; } return ( c < 0 && baos.size() == 0 )? (LuaValue) NIL: (LuaValue) LuaString.valueUsing(baos.toByteArray()); }
Example 3
Source File: IoLib.java From XPrivacyLua with GNU General Public License v3.0 | 6 votes |
public static LuaValue freaduntil(File f,boolean lineonly) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); int c; try { if ( lineonly ) { loop: while ( (c = f.read()) > 0 ) { switch ( c ) { case '\r': break; case '\n': break loop; default: baos.write(c); break; } } } else { while ( (c = f.read()) > 0 ) baos.write(c); } } catch ( EOFException e ) { c = -1; } return ( c < 0 && baos.size() == 0 )? (LuaValue) NIL: (LuaValue) LuaString.valueUsing(baos.toByteArray()); }
Example 4
Source File: StringLib.java From HtmlNative with Apache License 2.0 | 5 votes |
public Varargs invoke(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.valueUsing( bytes ); }
Example 5
Source File: IoLib.java From luaj with MIT License | 5 votes |
public static LuaValue freadbytes(File f, int count) throws IOException { if (count == 0) return f.eof() ? NIL : EMPTYSTRING; byte[] b = new byte[count]; int r; if ( ( r = f.read(b,0,b.length) ) < 0 ) return NIL; return LuaString.valueUsing(b, 0, r); }
Example 6
Source File: StringLib.java From luaj with MIT License | 5 votes |
public Varargs invoke(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 for string.char [0; 255]: " + c); bytes[i] = (byte) c; } return LuaString.valueUsing( bytes ); }
Example 7
Source File: StringLib.java From HtmlNative with Apache License 2.0 | 5 votes |
public LuaValue call(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.valueUsing( b ); }
Example 8
Source File: StringLib.java From HtmlNative with Apache License 2.0 | 5 votes |
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 9
Source File: StringLib.java From HtmlNative with Apache License 2.0 | 5 votes |
public LuaValue call(LuaValue arg) { LuaValue f = arg.checkfunction(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { DumpState.dump( ((LuaClosure)f).p, baos, true ); return LuaString.valueUsing(baos.toByteArray()); } catch (IOException e) { return error( e.getMessage() ); } }
Example 10
Source File: StringLib.java From XPrivacyLua with GNU General Public License v3.0 | 5 votes |
public Varargs invoke(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.valueUsing( bytes ); }
Example 11
Source File: IoLib.java From XPrivacyLua with GNU General Public License v3.0 | 5 votes |
public static LuaValue freadbytes(File f, int count) throws IOException { byte[] b = new byte[count]; int r; if ( ( r = f.read(b,0,b.length) ) < 0 ) return NIL; return LuaString.valueUsing(b, 0, r); }
Example 12
Source File: IoLib.java From HtmlNative with Apache License 2.0 | 5 votes |
public static LuaValue freadbytes(File f, int count) throws IOException { byte[] b = new byte[count]; int r; if ( ( r = f.read(b,0,b.length) ) < 0 ) return NIL; return LuaString.valueUsing(b, 0, r); }
Example 13
Source File: StringLib.java From luaj with MIT License | 5 votes |
public Varargs invoke(Varargs args) { LuaValue f = args.checkfunction(1); ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { DumpState.dump( ((LuaClosure)f).p, baos, args.optboolean(2, true) ); return LuaString.valueUsing(baos.toByteArray()); } catch (IOException e) { return error( e.getMessage() ); } }
Example 14
Source File: StringLib.java From XPrivacyLua with GNU General Public License v3.0 | 5 votes |
public LuaValue call(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.valueUsing( b ); }
Example 15
Source File: StringLib.java From luaj with MIT License | 5 votes |
public LuaValue call(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.valueUsing( b ); }
Example 16
Source File: StringLib.java From XPrivacyLua with GNU General Public License v3.0 | 5 votes |
public LuaValue call(LuaValue arg) { LuaValue f = arg.checkfunction(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { DumpState.dump( ((LuaClosure)f).p, baos, true ); return LuaString.valueUsing(baos.toByteArray()); } catch (IOException e) { return error( e.getMessage() ); } }
Example 17
Source File: Str.java From HtmlNative with Apache License 2.0 | 4 votes |
public static LuaString charString(String image) { String s = image.substring(1, image.length()-1); byte[] bytes = unquote(s); return LuaString.valueUsing(bytes); }
Example 18
Source File: Str.java From HtmlNative with Apache License 2.0 | 4 votes |
public static LuaString quoteString(String image) { String s = image.substring(1, image.length()-1); byte[] bytes = unquote(s); return LuaString.valueUsing(bytes); }
Example 19
Source File: Str.java From luaj with MIT License | 4 votes |
public static LuaString quoteString(String image) { String s = image.substring(1, image.length()-1); byte[] bytes = unquote(s); return LuaString.valueUsing(bytes); }
Example 20
Source File: Str.java From luaj with MIT License | 4 votes |
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.valueUsing(b); }