Mercurial Hosting > luan
diff src/luan/interp/LuaStateImpl.java @ 40:e3624b7cd603
implement stack trace
git-svn-id: https://luan-java.googlecode.com/svn/trunk@41 21e917c8-12df-6dd8-5cb6-c86387c605b9
author | fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9> |
---|---|
date | Fri, 21 Dec 2012 10:45:54 +0000 |
parents | 8a57ebfdfd78 |
children | 57054fa43189 |
line wrap: on
line diff
--- a/src/luan/interp/LuaStateImpl.java Thu Dec 20 02:54:06 2012 +0000 +++ b/src/luan/interp/LuaStateImpl.java Fri Dec 21 10:45:54 2012 +0000 @@ -8,67 +8,24 @@ import luan.LuaFunction; import luan.MetatableGetter; import luan.LuaException; +import luan.LuaElement; -final class LuaStateImpl implements LuaState { - private final LuaTable global = new LuaTable(); - private final List<MetatableGetter> mtGetters = new ArrayList<MetatableGetter>(); - - @Override public LuaTable global() { - return global; - } +final class LuaStateImpl extends LuaState { - @Override public String toString(Object obj) throws LuaException { - LuaFunction fn = getHandlerFunction("__tostring",obj); - if( fn != null ) - return Lua.checkString( Utils.first( fn.call(this,obj) ) ); - if( obj == null ) - return "nil"; - return obj.toString(); + LuaFunction getBinHandler(LuaElement el,String op,Object o1,Object o2) throws LuaException { + LuaFunction f1 = getHandlerFunction(el,op,o1); + if( f1 != null ) + return f1; + return getHandlerFunction(el,op,o2); } - @Override public LuaTable getMetatable(Object obj) { - if( obj instanceof LuaTable ) { - LuaTable table = (LuaTable)obj; - return table.getMetatable(); - } - for( MetatableGetter mg : mtGetters ) { - LuaTable table = mg.getMetatable(obj); - if( table != null ) - return table; - } - return null; - } - - public void addMetatableGetter(MetatableGetter mg) { - mtGetters.add(mg); - } - - Object getHandler(String op,Object obj) throws LuaException { - LuaTable t = getMetatable(obj); - return t==null ? null : t.get(op); - } - - LuaFunction getHandlerFunction(String op,Object obj) throws LuaException { - Object f = getHandler(op,obj); - if( f == null ) - return null; - return Lua.checkFunction(f); - } - - LuaFunction getBinHandler(String op,Object o1,Object o2) throws LuaException { - LuaFunction f1 = getHandlerFunction(op,o1); - if( f1 != null ) - return f1; - return getHandlerFunction(op,o2); - } - - final Object arithmetic(String op,Object o1,Object o2) throws LuaException { - LuaFunction fn = getBinHandler(op,o1,o2); + final Object arithmetic(LuaElement el,String op,Object o1,Object o2) throws LuaException { + LuaFunction fn = getBinHandler(el,op,o1,o2); if( fn != null ) - return Utils.first(fn.call(this,o1,o2)); + return Lua.first(call(fn,el,op,o1,o2)); String type = Lua.toNumber(o1)==null ? Lua.type(o1) : Lua.type(o2); - throw new LuaException("attempt to perform arithmetic on a "+type+" value"); + throw new LuaException(this,el,"attempt to perform arithmetic on a "+type+" value"); }