From 9b77084109cc1e522b7f9d834c293529e5f9b7af Mon Sep 17 00:00:00 2001 From: Enyby Date: Sun, 16 Sep 2018 15:39:24 +0300 Subject: [PATCH] Improved error messages. --- src/core/org/luaj/vm2/LuaValue.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/core/org/luaj/vm2/LuaValue.java b/src/core/org/luaj/vm2/LuaValue.java index a3ac45d3..20fa804d 100644 --- a/src/core/org/luaj/vm2/LuaValue.java +++ b/src/core/org/luaj/vm2/LuaValue.java @@ -3143,7 +3143,7 @@ public class LuaValue extends Varargs { * @return {@link LuaString} corresponding to the value if a string or number * @throws LuaError if not a string or number */ - public LuaString strvalue() { typerror("strValue"); return null; } + public LuaString strvalue() { typerror("string or number"); return null; } /** Return this value as a strong reference, or null if it was weak and is no longer referenced. * @return {@link LuaValue} referred to, or null if it was weak and is no longer referenced. @@ -3298,7 +3298,7 @@ public class LuaValue extends Varargs { if ((!res.isnil()) || (tm = t.metatag(INDEX)).isnil()) return res; } else if ((tm = t.metatag(INDEX)).isnil()) - t.indexerror(); + t.indexerror(key.tojstring()); if (tm.isfunction()) return tm.call(t, key); t = tm; @@ -3326,7 +3326,7 @@ public class LuaValue extends Varargs { return true; } } else if ((tm = t.metatag(NEWINDEX)).isnil()) - t.typerror("index"); + throw new LuaError("table expected for set index ('" + key + "') value, got " + t.typename()); if (tm.isfunction()) { tm.call(t, key, value); return true; @@ -3389,8 +3389,8 @@ public class LuaValue extends Varargs { /** Throw {@link LuaError} indicating index was attempted on illegal type * @throws LuaError when called. */ - private void indexerror() { - error( "attempt to index ? (a "+typename()+" value)" ); + private void indexerror(String key) { + error( "attempt to index ? (a "+typename()+" value) with key '" + key + "'" ); } /** Construct a {@link Varargs} around an array of {@link LuaValue}s.