Java Code Examples for org.luaj.vm2.LuaValue#toboolean()
The following examples show how to use
org.luaj.vm2.LuaValue#toboolean() .
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 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 2
Source File: CoerceLuaToJava.java From luaj with MIT License | 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 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 4
Source File: CoerceLuaToJava.java From HtmlNative with Apache License 2.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 5
Source File: PackageLib.java From HtmlNative with Apache License 2.0 | 5 votes |
public LuaValue call( LuaValue arg ) { LuaString name = arg.checkstring(); LuaValue loaded = package_.get(_LOADED); LuaValue result = loaded.get(name); if ( result.toboolean() ) { if ( result == _SENTINEL ) error("loop or previous error loading module '"+name+"'"); return result; } /* else must load it; iterate over available loaders */ LuaTable tbl = package_.get(_SEARCHERS).checktable(); StringBuffer sb = new StringBuffer(); Varargs loader = null; for ( int i=1; true; i++ ) { LuaValue searcher = tbl.get(i); if ( searcher.isnil() ) { error( "module '"+name+"' not found: "+name+sb ); } /* call loader with module name as argument */ loader = searcher.invoke(name); if ( loader.isfunction(1) ) break; if ( loader.isstring(1) ) sb.append( loader.tojstring(1) ); } // load the module using the loader loaded.set(name, _SENTINEL); result = loader.arg1().call(name, loader.arg(2)); if ( ! result.isnil() ) loaded.set( name, result ); else if ( (result = loaded.get(name)) == _SENTINEL ) loaded.set( name, result = LuaValue.TRUE ); return result; }
Example 6
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 7
Source File: PackageLib.java From luaj with MIT License | 5 votes |
public LuaValue call( LuaValue arg ) { LuaString name = arg.checkstring(); LuaValue loaded = package_.get(_LOADED); LuaValue result = loaded.get(name); if ( result.toboolean() ) { if ( result == _SENTINEL ) error("loop or previous error loading module '"+name+"'"); return result; } /* else must load it; iterate over available loaders */ LuaTable tbl = package_.get(_SEARCHERS).checktable(); StringBuffer sb = new StringBuffer(); Varargs loader = null; for ( int i=1; true; i++ ) { LuaValue searcher = tbl.get(i); if ( searcher.isnil() ) { error( "module '"+name+"' not found: "+name+sb ); } /* call loader with module name as argument */ loader = searcher.invoke(name); if ( loader.isfunction(1) ) break; if ( loader.isstring(1) ) sb.append( loader.tojstring(1) ); } // load the module using the loader loaded.set(name, _SENTINEL); result = loader.arg1().call(name, loader.arg(2)); if ( ! result.isnil() ) loaded.set( name, result ); else if ( (result = loaded.get(name)) == _SENTINEL ) loaded.set( name, result = LuaValue.TRUE ); return result; }
Example 8
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 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 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 11
Source File: PackageLib.java From XPrivacyLua with GNU General Public License v3.0 | 5 votes |
public LuaValue call( LuaValue arg ) { LuaString name = arg.checkstring(); LuaValue loaded = package_.get(_LOADED); LuaValue result = loaded.get(name); if ( result.toboolean() ) { if ( result == _SENTINEL ) error("loop or previous error loading module '"+name+"'"); return result; } /* else must load it; iterate over available loaders */ LuaTable tbl = package_.get(_SEARCHERS).checktable(); StringBuffer sb = new StringBuffer(); Varargs loader = null; for ( int i=1; true; i++ ) { LuaValue searcher = tbl.get(i); if ( searcher.isnil() ) { error( "module '"+name+"' not found: "+name+sb ); } /* call loader with module name as argument */ loader = searcher.invoke(name); if ( loader.isfunction(1) ) break; if ( loader.isstring(1) ) sb.append( loader.tojstring(1) ); } // load the module using the loader loaded.set(name, _SENTINEL); result = loader.arg1().call(name, loader.arg(2)); if ( ! result.isnil() ) loaded.set( name, result ); else if ( (result = loaded.get(name)) == _SENTINEL ) loaded.set( name, result = LuaValue.TRUE ); return result; }
Example 12
Source File: StringLib.java From VideoOS-Android-SDK 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 13
Source File: CoerceLuaToJava.java From HtmlNative with Apache License 2.0 | 4 votes |
public Object coerce(LuaValue value) { return value.toboolean()? Boolean.TRUE: Boolean.FALSE; }
Example 14
Source File: PackageLib.java From VideoOS-Android-SDK with GNU General Public License v3.0 | 4 votes |
public LuaValue call(LuaValue arg) { LuaString name = arg.checkstring(); LuaValue loaded = package_.get(_LOADED); LuaValue result = loaded.get(name); if (result.toboolean()) { if (result == _SENTINEL) error("loop or previous error loading module '" + name + "'"); return result; }/* else if (globals != null && (result = globals.lazyLoad(name.checkjstring())) != null){//TODO add by song, 如果是加载自定义的内容则使用globals加载 loaded.set(name, _SENTINEL); return result; }*/ /* else must load it; iterate over available loaders */ LuaTable tbl = package_.get(_SEARCHERS).checktable(); StringBuffer sb = new StringBuffer(); Varargs loader = null; for (int i = 1; true; i++) { LuaValue searcher = tbl.get(i); if (searcher.isnil()) { error("module '" + name + "' not found: " + name + sb); } /* call loader with module name as argument */ loader = searcher.invoke(name); if (loader.isfunction(1)) break; if (loader.isstring(1)) sb.append(loader.tojstring(1)); } // load the module using the loader loaded.set(name, _SENTINEL); try { result = loader.arg1().call(name, loader.arg(2)); if (!result.isnil()) loaded.set(name, result); else if ((result = loaded.get(name)) == _SENTINEL) loaded.set(name, result = LuaValue.TRUE); return result; } catch (Exception e) { return NIL; } }
Example 15
Source File: CoerceLuaToJava.java From XPrivacyLua with GNU General Public License v3.0 | 4 votes |
public Object coerce(LuaValue value) { return value.toboolean()? Boolean.TRUE: Boolean.FALSE; }
Example 16
Source File: CoerceLuaToJava.java From luaj with MIT License | 4 votes |
public Object coerce(LuaValue value) { return value.toboolean()? Boolean.TRUE: Boolean.FALSE; }
Example 17
Source File: CoerceLuaToJava.java From VideoOS-Android-SDK with GNU General Public License v3.0 | 4 votes |
public Object coerce(LuaValue value) { return value.toboolean() ? Boolean.TRUE : Boolean.FALSE; }