/** Return argument i as a java Object if it is a userdata whose instance Class c or a subclass, or null. * @param i the index of the argument to convert, 1 is the first argument * @param c the class to which the userdata instance must be assignable * @return java Object value if argument i is a userdata whose instance Class c or a subclass, otherwise null * */ public Object touserdata(int i,Class c) { return arg(i).touserdata(c); }
private WeakUserdata(LuaValue value) { super(value); ob = new WeakReference(value.touserdata()); mt = value.getmetatable(); }
/** Return argument i as a java Object if a userdata, or null. * @param i the index of the argument to convert, 1 is the first argument * @return java Object value if argument i is a userdata, otherwise null * */ public Object touserdata(int i) { return arg(i).touserdata(); }
/** Return argument i as a java Object if a userdata, or null. * @param i the index of the argument to convert, 1 is the first argument * @return java Object value if argument i is a userdata, otherwise null * */ public Object touserdata(int i) { return arg(i).touserdata(); }
private WeakUserdata(LuaValue value) { super(value); ob = new WeakReference(value.touserdata()); mt = value.getmetatable(); }
/** Return argument i as a java Object if a userdata, or null. * @param i the index of the argument to convert, 1 is the first argument * @return java Object value if argument i is a userdata, otherwise null * */ public Object touserdata(int i) { return arg(i).touserdata(); }
/** Return argument i as a java Object if it is a userdata whose instance Class c or a subclass, or null. * @param i the index of the argument to convert, 1 is the first argument * @param c the class to which the userdata instance must be assignable * @return java Object value if argument i is a userdata whose instance Class c or a subclass, otherwise null * */ public Object touserdata(int i,Class c) { return arg(i).touserdata(c); }
private WeakUserdata(LuaValue value) { super(value); ob = new WeakReference(value.touserdata()); mt = value.getmetatable(); }
/** Return argument i as a java Object if it is a userdata whose instance Class c or a subclass, or null. * @param i the index of the argument to convert, 1 is the first argument * @param c the class to which the userdata instance must be assignable * @return java Object value if argument i is a userdata whose instance Class c or a subclass, otherwise null * */ public Object touserdata(int i,Class c) { return arg(i).touserdata(c); }
public int score(LuaValue value) { switch ( value.type() ) { case LuaValue.TTABLE: return value.length()==0? 0: componentCoercion.score( value.get(1) ); case LuaValue.TUSERDATA: return inheritanceLevels( componentType, value.touserdata().getClass().getComponentType() ); case LuaValue.TNIL: return SCORE_NULL_VALUE; default: return SCORE_UNCOERCIBLE; } } public Object coerce(LuaValue value) {
public int score(LuaValue value) { switch ( value.type() ) { case LuaValue.TTABLE: return value.length()==0? 0: componentCoercion.score( value.get(1) ); case LuaValue.TUSERDATA: return inheritanceLevels( componentType, value.touserdata().getClass().getComponentType() ); case LuaValue.TNIL: return SCORE_NULL_VALUE; default: return SCORE_UNCOERCIBLE; } } public Object coerce(LuaValue value) {
private HashMap<?, ?> convertToMap(LuaTable table) { HashMap<Object, Object> map = new HashMap<>(); LuaValue[] rootKeys = table.keys(); for (LuaValue k : rootKeys) { if (table.get(k).istable()) { map.put(k, this.convertToMap(table.get(k).checktable())); } else { map.put(k, table.get(k).touserdata()); } } return map; }
@Override public LuaValue call(LuaValue arg) { Object[] list = (Object[]) arg.touserdata(); LuaTable t = new LuaTable(); for (int i = 0; i < list.length; i++) { t.set(LuaValue.valueOf(i + 1), CoerceJavaToLua.coerce(list[i])); } return t; } });
public int score(LuaValue value) { switch ( value.type() ) { case LuaValue.TNUMBER: return inheritanceLevels( targetType, value.isint()? Integer.class: Double.class ); case LuaValue.TBOOLEAN: return inheritanceLevels( targetType, Boolean.class ); case LuaValue.TSTRING: return inheritanceLevels( targetType, String.class ); case LuaValue.TUSERDATA: return inheritanceLevels( targetType, value.touserdata().getClass() ); case LuaValue.TNIL: return SCORE_NULL_VALUE; default: return inheritanceLevels( targetType, value.getClass() ); } } public Object coerce(LuaValue value) {
@Override public LuaValue call(LuaValue arg) { Map<?, ?> map; if (arg.checkuserdata() instanceof Map) { map = (Map<?, ?>) arg.touserdata(); } else { throw new LukkitPluginException("util.tableFromMap(obj) was passed something other than a implementation of Map."); } LuaTable t = new LuaTable(); map.forEach((k, v) -> t.set(CoerceJavaToLua.coerce(k), CoerceJavaToLua.coerce(v))); return t; } });
public int score(LuaValue value) { switch ( value.type() ) { case LuaValue.TNUMBER: return inheritanceLevels( targetType, value.isint()? Integer.class: Double.class ); case LuaValue.TBOOLEAN: return inheritanceLevels( targetType, Boolean.class ); case LuaValue.TSTRING: return inheritanceLevels( targetType, String.class ); case LuaValue.TUSERDATA: return inheritanceLevels( targetType, value.touserdata().getClass() ); case LuaValue.TNIL: return SCORE_NULL_VALUE; default: return inheritanceLevels( targetType, value.getClass() ); } } public Object coerce(LuaValue value) {
@Override public LuaValue call(LuaValue item) { if (!item.isnil() && !(item.checkuserdata() instanceof ItemStack)) { throw new LukkitPluginException("parseItemStack was given something other than an ItemStack"); } return CoerceJavaToLua.coerce(new ItemStackWrapper((ItemStack) item.touserdata())); } });
@Override public LuaValue call(LuaValue item) { if (!item.isnil() && !(item.checkuserdata() instanceof ItemStack)) { throw new LukkitPluginException("bukkit.getSkullMeta was passed something other than an ItemStack."); } return CoerceJavaToLua.coerce(new SkullWrapper((item.isnil()) ? null : (ItemStack) item.touserdata())); } });
@Override public LuaValue call(LuaValue item) { if (!item.isnil() && !(item.checkuserdata() instanceof ItemStack)) { throw new LukkitPluginException("bukkit.getBannerMeta was passed something other than an ItemStack."); } return CoerceJavaToLua.coerce(new BannerWrapper((item.isnil()) ? null : (ItemStack) item.touserdata())); } });
public Var(LuaValue value){ if( value == null || value.isnil() ){ return; } if( value.isboolean() ){ set(value.toboolean()); return; } if( value.isstring() || value.isnumber() ){ set(value.toString()); return; } if( value.isuserdata() ){ set(value.touserdata()); return; } set(value); }