/** * Assert a condition is true, or throw a {@link LuaError} if not * Returns no value when b is true, throws {@link #error(String)} with {@code msg} as argument * and does not return if b is false. * @param b condition to test * @param msg String message to produce on failure * @throws LuaError if b is not true */ public static void assert_(boolean b,String msg) { if(!b) throw new LuaError(msg); }
/** * Throw a {@link LuaError} indicating an invalid argument was supplied to a function * @param iarg index of the argument that was invalid, first index is 1 * @param msg String providing information about the invalid argument * @throws LuaError in all cases */ public static LuaValue argerror(int iarg,String msg) { throw new LuaError("bad argument #"+iarg+": "+msg); }
/** * Throw a {@link LuaError} with a particular message * @param message String providing message details * @throws LuaError in all cases */ public static LuaValue error(String message) { throw new LuaError(message); }
/** * Throw a {@link LuaError} indicating an illegal operation occurred, * typically involved in managing weak references * @throws LuaError in all cases */ protected LuaValue illegal(String op,String typename) { throw new LuaError("illegal operation '"+op+"' for "+typename); }
/** * Throw a {@link LuaError} based on the len operator, * typically due to an invalid operand type * @throws LuaError in all cases */ protected LuaValue lenerror() { throw new LuaError("attempt to get length of "+typename()); }
/** * Throw a {@link LuaError} based on an arithmetic error such as add, or pow, * typically due to an invalid operand type * @throws LuaError in all cases */ protected LuaValue aritherror() { throw new LuaError("attempt to perform arithmetic on "+typename()); }
/** * Throw a {@link LuaError} based on a comparison error such as greater-than or less-than, * typically due to an invalid operand type * @param rhs String description of what was on the right-hand-side of the comparison that resulted in the error. * @throws LuaError in all cases */ protected LuaValue compareerror(String rhs) { throw new LuaError("attempt to compare "+typename()+" with "+rhs); }
/** * Throw a {@link LuaError} based on an arithmetic error such as add, or pow, * typically due to an invalid operand type * @param fun String description of the function that was attempted * @throws LuaError in all cases */ protected LuaValue aritherror(String fun) { throw new LuaError("attempt to perform arithmetic '"+fun+"' on "+typename()); }
/** * Throw a {@link LuaError} based on an arithmetic error such as add, or pow, * typically due to an invalid operand type * @param fun String description of the function that was attempted * @throws LuaError in all cases */ protected LuaValue aritherror(String fun) { throw new LuaError("attempt to perform arithmetic '"+fun+"' on "+typename()); }
/** * Throw a {@link LuaError} indicating an operation is not implemented * @throws LuaError in all cases */ protected LuaValue unimplemented(String fun) { throw new LuaError("'"+fun+"' not implemented for "+typename()); }
/** Function which yields the current thread. * @param args Arguments to supply as return values in the resume function of the resuming thread. * @return Values supplied as arguments to the resume() call that reactivates this thread. */ public Varargs yield(Varargs args) { if (running == null || running.isMainThread()) throw new LuaError("cannot yield main thread"); final LuaThread.State s = running.state; return s.lua_yield(args); }
/** * Throw a {@link LuaError} indicating an invalid type was supplied to a function * @param expected String naming the type that was expected * @throws LuaError in all cases */ protected LuaValue typerror(String expected) { throw new LuaError(expected+" expected, got "+typename()+" value="+this.tostring()); }
/** * Throw a {@link LuaError} based on a comparison error such as greater-than or less-than, * typically due to an invalid operand type * @param rhs Right-hand-side of the comparison that resulted in the error. * @throws LuaError in all cases */ protected LuaValue compareerror(LuaValue rhs) { throw new LuaError("attempt to compare "+typename()+" with "+rhs.typename()); }
public Varargs invoke(Varargs args) { Object[] a = convertArgs(args); try { return CoerceJavaToLua.coerce( constructor.newInstance(a) ); } catch (InvocationTargetException e) { throw new LuaError(e.getTargetException()); } catch (Exception e) { return LuaValue.error("coercion error "+e); } }
/** * Throw a {@link LuaError} based on a comparison error such as greater-than or less-than, * typically due to an invalid operand type * @param rhs Right-hand-side of the comparison that resulted in the error. * @throws LuaError in all cases */ protected LuaValue compareerror(LuaValue rhs) { throw new LuaError("attempt to compare "+typename()+" with "+rhs.typename()); }
/** * Throw a {@link LuaError} indicating an invalid argument was supplied to a function * @param expected String naming the type that was expected * @throws LuaError in all cases */ protected LuaValue argerror(String expected) { throw new LuaError("bad argument: "+expected+" expected, got "+typename()+" value="+this.tostring()); }
LuaValue invokeMethod(Object instance, Varargs args) { Object[] a = convertArgs(args); try { return CoerceJavaToLua.coerce( method.invoke(instance, a) ); } catch (InvocationTargetException e) { throw new LuaError(e.getTargetException()); } catch (Exception e) { return LuaValue.error("coercion error "+e); } }
void lexerror( String msg, int token ) { String cid = Lua.chunkid( source.tojstring() ); L.pushfstring( cid+":"+linenumber+": "+msg ); if ( token != 0 ) L.pushfstring( "syntax error: "+msg+" near "+txtToken(token) ); throw new LuaError(cid+":"+linenumber+": "+msg); }