use of org.luaj.vm2.LuaTable in project LogisticsPipes by RS485.
the class LPASMHookCC method onCCWrappedILuaObject.
public static LuaTable onCCWrappedILuaObject(final LuaTable table, final ILuaObject object) {
if (object instanceof CCCommandWrapper) {
LuaTable lpTable = new LPLuaTable((CCCommandWrapper) object);
LuaValue k = LuaValue.NIL;
while (true) {
Varargs n = table.next(k);
if ((k = n.arg1()).isnil()) {
break;
}
LuaValue v = n.arg(2);
lpTable.set(k, v);
}
((CCCommandWrapper) object).table = lpTable;
return lpTable;
}
return table;
}
use of org.luaj.vm2.LuaTable in project LuaViewSDK by alibaba.
the class LuaViewManager method bindMethods.
/**
* 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;
}
}
use of org.luaj.vm2.LuaTable in project LuaViewSDK by alibaba.
the class LuaViewManager method bind.
/**
* bind lua functions using opcode
*
* @param factory
* @param methods
* @return
*/
public static LuaTable bind(Class<? extends LibFunction> factory, String[] methods) {
LuaTable env = new LuaTable();
try {
if (methods != null) {
for (int i = 0; i < methods.length; i++) {
LibFunction f = factory.newInstance();
f.opcode = i;
f.method = null;
f.name = methods[i];
env.set(f.name, f);
}
}
} catch (Exception e) {
throw new LuaError("[Bind Failed] " + e);
} finally {
return env;
}
}
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;
}
Aggregations