本文整理汇总了Java中org.luaj.vm2.LuaTable类的典型用法代码示例。如果您正苦于以下问题:Java LuaTable类的具体用法?Java LuaTable怎么用?Java LuaTable使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
LuaTable类属于org.luaj.vm2包,在下文中一共展示了LuaTable类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: drawLines
import org.luaj.vm2.LuaTable; //导入依赖的package包/类
private void drawLines(Varargs varargs) {
final Canvas canvas = getCanvas();
if (canvas != null) {
final LuaTable table = LuaUtil.getTable(varargs, 2);
if (table != null) {
final LuaValue[] keys = table.keys();
if (keys.length > 0) {
final float pts[] = new float[keys.length * 4];
LuaValue value = null;
for (int i = 0; i < keys.length; i++) {
value = table.get(keys[i]);
if (value instanceof LuaTable && value.length() >= 4) {
for (int j = 0; j < 4; j++) {
pts[i * 4 + j] = DimenUtil.dpiToPx(value.get(j + 1));
}
}
}
final LuaValue config = LuaUtil.isTable(varargs.arg(3)) ? LuaUtil.getTable(varargs, 3) : null;
canvas.drawLines(pts, getDefaultPaint(config));
}
}
}
}
示例2: require
import org.luaj.vm2.LuaTable; //导入依赖的package包/类
/**
* Lua业务代码层可以使用该API请求跳转到一个新的Activity。
* @param params
*/
@LuaViewApi
public void require(LuaTable params) {
HashMap<String, String> hashMap = new HashMap<>();
LuaValue[] k = params.keys();
for (int i=0; i < k.length; i++) {
hashMap.put(k[i].optjstring(null), params.get(k[i]).optjstring(null));
}
/**
* 启动另一个Activity之前,把当前Activity的packagePath和uri参数透传给下一个Activity。
*/
if (mActivity.mUri != null) {
hashMap.put("uri", mActivity.mUri);
hashMap.put("packagePath", LuaScriptManager.buildScriptBundleFolderPath(mActivity.mUri));
}
Intent intent = new Intent(mActivity, LVBasicActivity.class);
intent.putExtra(Constants.PAGE_PARAMS, hashMap);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mActivity.startActivity(intent);
}
示例3: time
import org.luaj.vm2.LuaTable; //导入依赖的package包/类
/**
* Returns the current time when called without arguments,
* or a time representing the date and time specified by the given table.
* This table must have fields year, month, and day,
* and may have fields hour, min, sec, and isdst
* (for a description of these fields, see the os.date function).
* @param table
* @return long value for the time
*/
protected double time(LuaTable table) {
java.util.Date d;
if (table == null) {
d = new java.util.Date();
} else {
Calendar c = Calendar.getInstance();
c.set(Calendar.YEAR, table.get("year").checkint());
c.set(Calendar.MONTH, table.get("month").checkint()-1);
c.set(Calendar.DAY_OF_MONTH, table.get("day").checkint());
c.set(Calendar.HOUR_OF_DAY, table.get("hour").optint(0));
c.set(Calendar.MINUTE, table.get("min").optint(0));
c.set(Calendar.SECOND, table.get("sec").optint(0));
c.set(Calendar.MILLISECOND, 0);
d = c.getTime();
}
return d.getTime() / 1000.;
}
示例4: call
import org.luaj.vm2.LuaTable; //导入依赖的package包/类
public LuaValue call(LuaValue modname, LuaValue env) {
globals = env.checkglobals();
// io lib functions
LuaTable t = new LuaTable();
bind(t, IoLibV.class, IO_NAMES );
// create file methods table
filemethods = new LuaTable();
bind(filemethods, IoLibV.class, FILE_NAMES, FILE_CLOSE );
// set up file metatable
LuaTable mt = new LuaTable();
bind(mt, IoLibV.class, new String[] { "__index" }, IO_INDEX );
t.setmetatable( mt );
// all functions link to library instance
setLibInstance( t );
setLibInstance( filemethods );
setLibInstance( mt );
// return the table
env.set("io", t);
env.get("package").get("loaded").set("io", t);
return t;
}
示例5: call
import org.luaj.vm2.LuaTable; //导入依赖的package包/类
public LuaValue call(LuaValue modname, LuaValue env) {
globals = env.checkglobals();
globals.set("require", new require());
package_ = new LuaTable();
package_.set(_LOADED, new LuaTable());
package_.set(_PRELOAD, new LuaTable());
package_.set(_PATH, LuaValue.valueOf(DEFAULT_LUA_PATH));
package_.set(_LOADLIB, new loadlib());
package_.set(_SEARCHPATH, new searchpath());
LuaTable searchers = new LuaTable();
searchers.set(1, preload_searcher = new preload_searcher());
searchers.set(2, lua_searcher = new lua_searcher());
searchers.set(3, java_searcher = new java_searcher());
package_.set(_SEARCHERS, searchers);
package_.get(_LOADED).set("package", package_);
env.set("package", package_);
globals.package_ = this;
return env;
}
示例6: invoke
import org.luaj.vm2.LuaTable; //导入依赖的package包/类
public Varargs invoke(Varargs args) {
switch (args.narg()) {
case 0: case 1: {
return argerror(2, "value expected");
}
case 2: {
LuaTable table = args.arg1().checktable();
table.insert(table.length()+1,args.arg(2));
return NONE;
}
default: {
args.arg1().checktable().insert(args.checkint(2),args.arg(3));
return NONE;
}
}
}
示例7: bindMethods
import org.luaj.vm2.LuaTable; //导入依赖的package包/类
/**
* bind lua functions using method
*
* @param factory
* @param methods
* @return
*/
public static LuaTable bindMethods(Class<? extends LibFunction> factory, List<Method> methods) {
LuaTable env = new LuaTable();
try {
if (methods != null) {
for (int i = 0; i < methods.size(); i++) {
LibFunction f = factory.newInstance();
f.opcode = -1;
f.method = methods.get(i);
f.name = methods.get(i).getName();
env.set(f.name, f);
}
}
} catch (Exception e) {
throw new LuaError("[Bind Failed] " + e);
} finally {
return env;
}
}
示例8: bind
import org.luaj.vm2.LuaTable; //导入依赖的package包/类
/**
* bind lua functions using opcode
*
* @param factory
* @param methods
* @return
*/
public static LuaTable bind(Class<? extends LibFunction> factory, List<String> methods) {
LuaTable env = new LuaTable();
try {
if (methods != null) {
for (int i = 0; i < methods.size(); i++) {
LibFunction f = factory.newInstance();
f.opcode = i;
f.method = null;
f.name = methods.get(i);
env.set(f.name, f);
}
}
} catch (Exception e) {
throw new LuaError("[Bind Failed] " + e);
} finally {
return env;
}
}
示例9: createMetatable
import org.luaj.vm2.LuaTable; //导入依赖的package包/类
/**
* create metatable for libs
*
* @return
*/
public static LuaTable createMetatable(Class<? extends LibFunction> libClass) {
LuaTable result = AppCache.getCache(CACHE_METATABLES).get(libClass);//get from cache
if (result == null) {
LuaTable libTable = null;
if (LuaViewConfig.isUseNoReflection()) {
final List<String> methodNames = getMapperMethodNames(libClass);
libTable = LuaViewManager.bind(libClass, methodNames);
} else {
final List<Method> methods = getMapperMethods(libClass);
libTable = LuaViewManager.bindMethods(libClass, methods);
}
result = LuaValue.tableOf(new LuaValue[]{LuaValue.INDEX, libTable, LuaValue.NEWINDEX, new NewIndexFunction(libTable)});
//update cache
AppCache.getCache(CACHE_METATABLES).put(libClass, result);
}
return result;
}
示例10: invoke
import org.luaj.vm2.LuaTable; //导入依赖的package包/类
@Override
public Varargs invoke(Varargs args) {
LuaTable table = new LuaTable();
table.set("device", AndroidUtil.getDevice());
table.set("brand", AndroidUtil.getBrand());
table.set("product", AndroidUtil.getProduct());
table.set("manufacturer", AndroidUtil.getManufacturer());
//screen size
int[] screenSize = AndroidUtil.getWindowSizeInDp(getContext());
table.set("window_width", screenSize[0]);
table.set("window_height", screenSize[1]);
//action bar height
int actionBarHeight = AndroidUtil.getActionBarHeightInDp(getContext());
table.set("nav_height", actionBarHeight);
int bottomNavHeight = AndroidUtil.getNavigationBarHeightInDp(getContext());
table.set("bottom_nav_height", bottomNavHeight);
int statusBarHeight = AndroidUtil.getStatusBarHeightInDp(getContext());
table.set("status_bar_height", statusBarHeight);
return table;
}
示例11: vibrate
import org.luaj.vm2.LuaTable; //导入依赖的package包/类
/**
* 震动
*
* @param patternTable
* @param repeat
* @return
*/
public UDVibrator vibrate(final LuaTable patternTable, final Integer repeat) {
if (patternTable != null) {
final Vibrator vibrator = getVibrator();
if (vibrator != null) {
if (patternTable.length() > 1) {
long[] pattern = new long[patternTable.length()];
for (int i = 0; i < patternTable.length(); i++) {
pattern[i] = (long) (patternTable.get((i + 1)).optdouble(1) * 1000);
}
vibrator.vibrate(pattern, repeat);
} else {
vibrator.vibrate((long) (patternTable.get(1).optdouble(1) * 1000));
}
}
}
return this;
}
示例12: clipRects
import org.luaj.vm2.LuaTable; //导入依赖的package包/类
private void clipRects(Varargs varargs) {
final Canvas canvas = getCanvas();
if (canvas != null) {
final LuaTable table = LuaUtil.getTable(varargs, 2);
if (table != null) {
final LuaValue[] keys = table.keys();
if (keys.length > 0) {
LuaValue value = null;
float x1, y1, dx, dy;
for (int i = 0; i < keys.length; i++) {
value = table.get(keys[i]);
if (value instanceof LuaTable && value.length() >= 4) {
x1 = DimenUtil.dpiToPx(value.get(1));
y1 = DimenUtil.dpiToPx(value.get(2));
dx = DimenUtil.dpiToPx(value.get(3));
dy = DimenUtil.dpiToPx(value.get(4));
canvas.clipRect(x1, y1, x1 + dx, y1 + dy);
}
}
}
}
}
}
示例13: mapping
import org.luaj.vm2.LuaTable; //导入依赖的package包/类
public static LuaTable mapping(Class<?> c) {
try {
LuaTable luaTable = new LuaTable();
for (Field field : c.getFields()) {
if (!Modifier.isStatic(field.getModifiers())) continue;
if (LuaValue.class.isAssignableFrom(field.getType())) {
luaTable.set(field.getName(), (LuaValue) field.get(null));
}
if (field.getType().equals(Class.class)) {
luaTable.set(field.getName(), mapping((Class<?>) field.get(null)));
}
}
return new ReadOnlyLuaTable(luaTable);
} catch (Exception e) {
throw new CubesException("Failed to create lua api", e);
}
}
示例14: drawCircles
import org.luaj.vm2.LuaTable; //导入依赖的package包/类
private void drawCircles(Varargs varargs) {
final Canvas canvas = getCanvas();
if (canvas != null) {
LuaTable table = LuaUtil.getTable(varargs, 2);
final LuaValue config = LuaUtil.isTable(varargs.arg(3)) ? LuaUtil.getTable(varargs, 3) : null;
if (table != null) {
final LuaValue[] keys = table.keys();
if (keys.length > 0) {
LuaValue value = null;
for (int i = 0; i < keys.length; i++) {
value = table.get(keys[i]);
if (value instanceof LuaTable && value.length() >= 3) {
canvas.drawCircle(DimenUtil.dpiToPx(value.get(1)),
DimenUtil.dpiToPx(value.get(2)),
DimenUtil.dpiToPx(value.get(3)),
getDefaultPaint(LuaUtil.isTable(value.get(4)) ? value.get(4) : config));
}
}
}
}
}
}
示例15: drawTexts
import org.luaj.vm2.LuaTable; //导入依赖的package包/类
private void drawTexts(Varargs varargs) {
final Canvas canvas = getCanvas();
if (canvas != null) {
final LuaTable table = LuaUtil.getTable(varargs, 2);
final LuaValue config = LuaUtil.isTable(varargs.arg(3)) ? LuaUtil.getTable(varargs, 3) : null;
if (table != null) {
final LuaValue[] keys = table.keys();
if (keys.length > 0) {
LuaValue value = null;
CharSequence text = null;
for (int i = 0; i < keys.length; i++) {
value = table.get(keys[i]);
if (value instanceof LuaTable && value.length() >= 3) {
text = LuaUtil.toText(value.get(1));
if (!TextUtils.isEmpty(text)) {
canvas.drawText(text, 0, text.length(),
DimenUtil.dpiToPx(value.get(2)),
DimenUtil.dpiToPx(value.get(3)),
getDefaultPaint(LuaUtil.isTable(value.get(4)) ? value.get(4) : config));
}
}
}
}
}
}
}