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


Java LuaValue類代碼示例

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


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

示例1: getValue

import org.luaj.vm2.LuaValue; //導入依賴的package包/類
/**
 * get value of given type, from varargs in position [poslist]
 *
 * @param type
 * @param varargs
 * @param poslist
 * @return
 */
private static Object getValue(final int type, final Varargs varargs, Object defaultValue, int... poslist) {
    Object result = null;
    if (varargs != null) {
        if (poslist != null && poslist.length > 0) {
            LuaValue value = null;
            for (int i = 0; i < poslist.length; i++) {
                if (varargs.narg() >= poslist[i]) {
                    value = varargs.arg(poslist[i]);
                    result = parseValue(type, value);
                }
                if (result != null) {
                    break;
                }
            }
        }
    }
    return result != null ? result : defaultValue;
}
 
開發者ID:alibaba,項目名稱:LuaViewPlayground,代碼行數:27,代碼來源:LuaUtil.java

示例2: invoke

import org.luaj.vm2.LuaValue; //導入依賴的package包/類
public Varargs invoke(Varargs args) {
	String s = args.optjstring(1, "collect");
	if ( "collect".equals(s) ) {
		System.gc();
		return ZERO;
	} else if ( "count".equals(s) ) {
		Runtime rt = Runtime.getRuntime();
		long used = rt.totalMemory() - rt.freeMemory();
		return varargsOf(valueOf(used/1024.), valueOf(used%1024));
	} else if ( "step".equals(s) ) {
		System.gc();
		return LuaValue.TRUE;
	} else {
		this.argerror("gc op");
	}
	return NIL;
}
 
開發者ID:nekocode,項目名稱:Hubs,代碼行數:18,代碼來源:BaseLib.java

示例3: invoke

import org.luaj.vm2.LuaValue; //導入依賴的package包/類
@Override
public Varargs invoke(Varargs args) {
    final ActionBar actionBar = LuaViewUtil.getActionBar(getGlobals());
    if (actionBar != null) {
        final CharSequence title = actionBar.getTitle();
        if (!TextUtils.isEmpty(title)) {
            return valueOf(title.toString());
        } else {
            final View view = actionBar.getCustomView();
            if (view != null) {
                final Object tag = view.getTag(Constants.RES_LV_TAG);
                return tag instanceof LuaValue ? (LuaValue) tag : NIL;
            }
        }
    }
    return NIL;
}
 
開發者ID:alibaba,項目名稱:LuaViewPlayground,代碼行數:18,代碼來源:UDActionBar.java

示例4: byte_

import org.luaj.vm2.LuaValue; //導入依賴的package包/類
/**
 * string.byte (s [, i [, j]])
 *
 * Returns the internal numerical codes of the
 * characters s[i], s[i+1], ..., s[j]. The default value for i is 1; the
 * default value for j is i.
 *
 * Note that numerical codes are not necessarily portable across platforms.
 *
 * @param args the calling args
 */
static Varargs byte_(Varargs args) {
    LuaString s = args.checkstring(1);
    int l = s.m_length;
    int posi = posrelat(args.optint(2, 1), l);
    int pose = posrelat(args.optint(3, posi), l);
    int n, i;
    if (posi <= 0) posi = 1;
    if (pose > l) pose = l;
    if (posi > pose) return NONE;  /* empty interval; return no values */
    n = (int) (pose - posi + 1);
    if (posi + n <= pose)  /* overflow? */
        error("string slice too long");
    LuaValue[] v = new LuaValue[n];
    for (i = 0; i < n; i++)
        v[i] = valueOf(s.luaByte(posi + i - 1));
    return varargsOf(v);
}
 
開發者ID:alibaba,項目名稱:LuaViewPlayground,代碼行數:29,代碼來源:StringLib.java

示例5: HTTPInputGenerator

import org.luaj.vm2.LuaValue; //導入依賴的package包/類
/**
 * Constructs a new HTTPInputGenerator using a Lua generation script.
 * The Lua script must contain the onInit() and onCall(callnum) functions.
 * onCall(callnum) must return the HTTP request for a specific call with number callnum.
 * callnum begins at 1 (Lua convention) and increments for each call. It resets back to 1
 * if onCall returns nil.
 * @param scriptFile The url generator script.
 * @param randomSeed Seed for Lua random function.
 * @param timeout The http read timeout.
 */
public HTTPInputGenerator(File scriptFile, int randomSeed, int timeout) {
	OkHttpClient.Builder httpClientBuilder = new OkHttpClient.Builder();
	cookieManager.setCookiePolicy(CookiePolicy.ACCEPT_ALL);
	httpClientBuilder = httpClientBuilder.cookieJar(new JavaNetCookieJar(cookieManager));
	if (timeout > 0) {
		httpClientBuilder = httpClientBuilder.readTimeout(timeout, TimeUnit.MILLISECONDS)
			.connectTimeout(timeout, TimeUnit.MILLISECONDS);
	}
	httpClient = httpClientBuilder.build();
	if (scriptFile != null) {
		luaGlobals = JsePlatform.standardGlobals();
		//luaGlobals.get("require").call(LuaValue.valueOf("tools.descartes.httploadgenerator.http.lua.HTML"));
		LuaValue library = new LuaTable();
		library.set("getMatches", new GetMatches(htmlFunctions));
		library.set("extractMatches", new ExtractAllMatches(htmlFunctions));
		luaGlobals.set("html", library);
		luaGlobals.get("math").get("randomseed").call(LuaValue.valueOf(5));
		luaGlobals.get("dofile").call(LuaValue.valueOf(scriptFile.getAbsolutePath()));
	}
}
 
開發者ID:joakimkistowski,項目名稱:HTTP-Load-Generator,代碼行數:31,代碼來源:HTTPInputGenerator.java

示例6: callFunction

import org.luaj.vm2.LuaValue; //導入依賴的package包/類
public static Varargs callFunction(LuaValue target, Object... objs) {
    if (target != null && target.isfunction()) {
        LuaValue[] args = null;
        if (objs != null && objs.length > 0) {
            args = new LuaValue[objs.length];

            for (int i = 0; i < objs.length; i++) {
                args[i] = CoerceJavaToLua.coerce(objs[i]);
            }
        }
        if (args != null) {
            return target.invoke(LuaValue.varargsOf(args));
        } else {
            return target.call();
        }
    }
    return LuaValue.NIL;
}
 
開發者ID:alibaba,項目名稱:LuaViewPlayground,代碼行數:19,代碼來源:LuaUtil.java

示例7: freaduntil

import org.luaj.vm2.LuaValue; //導入依賴的package包/類
public static LuaValue freaduntil(File f,boolean lineonly) throws IOException {
	ByteArrayOutputStream baos = new ByteArrayOutputStream();
	int c;
	try {
		if ( lineonly ) {
			loop: while ( (c = f.read()) > 0 ) { 
				switch ( c ) {
				case '\r': break;
				case '\n': break loop;
				default: baos.write(c); break;
				}
			}
		} else {
			while ( (c = f.read()) > 0 ) 
				baos.write(c);
		}
	} catch ( EOFException e ) {
		c = -1;
	}
	return ( c < 0 && baos.size() == 0 )? 
		(LuaValue) NIL:
		(LuaValue) LuaString.valueOf(baos.toByteArray());
}
 
開發者ID:alibaba,項目名稱:LuaViewPlayground,代碼行數:24,代碼來源:IoLib.java

示例8: runFunction

import org.luaj.vm2.LuaValue; //導入依賴的package包/類
@Override
public void runFunction(String functionName) {
    LuaValue v = mGlobals.get(functionName);
    if (v != null) {
        v.call();
    }
}
 
開發者ID:hsllany,項目名稱:HtmlNative,代碼行數:8,代碼來源:LuaRunner.java

示例9: 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:nekocode,項目名稱:Hubs,代碼行數:9,代碼來源:StringLib.java

示例10: LuaPlugin

import org.luaj.vm2.LuaValue; //導入依賴的package包/類
public LuaPlugin(String name, String version, String description, LuaValue handler) {
    this.name = name;
    this.description = description;
    this.version = version;
    this.handler = handler;
    constructHandlerFunctions();
    logger = Logger.getLogger(name);
    set("logger", new LuaLogger(logger));
    set("name", LuaValue.valueOf(getName()));
    set("version", LuaValue.valueOf(getVersion()));
    set("description", LuaValue.valueOf(getDescription()));
}
 
開發者ID:LukkitPlus,項目名稱:Lukkit,代碼行數:13,代碼來源:LuaPlugin.java

示例11: translationX

import org.luaj.vm2.LuaValue; //導入依賴的package包/類
/**
 * 獲取translationX
 *
 * @param view
 * @param varargs
 * @return
 */
public LuaValue translationX(U view, Varargs varargs) {
    if (varargs.narg() > 1) {
        return setTranslationX(view, varargs);
    } else {
        return getTranslationX(view, varargs);
    }
}
 
開發者ID:alibaba,項目名稱:LuaViewPlayground,代碼行數:15,代碼來源:UIViewMethodMapper.java

示例12: getBooleanListFromTable

import org.luaj.vm2.LuaValue; //導入依賴的package包/類
/**
 * Transforming a table of LUA values to a array list of booleans.
 * @param table The table to map.
 * @return The Boolean list.
 */
public static ArrayList<Boolean> getBooleanListFromTable(LuaValue table) {
	return getGenericListFromTable(table, new LuaValueMapper<Boolean>() {
		@Override
		public Boolean map(LuaValue v) {
			return v.toboolean();
		}
	});
}
 
開發者ID:joakimkistowski,項目名稱:HTTP-Load-Generator,代碼行數:14,代碼來源:LuaHelpers.java

示例13: call

import org.luaj.vm2.LuaValue; //導入依賴的package包/類
public LuaValue call(LuaValue e, LuaValue base) {
    if (base.isnil())
        return e.tonumber();
    final int b = base.checkint();
    if (b < 2 || b > 36)
        argerror(2, "base out of range");
    return e.checkstring().tonumber(b);
}
 
開發者ID:alibaba,項目名稱:LuaViewPlayground,代碼行數:9,代碼來源:BaseLib.java

示例14: call

import org.luaj.vm2.LuaValue; //導入依賴的package包/類
@Override
public final LuaValue call(LuaValue modname, LuaValue env) {
    LuaValue library = tableOf();

    // Load library table
    Map<String, LuaValue> table = new HashMap<>();
    load(table);
    table.forEach(library::set);

    env.set(key, library);
    return library;
}
 
開發者ID:ImpactDevelopment,項目名稱:ClientAPI,代碼行數:13,代碼來源:LuaLibrary.java

示例15: testLuaRunner

import org.luaj.vm2.LuaValue; //導入依賴的package包/類
@Test
public void testLuaRunner() {
    String luaScript = Utils.toString(new File("lua_test/test.lua"));
    Globals globals = JsePlatform.standardGlobals();
    LuaValue value = globals.load(luaScript);
    value.invoke();
}
 
開發者ID:hsllany,項目名稱:HtmlNative,代碼行數:8,代碼來源:LuaRunnerTest.java


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