/** * Get particular metatag, or throw {@link LuaError} if it doesn't exist * @param tag Metatag name to look up, typically a string such as * {@link LuaValue#INDEX} or {@link LuaValue#NEWINDEX} * @param reason Description of error when tag lookup fails. * @return {@link LuaValue} that can be called * @throws LuaError when the lookup fails. */ protected LuaValue checkmetatag(LuaValue tag, String reason) { LuaValue h = this.metatag(tag); if ( h.isnil() ) throw new LuaError(reason+typename()); return h; }
/** Perform metatag processing for concatenation operations. * <p> * Finds the {@link #CONCAT} metatag value and invokes it, * or throws {@link LuaError} if it doesn't exist. * @param rhs The right-hand-side value to perform the operation with * @return {@link LuaValue} resulting from metatag processing for {@link #CONCAT} metatag. * @throws LuaError if metatag was not defined for either operand */ public LuaValue concatmt(LuaValue rhs) { LuaValue h=metatag(CONCAT); if ( h.isnil() && (h=rhs.metatag(CONCAT)).isnil()) error("attempt to concatenate "+typename()+" and "+rhs.typename()); return h.call(this,rhs); }
/** * Get particular metatag, or throw {@link LuaError} if it doesn't exist * @param tag Metatag name to look up, typically a string such as * {@link LuaValue#INDEX} or {@link LuaValue#NEWINDEX} * @param reason Description of error when tag lookup fails. * @return {@link LuaValue} that can be called * @throws LuaError when the lookup fails. */ protected LuaValue checkmetatag(LuaValue tag, String reason) { LuaValue h = this.metatag(tag); if ( h.isnil() ) throw new LuaError(reason+typename()); return h; }
/** Perform metatag processing for concatenation operations. * <p> * Finds the {@link #CONCAT} metatag value and invokes it, * or throws {@link LuaError} if it doesn't exist. * @param rhs The right-hand-side value to perform the operation with * @return {@link LuaValue} resulting from metatag processing for {@link #CONCAT} metatag. * @throws LuaError if metatag was not defined for either operand */ public LuaValue concatmt(LuaValue rhs) { LuaValue h=metatag(CONCAT); if ( h.isnil() && (h=rhs.metatag(CONCAT)).isnil()) error("attempt to concatenate "+typename()+" and "+rhs.typename()); return h.call(this,rhs); }
/** * Get particular metatag, or throw {@link LuaError} if it doesn't exist * @param tag Metatag name to look up, typically a string such as * {@link LuaValue#INDEX} or {@link LuaValue#NEWINDEX} * @param reason Description of error when tag lookup fails. * @return {@link LuaValue} that can be called * @throws LuaError when the lookup fails. */ protected LuaValue checkmetatag(LuaValue tag, String reason) { LuaValue h = this.metatag(tag); if ( h.isnil() ) throw new LuaError(reason+typename()); return h; }
/** Perform metatag processing for concatenation operations. * <p> * Finds the {@link CONCAT} metatag value and invokes it, * or throws {@link LuaError} if it doesn't exist. * @param rhs The right-hand-side value to perform the operation with * @return {@link LuaValue} resulting from metatag processing for {@link CONCAT} metatag. * @throws LuaError if metatag was not defined for either operand */ public LuaValue concatmt(LuaValue rhs) { LuaValue h=metatag(CONCAT); if ( h.isnil() && (h=rhs.metatag(CONCAT)).isnil()) error("attempt to concatenate "+typename()+" and "+rhs.typename()); return h.call(this,rhs); }
/** Perform metatag processing for comparison operations. * <p> * Finds the supplied metatag value and invokes it, * or throws {@link LuaError} if none applies. * @param tag The metatag to look up * @param op1 The operand with which to to perform the operation * @return {@link LuaValue} resulting from metatag processing * @throws LuaError if metatag was not defined for either operand, * or if the operands are not the same type, * or the metatag values for the two operands are different. * @see #gt(LuaValue) * @see #gteq(LuaValue) * @see #lt(LuaValue) * @see #lteq(LuaValue) */ public LuaValue comparemt( LuaValue tag, LuaValue op1 ) { LuaValue h; if (!(h = metatag(tag)).isnil() || !(h = op1.metatag(tag)).isnil()) return h.call(this, op1); if (LuaValue.LE.raweq(tag) && (!(h = metatag(LT)).isnil() || !(h = op1.metatag(LT)).isnil())) return h.call(op1, this).not(); return error("attempt to compare "+tag+" on "+typename()+" and "+op1.typename()); }
/** Perform metatag processing for comparison operations. * <p> * Finds the supplied metatag value and invokes it, * or throws {@link LuaError} if none applies. * @param tag The metatag to look up * @param op1 The operand with which to to perform the operation * @return {@link LuaValue} resulting from metatag processing * @throws LuaError if metatag was not defined for either operand, * or if the operands are not the same type, * or the metatag values for the two operands are different. * @see #gt(LuaValue) * @see #gteq(LuaValue) * @see #lt(LuaValue) * @see #lteq(LuaValue) */ public LuaValue comparemt( LuaValue tag, LuaValue op1 ) { LuaValue h; if (!(h = metatag(tag)).isnil() || !(h = op1.metatag(tag)).isnil()) return h.call(this, op1); if (LuaValue.LE.raweq(tag) && (!(h = metatag(LT)).isnil() || !(h = op1.metatag(LT)).isnil())) return h.call(op1, this).not(); return error("attempt to compare "+tag+" on "+typename()+" and "+op1.typename()); }
/** Perform metatag processing for comparison operations. * <p> * Finds the supplied metatag value and invokes it, * or throws {@link LuaError} if none applies. * @param tag The metatag to look up * @param rhs The right-hand-side value to perform the operation with * @return {@link LuaValue} resulting from metatag processing * @throws LuaError if metatag was not defined for either operand, * or if the operands are not the same type, * or the metatag values for the two operands are different. * @see #gt(LuaValue) * @see #gteq(LuaValue) * @see #lt(LuaValue) * @see #lteq(LuaValue) */ public LuaValue comparemt( LuaValue tag, LuaValue op1 ) { LuaValue h = metatag(tag); if ( !h.isnil() ) return h.call(this, op1); h = op1.metatag(tag); if ( !h.isnil() ) return h.call(this, op1); return error("attempt to compare "+tag+" on "+typename()+" and "+op1.typename()); }
/** get value from metatable operations, or NIL if not defined by metatables */ protected static LuaValue gettable(LuaValue t, LuaValue key) { LuaValue tm; int loop = 0; do { if (t.istable()) { LuaValue res = t.rawget(key); if ((!res.isnil()) || (tm = t.metatag(INDEX)).isnil()) return res; } else if ((tm = t.metatag(INDEX)).isnil()) t.indexerror(); if (tm.isfunction()) return tm.call(t, key); t = tm; } while ( ++loop < MAXTAGLOOP ); error("loop in gettable"); return NIL; }
/** get value from metatable operations, or NIL if not defined by metatables */ protected static LuaValue gettable(LuaValue t, LuaValue key) { LuaValue tm; int loop = 0; do { if (t.istable()) { LuaValue res = t.rawget(key); if ((!res.isnil()) || (tm = t.metatag(INDEX)).isnil()) return res; } else if ((tm = t.metatag(INDEX)).isnil()) t.indexerror(); if (tm.isfunction()) return tm.call(t, key); t = tm; } while ( ++loop < MAXTAGLOOP ); error("loop in gettable"); return NIL; }
/** get value from metatable operations, or NIL if not defined by metatables */ protected static LuaValue gettable(LuaValue t, LuaValue key) { LuaValue tm; int loop = 0; do { if (t.istable()) { LuaValue res = t.rawget(key); if ((!res.isnil()) || (tm = t.metatag(INDEX)).isnil()) return res; } else if ((tm = t.metatag(INDEX)).isnil()) t.indexerror(); if (tm.isfunction()) return tm.call(t, key); t = tm; } while ( ++loop < MAXTAGLOOP ); error("loop in gettable"); return NIL; }
public LuaValue call(LuaValue arg) { LuaValue h = arg.metatag(TOSTRING); if (!h.isnil()) { return h.call(arg); } LuaValue v = arg.tostring(); if (!v.isnil()) { return v; } return valueOf(arg.tojstring()); } }
public LuaValue call(LuaValue arg) { LuaValue h = arg.metatag(TOSTRING); if ( ! h.isnil() ) return h.call(arg); LuaValue v = arg.tostring(); if ( ! v.isnil() ) return v; return valueOf(arg.tojstring()); } }
@Override public LuaValue call(LuaValue arg) { LuaValue h = arg.metatag(TOSTRING); if ( ! h.isnil() ) return h.call(arg); LuaValue v = arg.tostring(); if ( ! v.isnil() ) return v; return valueOf(arg.tojstring()); } }
/** * Perform field assignment including metatag processing. * @param t {@link LuaValue} on which value is being set, typically a table or something with the metatag {@link LuaValue#NEWINDEX} defined * @param key {@link LuaValue} naming the field to assign * @param value {@link LuaValue} the new value to assign to {@code key} * @throws LuaError if there is a loop in metatag processing * @return true if assignment or metatag processing succeeded, false otherwise */ protected static boolean settable(LuaValue t, LuaValue key, LuaValue value) { LuaValue tm; int loop = 0; do { if (t.istable()) { if ((!t.rawget(key).isnil()) || (tm = t.metatag(NEWINDEX)).isnil()) { t.rawset(key, value); return true; } } else if ((tm = t.metatag(NEWINDEX)).isnil()) t.typerror("index"); if (tm.isfunction()) { tm.call(t, key, value); return true; } t = tm; } while ( ++loop < MAXTAGLOOP ); error("loop in settable"); return false; }
/** Perform metatag processing for arithmetic operations when the left-hand-side is a number. * <p> * Finds the supplied metatag value for {@code this} and invokes it, * or throws {@link LuaError} if neither is defined. * @param tag The metatag to look up * @param op1 The value of the left-hand-side to perform the operation with * @return {@link LuaValue} resulting from metatag processing * @throws LuaError if metatag was not defined for either operand * @see #add(LuaValue) * @see #sub(LuaValue) * @see #mul(LuaValue) * @see #pow(LuaValue) * @see #div(LuaValue) * @see #mod(LuaValue) * @see #ADD * @see #SUB * @see #MUL * @see #POW * @see #DIV * @see #MOD */ protected LuaValue arithmtwith(LuaValue tag, double op1) { LuaValue h = metatag(tag); if ( h.isnil() ) error( "attempt to perform arithmetic "+tag+" on number and "+typename() ); return h.call( LuaValue.valueOf(op1), this ); }
/** Perform metatag processing for arithmetic operations when the left-hand-side is a number. * <p> * Finds the supplied metatag value for {@code this} and invokes it, * or throws {@link LuaError} if neither is defined. * @param tag The metatag to look up * @param op1 The value of the left-hand-side to perform the operation with * @return {@link LuaValue} resulting from metatag processing * @throws LuaError if metatag was not defined for either operand * @see #add(LuaValue) * @see #sub(LuaValue) * @see #mul(LuaValue) * @see #pow(LuaValue) * @see #div(LuaValue) * @see #mod(LuaValue) * @see #ADD * @see #SUB * @see #MUL * @see #POW * @see #DIV * @see #MOD */ protected LuaValue arithmtwith(LuaValue tag, double op1) { LuaValue h = metatag(tag); if ( h.isnil() ) error( "attempt to perform arithmetic "+tag+" on number and "+typename() ); return h.call( LuaValue.valueOf(op1), this ); }
/** Perform metatag processing for arithmetic operations when the left-hand-side is a number. * <p> * Finds the supplied metatag value for {@code this} and invokes it, * or throws {@link LuaError} if neither is defined. * @param tag The metatag to look up * @param op1 The value of the left-hand-side to perform the operation with * @return {@link LuaValue} resulting from metatag processing * @throws LuaError if metatag was not defined for either operand * @see #add(LuaValue) * @see #sub(LuaValue) * @see #mul(LuaValue) * @see #pow(LuaValue) * @see #div(LuaValue) * @see #mod(LuaValue) * @see #ADD * @see #SUB * @see #MUL * @see #POW * @see #DIV * @see #MOD */ protected LuaValue arithmtwith(LuaValue tag, double op1) { LuaValue h = metatag(tag); if ( h.isnil() ) error( "attempt to perform arithmetic "+tag+" on number and "+typename() ); return h.call( LuaValue.valueOf(op1), this ); }