use of org.luaj.vm2.LuaValue in project love-android by hagish.
the class LuanThread method InitLib.
public LuaTable InitLib() {
LuaTable t = LuaValue.tableOf();
LuaValue _G = vm.get_G();
_G.set(sMetaName_LuanThread, LuanObjThreadObj.CreateMetaTable(this));
// / thread = love.thread.newThread( name, filename )
// / thread = love.thread.newThread( name, file ) -- File file : The file to use as source.
// / thread = love.thread.newThread( name, data ) -- Data data : The data to use as source.
// / Creates a new Thread from a File or Data Object.
t.set("newThread", new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
String name = args.checkjstring(1);
// TODO: param2 ? can be different things
try {
return LuaValue.userdataOf(new LuanObjThreadObj(LuanThread.this, name), vm.get_G().get(sMetaName_LuanThread));
} catch (Exception e) {
vm.handleError(e);
}
return LuaValue.NONE;
}
});
// / thread = love.thread.getThread( name )
// / Look for a thread and get its object.
// / TODO: not yet implemented
t.set("getThread", new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
vm.NotImplemented("love.thread.getThread");
return LuaValue.NONE;
}
});
// / threads = love.thread.getThreads( )
// / Get all threads.
// / TODO: not yet implemented
t.set("getThreads", new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
vm.NotImplemented("love.thread.getThreads");
return LuaValue.NONE;
}
});
return t;
}
use of org.luaj.vm2.LuaValue 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.LuaValue in project LuaViewSDK by alibaba.
the class UDSpannableString method initSpannableStringBuilder.
private void initSpannableStringBuilder(LuaValue text, LuaValue config) {
SpannableStringBuilder spannableStringBuilder = getSpannableStringBuilder();
if (text != null && text.isstring()) {
spannableStringBuilder = spannableStringBuilder.append(text.tojstring());
}
if (spannableStringBuilder.length() > 0) {
if (config != null && config.istable()) {
final int end = spannableStringBuilder.length();
final int fontSize = DimenUtil.spToPx(config.get("fontSize").optint(-1));
final Integer fontColor = ColorUtil.parse(LuaUtil.getValue(config, "fontColor"));
final String fontName = config.get("fontName").optjstring(null);
final LuaValue weightValue = config.get("fontWeight");
final int fontWeight = LuaUtil.isNumber(weightValue) ? weightValue.optint(UDFontWeight.WEIGHT_NORMAL_INT) : UDFontWeight.getValue(weightValue.optjstring(UDFontWeight.WEIGHT_NORMAL));
final LuaValue styleValue = config.get("fontStyle");
final int fontStyle = LuaUtil.isNumber(styleValue) ? styleValue.optint(Typeface.NORMAL) : UDFontStyle.getValue(styleValue.optjstring(UDFontStyle.STYLE_NORMAL));
final Integer backgroundColor = ColorUtil.parse(LuaUtil.getValue(config, "backgroundColor"));
final boolean strikethrough = config.get("strikethrough").optboolean(false);
final boolean underline = config.get("underline").optboolean(false);
if (fontSize != -1) {
// 字体大小
spannableStringBuilder.setSpan(new AbsoluteSizeSpan(fontSize), 0, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
if (fontColor != null) {
// 字体颜色
spannableStringBuilder.setSpan(new ForegroundColorSpan(fontColor), 0, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
if (fontName != null && getLuaResourceFinder() != null) {
// 字体
spannableStringBuilder.setSpan(new CustomTypefaceSpan(fontName, getLuaResourceFinder().findTypeface(fontName)), 0, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
if (fontWeight != -1 && fontWeight > UDFontWeight.WEIGHT_NORMAL_INT) {
// 文字Weight
spannableStringBuilder.setSpan(new WeightStyleSpan(fontWeight), 0, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
if (fontStyle != -1 && (fontStyle >= Typeface.NORMAL && fontStyle <= Typeface.BOLD_ITALIC)) {
// 文字样式
spannableStringBuilder.setSpan(new StyleSpan(fontStyle), 0, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
if (backgroundColor != null) {
// 背景色
spannableStringBuilder.setSpan(new BackgroundColorSpan(backgroundColor), 0, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
if (strikethrough) {
// 删除线
spannableStringBuilder.setSpan(new StrikethroughSpan(), 0, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
if (underline) {
// 下划线
spannableStringBuilder.setSpan(new UnderlineSpan(), 0, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
}
}
}
use of org.luaj.vm2.LuaValue 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.LuaValue in project LuaViewSDK by alibaba.
the class UDBitmap method init.
/**
* 初始化
*/
private void init() {
if (initParams != null) {
LuaValue data = null;
if (initParams.isuserdata(1)) {
data = LuaUtil.getUserdata(initParams, 1);
} else {
mUrl = LuaUtil.getString(initParams, 1);
}
mCallback = LuaUtil.getFunction(initParams, 2);
if (data != null) {
fetchBitmapFromData(data);
} else {
fetchBitmapFromUrl(mUrl);
}
}
}
Aggregations