本文整理匯總了Java中org.luaj.vm2.LuaValue.toboolean方法的典型用法代碼示例。如果您正苦於以下問題:Java LuaValue.toboolean方法的具體用法?Java LuaValue.toboolean怎麽用?Java LuaValue.toboolean使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.luaj.vm2.LuaValue
的用法示例。
在下文中一共展示了LuaValue.toboolean方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: coerce
import org.luaj.vm2.LuaValue; //導入方法依賴的package包/類
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;
}
}
示例2: add_value
import org.luaj.vm2.LuaValue; //導入方法依賴的package包/類
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());
}
示例3: call
import org.luaj.vm2.LuaValue; //導入方法依賴的package包/類
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;
}
示例4: add_value
import org.luaj.vm2.LuaValue; //導入方法依賴的package包/類
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() );
}
示例5: call
import org.luaj.vm2.LuaValue; //導入方法依賴的package包/類
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){
LogUtil.e("[PackageLib]", name, "load failed!", e);
return NIL;
}
}