Mercurial Hosting > luan
diff src/luan/Lua.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 | bca8fc5d928b |
children | e51906de0f11 |
line wrap: on
line diff
--- a/src/luan/Lua.java Wed Nov 21 09:40:33 2012 +0000 +++ b/src/luan/Lua.java Thu Nov 22 04:37:10 2012 +0000 @@ -25,8 +25,17 @@ return obj.toString(); } - public static String checkString(Object obj) { - return toString(obj); + public static String asString(Object obj) { + if( obj instanceof String || obj instanceof LuaNumber ) + return obj.toString(); + return null; + } + + public static String checkString(Object obj) throws LuaException { + String s = asString(obj); + if( s == null ) + throw new LuaException( "attempt to use a " + Lua.type(obj) + " as a string" ); + return s; } public static LuaNumber toNumber(Object obj) {