Java Code Examples for org.luaj.vm2.LuaValue#TSTRING
The following examples show how to use
org.luaj.vm2.LuaValue#TSTRING .
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: CoerceLuaToJava.java From VideoOS-Android-SDK with GNU General Public License v3.0 | 6 votes |
public int score(LuaValue value) { switch (value.type()) { case LuaValue.TNUMBER: return inheritanceLevels(targetType, value.isint() ? Integer.class : Double.class); case LuaValue.TBOOLEAN: return inheritanceLevels(targetType, Boolean.class); case LuaValue.TSTRING: return inheritanceLevels(targetType, String.class); case LuaValue.TUSERDATA: return inheritanceLevels(targetType, value.touserdata().getClass()); case LuaValue.TNIL: return SCORE_NULL_VALUE; default: return inheritanceLevels(targetType, value.getClass()); } }
Example 2
Source File: CoerceLuaToJava.java From VideoOS-Android-SDK with GNU General Public License v3.0 | 6 votes |
public Object coerce(LuaValue value) { switch (value.type()) { case LuaValue.TNUMBER: return value.isint() ? (Object) new Integer(value.toint()) : (Object) new Double(value.todouble()); case LuaValue.TBOOLEAN: return value.toboolean() ? Boolean.TRUE : Boolean.FALSE; case LuaValue.TSTRING: return value.tojstring(); case LuaValue.TUSERDATA: return value.optuserdata(targetType, null); case LuaValue.TNIL: return null; default: return value; } }
Example 3
Source File: CoerceLuaToJava.java From HtmlNative with Apache License 2.0 | 6 votes |
public int score(LuaValue value) { switch ( value.type() ) { case LuaValue.TNUMBER: return inheritanceLevels( targetType, value.isint()? Integer.class: Double.class ); case LuaValue.TBOOLEAN: return inheritanceLevels( targetType, Boolean.class ); case LuaValue.TSTRING: return inheritanceLevels( targetType, String.class ); case LuaValue.TUSERDATA: return inheritanceLevels( targetType, value.touserdata().getClass() ); case LuaValue.TNIL: return SCORE_NULL_VALUE; default: return inheritanceLevels( targetType, value.getClass() ); } }
Example 4
Source File: LuaUtil.java From VideoOS-Android-SDK with GNU General Public License v3.0 | 6 votes |
/** * parse a value to given type * * @param type * @param value * @return */ static Object parseValue(int type, LuaValue value) { switch (type) { case LuaValue.TBOOLEAN: if (isBoolean(value)) return value.checkboolean(); break; case LuaValue.TNUMBER: if (isNumber(value)) return value.checknumber(); break; case LuaValue.TSTRING: if (isString(value)) return value.checkjstring(); break; case LuaValue.TTABLE: if (isTable(value)) return value.checktable(); break; case LuaValue.TFUNCTION: if (isFunction(value)) return value.checkfunction(); break; case LuaValue.TUSERDATA: if (isUserdata(value)) return value.checkuserdata(); break; case LuaValue.TVALUE: return value; } return null; }
Example 5
Source File: CoerceLuaToJava.java From luaj with MIT License | 6 votes |
public int score(LuaValue value) { switch ( value.type() ) { case LuaValue.TNUMBER: return inheritanceLevels( targetType, value.isint()? Integer.class: Double.class ); case LuaValue.TBOOLEAN: return inheritanceLevels( targetType, Boolean.class ); case LuaValue.TSTRING: return inheritanceLevels( targetType, String.class ); case LuaValue.TUSERDATA: return inheritanceLevels( targetType, value.touserdata().getClass() ); case LuaValue.TNIL: return SCORE_NULL_VALUE; default: return inheritanceLevels( targetType, value.getClass() ); } }
Example 6
Source File: CoerceLuaToJava.java From XPrivacyLua with GNU General Public License v3.0 | 6 votes |
public int score(LuaValue value) { switch ( value.type() ) { case LuaValue.TNUMBER: return inheritanceLevels( targetType, value.isint()? Integer.class: Double.class ); case LuaValue.TBOOLEAN: return inheritanceLevels( targetType, Boolean.class ); case LuaValue.TSTRING: return inheritanceLevels( targetType, String.class ); case LuaValue.TUSERDATA: return inheritanceLevels( targetType, value.touserdata().getClass() ); case LuaValue.TNIL: return SCORE_NULL_VALUE; default: return inheritanceLevels( targetType, value.getClass() ); } }
Example 7
Source File: CoerceLuaToJava.java From XPrivacyLua with GNU General Public License v3.0 | 6 votes |
public Object coerce(LuaValue value) { switch ( value.type() ) { case LuaValue.TNUMBER: return value.isint()? (Object)new Integer(value.toint()): (Object)new Double(value.todouble()); case LuaValue.TBOOLEAN: return value.toboolean()? Boolean.TRUE: Boolean.FALSE; case LuaValue.TSTRING: return value.tojstring(); case LuaValue.TUSERDATA: return value.optuserdata(targetType, null); case LuaValue.TNIL: return null; default: return value; } }
Example 8
Source File: CoerceLuaToJava.java From XPrivacyLua with GNU General Public License v3.0 | 5 votes |
public int score(LuaValue value) { switch ( value.type() ) { case LuaValue.TSTRING: return value.checkstring().isValidUtf8()? (targetType==TARGET_TYPE_STRING? 0: 1): (targetType==TARGET_TYPE_BYTES? 0: SCORE_WRONG_TYPE); case LuaValue.TNIL: return SCORE_NULL_VALUE; default: return targetType == TARGET_TYPE_STRING? SCORE_WRONG_TYPE: SCORE_UNCOERCIBLE; } }
Example 9
Source File: StringLib.java From HtmlNative with Apache License 2.0 | 5 votes |
public void add_value( Buffer lbuf, int soffset, int end, LuaValue repl ) { switch ( repl.type() ) { case LuaValue.TSTRING: case LuaValue.TNUMBER: add_s( lbuf, repl.strvalue(), soffset, end ); return; case LuaValue.TFUNCTION: repl = repl.invoke( push_captures( true, soffset, end ) ).arg1(); break; case LuaValue.TTABLE: // Need to call push_onecapture here for the error checking repl = repl.get( push_onecapture( 0, soffset, end ) ); break; default: error( "bad argument: string/function/table expected" ); return; } if ( !repl.toboolean() ) { repl = s.substring( soffset, end ); } else if ( ! repl.isstring() ) { error( "invalid replacement value (a "+repl.typename()+")" ); } lbuf.append( repl.strvalue() ); }
Example 10
Source File: StringLib.java From luaj with MIT License | 5 votes |
public void add_value( Buffer lbuf, int soffset, int end, LuaValue repl ) { switch ( repl.type() ) { case LuaValue.TSTRING: case LuaValue.TNUMBER: add_s( lbuf, repl.strvalue(), soffset, end ); return; case LuaValue.TFUNCTION: repl = repl.invoke( push_captures( true, soffset, end ) ).arg1(); break; case LuaValue.TTABLE: // Need to call push_onecapture here for the error checking repl = repl.get( push_onecapture( 0, soffset, end ) ); break; default: error( "bad argument: string/function/table expected" ); return; } if ( !repl.toboolean() ) { repl = s.substring( soffset, end ); } else if ( ! repl.isstring() ) { error( "invalid replacement value (a "+repl.typename()+")" ); } lbuf.append( repl.strvalue() ); }
Example 11
Source File: CoerceLuaToJava.java From HtmlNative with Apache License 2.0 | 5 votes |
public int score(LuaValue value) { switch ( value.type() ) { case LuaValue.TSTRING: return value.checkstring().isValidUtf8()? (targetType==TARGET_TYPE_STRING? 0: 1): (targetType==TARGET_TYPE_BYTES? 0: SCORE_WRONG_TYPE); case LuaValue.TNIL: return SCORE_NULL_VALUE; default: return targetType == TARGET_TYPE_STRING? SCORE_WRONG_TYPE: SCORE_UNCOERCIBLE; } }
Example 12
Source File: IoLib.java From HtmlNative with Apache License 2.0 | 5 votes |
private Varargs ioread(File f, Varargs args) throws IOException { int i,n=args.narg(); LuaValue[] v = new LuaValue[n]; LuaValue ai,vi; LuaString fmt; for ( i=0; i<n; ) { item: switch ( (ai = args.arg(i+1)).type() ) { case LuaValue.TNUMBER: vi = freadbytes(f,ai.toint()); break item; case LuaValue.TSTRING: fmt = ai.checkstring(); if ( fmt.m_length == 2 && fmt.m_bytes[fmt.m_offset] == '*' ) { switch ( fmt.m_bytes[fmt.m_offset+1] ) { case 'n': vi = freadnumber(f); break item; case 'l': vi = freadline(f); break item; case 'a': vi = freadall(f); break item; } } default: return argerror( i+1, "(invalid format)" ); } if ( (v[i++] = vi).isnil() ) break; } return i==0? NIL: varargsOf(v, 0, i); }
Example 13
Source File: StringLib.java From XPrivacyLua with GNU General Public License v3.0 | 5 votes |
public void add_value( Buffer lbuf, int soffset, int end, LuaValue repl ) { switch ( repl.type() ) { case LuaValue.TSTRING: case LuaValue.TNUMBER: add_s( lbuf, repl.strvalue(), soffset, end ); return; case LuaValue.TFUNCTION: repl = repl.invoke( push_captures( true, soffset, end ) ).arg1(); break; case LuaValue.TTABLE: // Need to call push_onecapture here for the error checking repl = repl.get( push_onecapture( 0, soffset, end ) ); break; default: error( "bad argument: string/function/table expected" ); return; } if ( !repl.toboolean() ) { repl = s.substring( soffset, end ); } else if ( ! repl.isstring() ) { error( "invalid replacement value (a "+repl.typename()+")" ); } lbuf.append( repl.strvalue() ); }
Example 14
Source File: LuaPrint.java From VideoOS-Android-SDK with GNU General Public License v3.0 | 5 votes |
void buildValue(StringBuffer ps, LuaValue v) { switch (v.type()) { case LuaValue.TSTRING: buildString(ps, (LuaString) v); break; default: ps.append(v.tojstring()); } }
Example 15
Source File: IoLib.java From XPrivacyLua with GNU General Public License v3.0 | 5 votes |
private Varargs ioread(File f, Varargs args) throws IOException { int i,n=args.narg(); LuaValue[] v = new LuaValue[n]; LuaValue ai,vi; LuaString fmt; for ( i=0; i<n; ) { item: switch ( (ai = args.arg(i+1)).type() ) { case LuaValue.TNUMBER: vi = freadbytes(f,ai.toint()); break item; case LuaValue.TSTRING: fmt = ai.checkstring(); if ( fmt.m_length == 2 && fmt.m_bytes[fmt.m_offset] == '*' ) { switch ( fmt.m_bytes[fmt.m_offset+1] ) { case 'n': vi = freadnumber(f); break item; case 'l': vi = freadline(f); break item; case 'a': vi = freadall(f); break item; } } default: return argerror( i+1, "(invalid format)" ); } if ( (v[i++] = vi).isnil() ) break; } return i==0? NIL: varargsOf(v, 0, i); }
Example 16
Source File: CoerceLuaToJava.java From luaj with MIT License | 5 votes |
public int score(LuaValue value) { switch ( value.type() ) { case LuaValue.TSTRING: return value.checkstring().isValidUtf8()? (targetType==TARGET_TYPE_STRING? 0: 1): (targetType==TARGET_TYPE_BYTES? 0: SCORE_WRONG_TYPE); case LuaValue.TNIL: return SCORE_NULL_VALUE; default: return targetType == TARGET_TYPE_STRING? SCORE_WRONG_TYPE: SCORE_UNCOERCIBLE; } }
Example 17
Source File: DefaultLauncher.java From luaj with MIT License | 5 votes |
private Object[] launchChunk(LuaValue chunk, Object[] arg) { LuaValue args[] = new LuaValue[arg.length]; for (int i = 0; i < args.length; ++i) args[i] = CoerceJavaToLua.coerce(arg[i]); Varargs results = chunk.invoke(LuaValue.varargsOf(args)); final int n = results.narg(); Object return_values[] = new Object[n]; for (int i = 0; i < n; ++i) { LuaValue r = results.arg(i+1); switch (r.type()) { case LuaValue.TBOOLEAN: return_values[i] = r.toboolean(); break; case LuaValue.TNUMBER: return_values[i] = r.todouble(); break; case LuaValue.TINT: return_values[i] = r.toint(); break; case LuaValue.TNIL: return_values[i] = null; break; case LuaValue.TSTRING: return_values[i] = r.tojstring(); break; case LuaValue.TUSERDATA: return_values[i] = r.touserdata(); break; default: return_values[i] = r; } } return return_values; }
Example 18
Source File: CoerceLuaToJava.java From VideoOS-Android-SDK with GNU General Public License v3.0 | 5 votes |
public int score(LuaValue value) { switch (value.type()) { case LuaValue.TSTRING: return value.checkstring().isValidUtf8() ? (targetType == TARGET_TYPE_STRING ? 0 : 1) : (targetType == TARGET_TYPE_BYTES ? 0 : SCORE_WRONG_TYPE); case LuaValue.TNIL: return SCORE_NULL_VALUE; default: return targetType == TARGET_TYPE_STRING ? SCORE_WRONG_TYPE : SCORE_UNCOERCIBLE; } }
Example 19
Source File: IoLib.java From luaj with MIT License | 5 votes |
private Varargs ioread(File f, Varargs args) throws IOException { int i,n=args.narg(); if (n == 0) return freadline(f,false); LuaValue[] v = new LuaValue[n]; LuaValue ai,vi; LuaString fmt; for ( i=0; i<n; ) { item: switch ( (ai = args.arg(i+1)).type() ) { case LuaValue.TNUMBER: vi = freadbytes(f,ai.toint()); break item; case LuaValue.TSTRING: fmt = ai.checkstring(); if ( fmt.m_length >= 2 && fmt.m_bytes[fmt.m_offset] == '*' ) { switch ( fmt.m_bytes[fmt.m_offset+1] ) { case 'n': vi = freadnumber(f); break item; case 'l': vi = freadline(f,false); break item; case 'L': vi = freadline(f,true); break item; case 'a': vi = freadall(f); break item; } } default: return argerror( i+1, "(invalid format)" ); } if ( (v[i++] = vi).isnil() ) break; } return i==0? NIL: varargsOf(v, 0, i); }
Example 20
Source File: LuaUtil.java From VideoOS-Android-SDK with GNU General Public License v3.0 | 2 votes |
/** * is string * * @param target * @return */ public static boolean isString(LuaValue target) { return target != null && target.type() == LuaValue.TSTRING; }