Mercurial Hosting > luan
diff src/luan/Lua.java @ 3:7a2cdbc5767f
add LuaState
git-svn-id: https://luan-java.googlecode.com/svn/trunk@4 21e917c8-12df-6dd8-5cb6-c86387c605b9
author | fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9> |
---|---|
date | Fri, 16 Nov 2012 05:23:12 +0000 |
parents | 4da26b11d12a |
children | bca8fc5d928b |
line wrap: on
line diff
--- a/src/luan/Lua.java Wed Nov 14 08:53:25 2012 +0000 +++ b/src/luan/Lua.java Fri Nov 16 05:23:12 2012 +0000 @@ -21,7 +21,11 @@ return obj.toString(); } - public static LuaNumber toNumber(Object obj) throws LuaException { + public static String checkString(Object obj) { + return toString(obj); + } + + public static LuaNumber toNumber(Object obj) { if( obj instanceof LuaNumber ) return (LuaNumber)obj; if( obj instanceof String ) { @@ -30,10 +34,17 @@ return new LuaNumber( Double.parseDouble(s) ); } catch(NumberFormatException e) {} } - throw new LuaException( "attempt to perform arithmetic on a " + type(obj) + " value" ); + return null; } - public static LuaFunction toFunction(Object obj) throws LuaException { + public static LuaNumber checkNumber(Object obj) throws LuaException { + LuaNumber n = toNumber(obj); + if( n == null ) + throw new LuaException( "attempt to perform arithmetic on a " + type(obj) + " value" ); + return n; + } + + public static LuaFunction checkFunction(Object obj) throws LuaException { if( obj instanceof LuaFunction ) return (LuaFunction)obj; throw new LuaException( "attempt to call a " + type(obj) + " value" );