當前位置: 首頁>>代碼示例>>Java>>正文


Java LuaValue.checkstring方法代碼示例

本文整理匯總了Java中org.luaj.vm2.LuaValue.checkstring方法的典型用法代碼示例。如果您正苦於以下問題:Java LuaValue.checkstring方法的具體用法?Java LuaValue.checkstring怎麽用?Java LuaValue.checkstring使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.luaj.vm2.LuaValue的用法示例。


在下文中一共展示了LuaValue.checkstring方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: coerce

import org.luaj.vm2.LuaValue; //導入方法依賴的package包/類
public Object coerce(LuaValue value) {
	if ( value.isnil() )
		return null;
	if ( targetType == TARGET_TYPE_STRING )
		return value.tojstring();
	LuaString s = value.checkstring();
	byte[] b = new byte[s.m_length];
	s.copyInto(0, b, 0, b.length);
	return b;
}
 
開發者ID:alibaba,項目名稱:LuaViewPlayground,代碼行數:11,代碼來源:CoerceLuaToJava.java

示例2: reverse

import org.luaj.vm2.LuaValue; //導入方法依賴的package包/類
/**
 * string.reverse (s)
 *
 * Returns a string that is the string s reversed.
 */
static LuaValue reverse(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.valueOf(b);
}
 
開發者ID:alibaba,項目名稱:LuaViewPlayground,代碼行數:14,代碼來源:StringLib.java

示例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;
}
 
開發者ID:hsllany,項目名稱:HtmlNative,代碼行數:38,代碼來源:PackageLib.java

示例4: call

import org.luaj.vm2.LuaValue; //導入方法依賴的package包/類
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 );
}
 
開發者ID:hsllany,項目名稱:HtmlNative,代碼行數:9,代碼來源:StringLib.java

示例5: buildState

import org.luaj.vm2.LuaValue; //導入方法依賴的package包/類
/**
 * Print the state of a {@link LuaClosure} that is being executed
 *
 * @param cl      the {@link LuaClosure}
 * @param pc      the program counter
 * @param stack   the stack of {@link LuaValue}
 * @param top     the top of the stack
 * @param varargs any {@link Varargs} value that may apply
 */
public LuaPrint buildState(LuaClosure cl, int pc, LuaValue[] stack, int top, Varargs varargs) {
    // print opcode into buffer
    StringBuffer previous = ps;
    ps = new StringBuffer();
    buildOpCode(cl.p, pc);

    LogUtil.i(ps);

    ps = previous;
    format(ps.toString(), 50);

    // print stack
    ps.append('[');
    for (int i = 0; i < stack.length; i++) {
        LuaValue v = stack[i];
        if (v == null)
            ps.append(STRING_FOR_NULL);
        else switch (v.type()) {
            case LuaValue.TSTRING:
                LuaString s = v.checkstring();
                ps.append(s.length() < 48 ?
                        s.tojstring() :
                        s.substring(0, 32).tojstring() + "...+" + (s.length() - 32) + "b");
                break;
            case LuaValue.TFUNCTION:
                ps.append(v.tojstring());
                break;
            case LuaValue.TUSERDATA:
                Object o = v.touserdata();
                if (o != null) {
                    String n = o.getClass().getName();
                    n = n.substring(n.lastIndexOf('.') + 1);
                    ps.append(n + ": " + Integer.toHexString(o.hashCode()));
                } else {
                    ps.append(v.toString());
                }
                break;
            default:
                ps.append(v.tojstring());
        }
        if (i + 1 == top)
            ps.append(']');
        ps.append(" | ");
    }
    ps.append(varargs);
    ps.append("\n");
    return this;
}
 
開發者ID:alibaba,項目名稱:LuaViewPlayground,代碼行數:58,代碼來源:LuaPrint.java

示例6: 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;
         }
     }
 
開發者ID:alibaba,項目名稱:LuaViewPlayground,代碼行數:47,代碼來源:PackageLib.java


注:本文中的org.luaj.vm2.LuaValue.checkstring方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。