Mercurial Hosting > luan
diff src/luan/interp/ConcatExpr.java @ 10:8217d8485715
fix string conversion
git-svn-id: https://luan-java.googlecode.com/svn/trunk@11 21e917c8-12df-6dd8-5cb6-c86387c605b9
author | fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9> |
---|---|
date | Thu, 22 Nov 2012 04:37:10 +0000 |
parents | 8896068e0a4b |
children | b7d7069fee58 |
line wrap: on
line diff
--- a/src/luan/interp/ConcatExpr.java Wed Nov 21 09:40:33 2012 +0000 +++ b/src/luan/interp/ConcatExpr.java Thu Nov 22 04:37:10 2012 +0000 @@ -13,15 +13,13 @@ } @Override Object eval(LuaState lua) throws LuaException { - Object v1 = op1.eval(lua); - Object v2 = op2.eval(lua); - check(v1); - check(v2); - return Lua.toString(v1) + Lua.toString(v2); + return toString(op1.eval(lua)) + toString(op2.eval(lua)); } - private static void check(Object v) throws LuaException { - if( !(v instanceof String || v instanceof LuaNumber) ) + private static String toString(Object v) throws LuaException { + String s = Lua.asString(v); + if( s==null ) throw new LuaException( "attempt to concatenate a " + Lua.type(v) + " value" ); + return s; } }