/** * 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); }
/** Get the LuaValue that was provided in the constructor, or * a LuaString containing the message if it was a string error argument. * @return LuaValue which was used in the constructor, or a LuaString * containing the message. */ public LuaValue getMessageObject() { if (object != null) return object; String m = getMessage(); return m != null ? LuaValue.valueOf(m): null; }
private LuaValue getValueFromElement(JsonElement element) { if (element.isJsonArray() || element.isJsonObject()) { return this.getTableFromElement(element); } else if (element.isJsonNull()) { return LuaValue.NIL; } else if (element.isJsonPrimitive()) { JsonPrimitive primitiveValue = element.getAsJsonPrimitive(); if (primitiveValue.isBoolean()) { return LuaValue.valueOf(primitiveValue.getAsBoolean()); } else if (primitiveValue.isString()) { return LuaValue.valueOf(primitiveValue.getAsString()); } else if (primitiveValue.isNumber()) { Number numberValue = primitiveValue.getAsNumber(); if (numberValue instanceof Double) return LuaValue.valueOf(numberValue.doubleValue()); else if (numberValue instanceof Integer) return LuaValue.valueOf(numberValue.intValue()); else if (numberValue instanceof Short) return LuaValue.valueOf(numberValue.shortValue()); else if (numberValue instanceof Long) return LuaValue.valueOf(numberValue.longValue()); else if (numberValue instanceof Float) return LuaValue.valueOf(numberValue.floatValue()); else if (numberValue instanceof Byte) return LuaValue.valueOf(numberValue.byteValue()); } } else { LuaError error = new LuaError("A LuaJsonElement object was passed an unsupported value other than that supported by LuaJ. Value: " + element.toString()); LuaEnvironment.addError(error); error.printStackTrace(); } return LuaValue.NIL; }
sender.sendMessage(error.getMessage()); error.printStackTrace(); } catch (NumberFormatException e) { sender.sendMessage(ChatColor.RED + args[1] + " cannot be converted to an integer.");
public Varargs invoke(Varargs args) { LuaValue func = args.checkvalue(1); if (globals != null && globals.debuglib != null) globals.debuglib.onCall(this); try { return varargsOf(TRUE, func.invoke(args.subargs(2))); } catch ( LuaError le ) { final LuaValue m = le.getMessageObject(); return varargsOf(FALSE, m!=null? m: NIL); } catch ( Exception e ) { final String m = e.getMessage(); return varargsOf(FALSE, valueOf(m!=null? m: e.toString())); } finally { if (globals != null && globals.debuglib != null) globals.debuglib.onReturn(); } } }
public Varargs invoke(Varargs args) { LuaValue func = args.checkvalue(1); if (globals != null && globals.debuglib != null) { globals.debuglib.onCall(this); } try { return varargsOf(TRUE, func.invoke(args.subargs(2))); } catch (LuaError le) { final LuaValue m = le.getMessageObject(); return varargsOf(FALSE, m != null ? m : NIL); } catch (Exception e) { final String m = e.getMessage(); return varargsOf(FALSE, valueOf(m != null ? m : e.toString())); } finally { if (globals != null && globals.debuglib != null) { globals.debuglib.onReturn(); } } } }
/** * 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); }
/** Get the LuaValue that was provided in the constructor, or * a LuaString containing the message if it was a string error argument. * @return LuaValue which was used in the constructor, or a LuaString * containing the message. */ public LuaValue getMessageObject() { if (object != null) return object; String m = getMessage(); return m != null ? LuaValue.valueOf(m): null; }
public Varargs invoke(Varargs args) { final LuaThread t = globals.running; final LuaValue preverror = t.errorfunc; t.errorfunc = args.checkvalue(2); try { if (globals != null && globals.debuglib != null) globals.debuglib.onCall(this); try { return varargsOf(TRUE, args.arg1().invoke(args.subargs(3))); } catch ( LuaError le ) { final LuaValue m = le.getMessageObject(); return varargsOf(FALSE, m!=null? m: NIL); } catch ( Exception e ) { final String m = e.getMessage(); return varargsOf(FALSE, valueOf(m!=null? m: e.toString())); } finally { if (globals != null && globals.debuglib != null) globals.debuglib.onReturn(); } } finally { t.errorfunc = preverror; } } }
/** * 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); }
private void processErrorHooks(LuaError le, Prototype p, int pc) { le.fileline = (p.source != null? p.source.tojstring(): "?") + ":" + (p.lineinfo != null && pc >= 0 && pc < p.lineinfo.length? String.valueOf(p.lineinfo[pc]): "?"); le.traceback = errorHook(le.getMessage(), le.level); }
public Varargs invoke(Varargs args) { final LuaThread t = globals.running; final LuaValue preverror = t.errorfunc; t.errorfunc = args.checkvalue(2); try { if (globals != null && globals.debuglib != null) { globals.debuglib.onCall(this); } try { return varargsOf(TRUE, args.arg1().invoke(args.subargs(3))); } catch (LuaError le) { final LuaValue m = le.getMessageObject(); return varargsOf(FALSE, m != null ? m : NIL); } catch (Exception e) { final String m = e.getMessage(); return varargsOf(FALSE, valueOf(m != null ? m : e.toString())); } finally { if (globals != null && globals.debuglib != null) { globals.debuglib.onReturn(); } } } finally { t.errorfunc = preverror; } } }
/** * 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); }
private void processErrorHooks(LuaError le, Prototype p, int pc) { le.fileline = (p.source != null? p.source.tojstring(): "?") + ":" + (p.lineinfo != null && pc >= 0 && pc < p.lineinfo.length? String.valueOf(p.lineinfo[pc]): "?"); le.traceback = errorHook(le.getMessage(), le.level); }
/** * 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); }
private void processErrorHooks(LuaError le, Prototype p, int pc) { le.fileline = (p.source != null? p.source.tojstring(): "?") + ":" + (p.lineinfo != null && pc >= 0 && pc < p.lineinfo.length? String.valueOf(p.lineinfo[pc]): "?"); le.traceback = errorHook(le.getMessage(), le.level); }
/** * 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); }
@Override public Varargs invoke(Varargs args) { LuaValue func = args.checkvalue(1); if (globals != null && globals.debuglib != null) globals.debuglib.onCall(this); try { return varargsOf(TRUE, func.invoke(args.subargs(2))); } catch ( LuaError le ) { final String m = le.getMessage(); return varargsOf(FALSE, m!=null? valueOf(m): NIL); } catch ( Exception e ) { final String m = e.getMessage(); return varargsOf(FALSE, valueOf(m!=null? m: e.toString())); } finally { if (globals != null && globals.debuglib != null) globals.debuglib.onReturn(); } } }
/** * 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); }
@Override public Varargs invoke(Varargs args) { final LuaThread t = globals.running; final LuaValue preverror = t.errorfunc; t.errorfunc = args.checkvalue(2); try { if (globals != null && globals.debuglib != null) globals.debuglib.onCall(this); try { return varargsOf(TRUE, args.arg1().invoke(args.subargs(3))); } catch ( LuaError le ) { final String m = le.getMessage(); return varargsOf(FALSE, m!=null? valueOf(m): NIL); } catch ( Exception e ) { final String m = e.getMessage(); return varargsOf(FALSE, valueOf(m!=null? m: e.toString())); } finally { if (globals != null && globals.debuglib != null) globals.debuglib.onReturn(); } } finally { t.errorfunc = preverror; } } }