use of org.luaj.vm2.LuaTable in project LuaViewSDK by alibaba.
the class LuaViewManager method createMetatable.
//-----------------------------------------metatable--------------------------------------------
/**
* create metatable for libs
*
* @return
*/
public static LuaTable createMetatable(Class<? extends LibFunction> libClass) {
//get from cache
LuaTable result = AppCache.getCache(CACHE_METATABLES).get(libClass);
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;
}
use of org.luaj.vm2.LuaTable in project LuaViewSDK by alibaba.
the class UDCanvas method getDefaultPaint.
private Paint getDefaultPaint(LuaValue config) {
if (mPaint == null) {
mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
}
//config
if (config instanceof LuaTable) {
mPaint.reset();
final LuaValue[] keys = ((LuaTable) config).keys();
if (keys != null && keys.length > 0) {
String key;
LuaValue value;
for (int i = 0; i < keys.length; i++) {
if (LuaUtil.isString(keys[i])) {
key = keys[i].optjstring(null);
if (!TextUtils.isEmpty(key)) {
key = key.toLowerCase();
value = config.get(keys[i]);
if (LuaUtil.isValid(value)) {
Integer pos = sPaintAttrIndex.get(key);
if (pos == null) {
continue;
}
switch(pos) {
case PAINT_COLOR:
mPaint.setColor(ColorUtil.parse(value));
break;
case PAINT_ALPHA:
mPaint.setAlpha(LuaUtil.toAlphaInt(value));
break;
case PAINT_STROKE_WIDTH:
mPaint.setStrokeWidth(DimenUtil.dpiToPxF((float) value.optdouble(0)));
break;
case PAINT_TEXT_SIZE:
mPaint.setTextSize(DimenUtil.spToPx((float) value.optdouble(12.0f)));
break;
case PAINT_UNDERLINE:
mPaint.setUnderlineText(value.optboolean(false));
break;
case PAINT_STRIKE_THROUGH:
mPaint.setStrikeThruText(value.optboolean(false));
break;
case PAINT_BOLD:
mPaint.setFakeBoldText(value.optboolean(false));
break;
case PAINT_LETTER_SPACING:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
mPaint.setLetterSpacing(DimenUtil.dpiToPxF((float) value.optdouble(0)));
}
break;
case PAINT_TYPEFACE:
{
String typeface = value.optjstring(null);
if (!TextUtils.isEmpty(typeface)) {
mPaint.setTypeface(getLuaResourceFinder().findTypeface(typeface));
}
break;
}
case PAINT_TEXT_SCALE_X:
mPaint.setTextScaleX((float) value.optdouble(1));
break;
case PAINT_TEXT_SKEW_X:
mPaint.setTextSkewX((float) value.optdouble(0));
break;
case PAINT_LINEAR_TEXT:
mPaint.setLinearText(value.optboolean(false));
break;
case PAINT_TEXT_ALIGN:
{
setPaintTextAlign(value);
break;
}
case PAINT_STYLE:
{
setPaintStyle(value);
break;
}
case PAINT_FILTER_BITMAP:
mPaint.setFilterBitmap(value.optboolean(false));
break;
}
}
}
}
}
}
//anti alias
mPaint.setAntiAlias(true);
}
return mPaint;
}
use of org.luaj.vm2.LuaTable in project LuaViewSDK by alibaba.
the class UDHttp method initVarargs.
/**
* 初始化数据
*/
private void initVarargs() {
final LuaValue param1 = getInitParam1();
final LuaFunction callback = LuaUtil.getFunction(initParams, 2);
final String method = LuaUtil.getString(param1, "method");
final LuaTable params = LuaUtil.getTable(param1, "params");
setMethod(method);
setParams(params);
setCallback(callback);
disableConnectionReuseIfNecessary();
}
use of org.luaj.vm2.LuaTable in project LuaViewSDK by alibaba.
the class UDHttpResponse method toTable.
/**
* convert response to LuaTable
*
* @return
*/
public LuaTable toTable() {
LuaTable result = new LuaTable();
result.set("data", new UDData(getGlobals(), getmetatable(), null).append(mData));
result.set("code", LuaValue.valueOf(mStatusCode));
result.set("header", LuaUtil.toTable(mHeaders));
result.set("message", LuaValue.valueOf(mResponseMsg));
return result;
}
use of org.luaj.vm2.LuaTable in project LuaViewSDK by alibaba.
the class VibratorMethodMapper method vibrate.
/**
* 开始震动
*
* @param vibrator
* @param varargs
* @return
*/
public LuaValue vibrate(U vibrator, Varargs varargs) {
if (varargs.narg() > 2 || (varargs.narg() > 1 && varargs.istable(2))) {
final LuaTable luaTable = LuaUtil.getTable(varargs, 2);
final Integer repeat = LuaUtil.toJavaInt(varargs.arg(3));
return vibrator.vibrate(luaTable, repeat);
} else {
final Double time = LuaUtil.getDouble(varargs, 2);
return vibrator.vibrate((long) (time != null ? time * DateUtil.ONE_SECOND : DateUtil.ONE_SECOND));
}
}
Aggregations