Java Code Examples for org.luaj.vm2.LuaValue#get()

The following examples show how to use org.luaj.vm2.LuaValue#get() . 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: JseMathLib.java    From XPrivacyLua with GNU General Public License v3.0 6 votes vote down vote up
/** Perform one-time initialization on the library by creating a table
 * containing the library functions, adding that table to the supplied environment,
 * adding the table to package.loaded, and returning table as the return value.
 * <P>Specifically, adds all library functions that can be implemented directly
 * in JSE but not JME: acos, asin, atan, atan2, cosh, exp, log, pow, sinh, and tanh.
 * @param modname the module name supplied if this is loaded via 'require'.
 * @param env the environment to load into, which must be a Globals instance.
 */
public LuaValue call(LuaValue modname, LuaValue env) {
	super.call(modname, env);
	LuaValue math = env.get("math");
	math.set("acos", new acos());
	math.set("asin", new asin());
	math.set("atan", new atan());
	math.set("atan2", new atan2());
	math.set("cosh", new cosh());
	math.set("exp", new exp());
	math.set("log", new log());
	math.set("pow", new pow());
	math.set("sinh", new sinh());
	math.set("tanh", new tanh());
	return math;
}
 
Example 2
Source File: JseMathLib.java    From HtmlNative with Apache License 2.0 6 votes vote down vote up
/** Perform one-time initialization on the library by creating a table
 * containing the library functions, adding that table to the supplied environment,
 * adding the table to package.loaded, and returning table as the return value.
 * <P>Specifically, adds all library functions that can be implemented directly
 * in JSE but not JME: acos, asin, atan, atan2, cosh, exp, log, pow, sinh, and tanh.
 * @param modname the module name supplied if this is loaded via 'require'.
 * @param env the environment to load into, which must be a Globals instance.
 */
public LuaValue call(LuaValue modname, LuaValue env) {
	super.call(modname, env);
	LuaValue math = env.get("math");
	math.set("acos", new acos());
	math.set("asin", new asin());
	math.set("atan", new atan());
	math.set("atan2", new atan2());
	math.set("cosh", new cosh());
	math.set("exp", new exp());
	math.set("log", new log());
	math.set("pow", new pow());
	math.set("sinh", new sinh());
	math.set("tanh", new tanh());
	return math;
}
 
Example 3
Source File: JseMathLib.java    From luaj with MIT License 6 votes vote down vote up
/** Perform one-time initialization on the library by creating a table
 * containing the library functions, adding that table to the supplied environment,
 * adding the table to package.loaded, and returning table as the return value.
 * <P>Specifically, adds all library functions that can be implemented directly
 * in JSE but not JME: acos, asin, atan, atan2, cosh, exp, log, pow, sinh, and tanh.
 * @param modname the module name supplied if this is loaded via 'require'.
 * @param env the environment to load into, which must be a Globals instance.
 */
public LuaValue call(LuaValue modname, LuaValue env) {
	super.call(modname, env);
	LuaValue math = env.get("math");
	math.set("acos", new acos());
	math.set("asin", new asin());
	LuaValue atan =  new atan2();
	math.set("atan", atan);
	math.set("atan2", atan);
	math.set("cosh", new cosh());
	math.set("exp", new exp());
	math.set("log", new log());
	math.set("pow", new pow());
	math.set("sinh", new sinh());
	math.set("tanh", new tanh());
	return math;
}
 
Example 4
Source File: JseMathLib.java    From VideoOS-Android-SDK with GNU General Public License v3.0 5 votes vote down vote up
public LuaValue call(LuaValue modname, LuaValue env) {
    super.call(modname, env);
    LuaValue math = env.get("math");
    math.set("acos", new acos());
    math.set("asin", new asin());
    math.set("atan", new atan());
    math.set("atan2", new atan2());
    math.set("cosh", new cosh());
    math.set("exp", new exp());
    math.set("log", new log());
    math.set("pow", new pow());
    math.set("sinh", new sinh());
    math.set("tanh", new tanh());
    return math;
}
 
Example 5
Source File: StringLib.java    From VideoOS-Android-SDK with GNU General Public License v3.0 5 votes vote down vote up
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 6
Source File: UDBaseListOrRecyclerView.java    From VideoOS-Android-SDK with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 调用 Callback 方法
 *
 * @param cell
 * @param position
 * @return
 */
public LuaValue onCellClicked(LuaValue cell, int position) {
    int section = getSectionByPosition(position);
    int row = getRowInSectionByPosition(position);
    LuaValue cellData = getCell(getId(position, section, row));
    if (cellData != null) {
         LuaValue callback = cellData.get("Callback");
        if (callback.isfunction()) {
            return LuaUtil.callFunction(callback, cell, LuaUtil.toLuaInt(section), LuaUtil.toLuaInt(row));
        } else if (callback.istable()) {
            return LuaUtil.callFunction(LuaUtil.getFunction(callback, "Click", "click"), cell, LuaUtil.toLuaInt(section), LuaUtil.toLuaInt(row));
        }
    }
    return NIL;
}
 
Example 7
Source File: UDBaseListOrRecyclerView.java    From VideoOS-Android-SDK with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 调用 Callback 方法
 *
 * @param cell
 * @param position
 * @return
 */
public boolean onCellLongClicked(LuaValue cell, int position) {
     int section = getSectionByPosition(position);
     int row = getRowInSectionByPosition(position);
     LuaValue cellData = getCell(getId(position, section, row));
    if (cellData != null) {
         LuaValue callback = cellData.get("Callback");
        if (callback != null && callback.istable()) {
            return LuaUtil.callFunction(LuaUtil.getFunction(callback, "LongClick", "longClick"), cell, LuaUtil.toLuaInt(section), LuaUtil.toLuaInt(row)).optboolean(false);
        }
    }
    return false;
}
 
Example 8
Source File: PackageLib.java    From XPrivacyLua with GNU General Public License v3.0 5 votes vote down vote up
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 9
Source File: StringLib.java    From XPrivacyLua with GNU General Public License v3.0 5 votes vote down vote up
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: PackageLib.java    From HtmlNative with Apache License 2.0 5 votes vote down vote up
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 11
Source File: StringLib.java    From HtmlNative with Apache License 2.0 5 votes vote down vote up
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 12
Source File: PackageLib.java    From luaj with MIT License 5 votes vote down vote up
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 13
Source File: StringLib.java    From luaj with MIT License 5 votes vote down vote up
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: PackageLib.java    From VideoOS-Android-SDK with GNU General Public License v3.0 4 votes vote down vote up
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: UDSpannableString.java    From VideoOS-Android-SDK with GNU General Public License v3.0 4 votes vote down vote up
private void initSpannableStringBuilder(LuaValue text, LuaValue config) {
    SpannableStringBuilder spannableStringBuilder = getSpannableStringBuilder();
    if (text != null && text.isstring()) {
        spannableStringBuilder = spannableStringBuilder.append(text.tojstring());
    }

    if (spannableStringBuilder.length() > 0) {
        if (config != null && config.istable()) {
             int end = spannableStringBuilder.length();
             int fontSize = DimenUtil.spToPx(config.get("fontSize").optint(-1));
             Integer fontColor = ColorUtil.parse(LuaUtil.getValue(config, "fontColor"));
             String fontName = config.get("fontName").optjstring(null);

             LuaValue weightValue = config.get("fontWeight");
             int fontWeight = LuaUtil.isNumber(weightValue) ? weightValue.optint(UDFontWeight.WEIGHT_NORMAL_INT) : UDFontWeight.getValue(weightValue.optjstring(UDFontWeight.WEIGHT_NORMAL));

             LuaValue styleValue = config.get("fontStyle");
             int fontStyle = LuaUtil.isNumber(styleValue) ? styleValue.optint(Typeface.NORMAL) : UDFontStyle.getValue(styleValue.optjstring(UDFontStyle.STYLE_NORMAL));

             Integer backgroundColor = ColorUtil.parse(LuaUtil.getValue(config, "backgroundColor"));
             boolean strikethrough = config.get("strikethrough").optboolean(false);
             boolean underline = config.get("underline").optboolean(false);

            if (fontSize != -1) {//字体大小
                spannableStringBuilder.setSpan(new AbsoluteSizeSpan(fontSize), 0, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            }

            if (fontColor != null) {//字体颜色
                spannableStringBuilder.setSpan(new ForegroundColorSpan(fontColor), 0, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            }

            if (fontName != null && getLuaResourceFinder() != null) {//字体
                spannableStringBuilder.setSpan(new CustomTypefaceSpan(fontName, getLuaResourceFinder().findTypeface(fontName)), 0, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            }

            if (fontWeight != -1 && fontWeight > UDFontWeight.WEIGHT_NORMAL_INT) {//文字Weight
                spannableStringBuilder.setSpan(new WeightStyleSpan(fontWeight), 0, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            }

            if (fontStyle != -1 && (fontStyle >= Typeface.NORMAL && fontStyle <= Typeface.BOLD_ITALIC)) {//文字样式
                spannableStringBuilder.setSpan(new StyleSpan(fontStyle), 0, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            }

            if (backgroundColor != null) {//背景色
                spannableStringBuilder.setSpan(new BackgroundColorSpan(backgroundColor), 0, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            }

            if (strikethrough) {//删除线
                spannableStringBuilder.setSpan(new StrikethroughSpan(), 0, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            }

            if (underline) {//下划线
                spannableStringBuilder.setSpan(new UnderlineSpan(), 0, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            }
        }
    }
}
 
Example 16
Source File: UDBaseListOrRecyclerView.java    From VideoOS-Android-SDK with GNU General Public License v3.0 2 votes vote down vote up
/**
 * 是否有某个函数
 *
 * @param cellId
 * @param method
 * @return
 */
public boolean hasCellFunction(String cellId, String method) {
     LuaValue methodData = getCell(cellId);
    return !methodData.isnil() && methodData.get(method) != null && methodData.get(method).isfunction();
}