Mercurial Hosting > luan
view src/luan/Lua.java @ 2:4da26b11d12a
start interp
git-svn-id: https://luan-java.googlecode.com/svn/trunk@3 21e917c8-12df-6dd8-5cb6-c86387c605b9
author | fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9> |
---|---|
date | Wed, 14 Nov 2012 08:53:25 +0000 |
parents | 2df768b926aa |
children | 7a2cdbc5767f |
line wrap: on
line source
package luan; public class Lua { public static String type(Object obj) { if( obj == null ) return "nil"; if( obj instanceof String ) return "string"; if( obj instanceof Boolean ) return "boolean"; if( obj instanceof LuaNumber ) return "number"; return "userdata"; } public static String toString(Object obj) { if( obj == null ) return "nil"; return obj.toString(); } public static LuaNumber toNumber(Object obj) throws LuaException { if( obj instanceof LuaNumber ) return (LuaNumber)obj; if( obj instanceof String ) { String s = (String)obj; try { return new LuaNumber( Double.parseDouble(s) ); } catch(NumberFormatException e) {} } throw new LuaException( "attempt to perform arithmetic on a " + type(obj) + " value" ); } public static LuaFunction toFunction(Object obj) throws LuaException { if( obj instanceof LuaFunction ) return (LuaFunction)obj; throw new LuaException( "attempt to call a " + type(obj) + " value" ); } }