use of org.luaj.vm2.LuaValue in project LuaViewSDK by alibaba.
the class JavaClass method getMethod.
LuaValue getMethod(LuaValue key) {
if (methods == null) {
Map namedlists = new HashMap();
Method[] m = ((Class) m_instance).getMethods();
for (int i = 0; i < m.length; i++) {
Method mi = m[i];
if (Modifier.isPublic(mi.getModifiers())) {
String name = mi.getName();
List list = (List) namedlists.get(name);
if (list == null) {
namedlists.put(name, list = new ArrayList());
}
JavaMethod method = JavaMethod.forMethod(mi);
if (method != null) {
//FIXME by song, 做保护
list.add(method);
}
}
}
Map map = new HashMap();
Constructor[] c = ((Class) m_instance).getConstructors();
List list = new ArrayList();
for (int i = 0; i < c.length; i++) if (Modifier.isPublic(c[i].getModifiers()))
list.add(JavaConstructor.forConstructor(c[i]));
switch(list.size()) {
case 0:
break;
case 1:
map.put(NEW, list.get(0));
break;
default:
map.put(NEW, JavaConstructor.forConstructors((JavaConstructor[]) list.toArray(new JavaConstructor[list.size()])));
break;
}
for (Iterator it = namedlists.entrySet().iterator(); it.hasNext(); ) {
Entry e = (Entry) it.next();
String name = (String) e.getKey();
List methods = (List) e.getValue();
map.put(LuaValue.valueOf(name), methods.size() == 1 ? methods.get(0) : JavaMethod.forMethods((JavaMethod[]) methods.toArray(new JavaMethod[methods.size()])));
}
methods = map;
}
return (LuaValue) methods.get(key);
}
use of org.luaj.vm2.LuaValue in project LuaViewSDK by alibaba.
the class JavaInstance method set.
public void set(LuaValue key, LuaValue value) {
if (jclass == null)
jclass = JavaClass.forClass(m_instance.getClass());
Field f = jclass.getField(key);
if (f != null)
try {
f.set(m_instance, CoerceLuaToJava.coerce(value, f.getType()));
return;
} catch (Exception e) {
throw new LuaError(e);
}
super.set(key, value);
}
use of org.luaj.vm2.LuaValue in project LuaViewSDK by alibaba.
the class JavaInstance method get.
public LuaValue get(LuaValue key) {
if (jclass == null)
jclass = JavaClass.forClass(m_instance.getClass());
Field f = jclass.getField(key);
if (f != null)
try {
return CoerceJavaToLua.coerce(f.get(m_instance));
} catch (Exception e) {
throw new LuaError(e);
}
LuaValue m = jclass.getMethod(key);
if (m != null)
return m;
return super.get(key);
}
use of org.luaj.vm2.LuaValue in project LuaViewSDK by alibaba.
the class JseMathLib method call.
public LuaValue call(LuaValue modname, LuaValue env) {
super.call(modname, env);
LuaValue math = env.get("math");
math.set("acos", new acos());
math.set("asin", new asin());
math.set("atan", new atan());
math.set("atan2", new atan2());
math.set("cosh", new cosh());
math.set("exp", new exp());
math.set("log", new log());
math.set("pow", new pow());
math.set("sinh", new sinh());
math.set("tanh", new tanh());
return math;
}
use of org.luaj.vm2.LuaValue in project LuaViewSDK by alibaba.
the class LVCustomViewPagerIndicator method createAndRenderView.
/**
* 创建一个item
*
* @param pos
* @return
*/
private View createAndRenderView(int pos) {
final int currentItem = mViewPager.getCurrentItem();
final LuaValue cellData = createView(pos, currentItem);
if (cellData instanceof UDLuaTable) {
//绘制
mLuaUserdata.callCellLayout(cellData, pos, currentItem);
return ((UDLuaTable) cellData).getView();
}
return null;
}
Aggregations