本文整理匯總了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;
}
示例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;
}
示例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;
}
示例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);
}
示例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()));
}
}
示例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;
}
示例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());
}
示例8: runFunction
import org.luaj.vm2.LuaValue; //導入依賴的package包/類
@Override
public void runFunction(String functionName) {
LuaValue v = mGlobals.get(functionName);
if (v != null) {
v.call();
}
}
示例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 );
}
示例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()));
}
示例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);
}
}
示例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();
}
});
}
示例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);
}
示例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;
}
示例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();
}