Mercurial Hosting > luan
changeset 41:c53dc854e6cc
minor
git-svn-id: https://luan-java.googlecode.com/svn/trunk@42 21e917c8-12df-6dd8-5cb6-c86387c605b9
author | fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9> |
---|---|
date | Fri, 21 Dec 2012 19:34:50 +0000 |
parents | e3624b7cd603 |
children | 786699c78837 |
files | src/luan/LuaElement.java src/luan/LuaSource.java src/luan/lib/BasicLib.java |
diffstat | 3 files changed, 14 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/src/luan/LuaElement.java Fri Dec 21 10:45:54 2012 +0000 +++ b/src/luan/LuaElement.java Fri Dec 21 19:34:50 2012 +0000 @@ -2,15 +2,16 @@ public abstract class LuaElement { - abstract String toString(String fnName); - final String function(String fnName) { - return fnName==null ? "main chunk" : "function '"+fnName+"'"; + final String toString(String fnName) { + return location() + ": in " + (fnName==null ? "main chunk" : "function '"+fnName+"'"); } + abstract String location(); + public static final LuaElement JAVA = new LuaElement(){ - @Override public String toString(String fnName) { - return "java: in " + function(fnName); + @Override String location() { + return "Java"; } }; }
--- a/src/luan/LuaSource.java Fri Dec 21 10:45:54 2012 +0000 +++ b/src/luan/LuaSource.java Fri Dec 21 19:34:50 2012 +0000 @@ -27,8 +27,8 @@ return source.text.substring(start,end); } - @Override public String toString(String fnName) { - return source.name + ':' + lineNumber() + ": in " + function(fnName); + @Override String location() { + return source.name + ':' + lineNumber(); } private int lineNumber() {
--- a/src/luan/lib/BasicLib.java Fri Dec 21 10:45:54 2012 +0000 +++ b/src/luan/lib/BasicLib.java Fri Dec 21 19:34:50 2012 +0000 @@ -26,6 +26,7 @@ LuaTable global = lua.global(); global.put( "_G", global ); add( global, "do_file", LuaState.class, String.class ); + add( global, "error", LuaState.class, String.class ); add( global, "get_metatable", LuaState.class, Object.class ); add( global, "ipairs", LuaTable.class ); add( global, "load", LuaState.class, String.class, String.class ); @@ -223,4 +224,9 @@ public static String to_string(LuaState lua,Object v) throws LuaException { return lua.toString(LuaElement.JAVA,v); } + + public static void error(LuaState lua,String msg) throws LuaException { + throw new LuaException(lua,LuaElement.JAVA,msg); + } + }