comparison src/luan/Lua.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
comparison
equal deleted inserted replaced
39:e5bcb1eeafc1 40:e3624b7cd603
24 if( obj instanceof String || obj instanceof LuaNumber ) 24 if( obj instanceof String || obj instanceof LuaNumber )
25 return obj.toString(); 25 return obj.toString();
26 return null; 26 return null;
27 } 27 }
28 28
29 public static String checkString(Object obj) throws LuaException {
30 String s = asString(obj);
31 if( s == null )
32 throw new LuaException( "attempt to use a " + Lua.type(obj) + " as a string" );
33 return s;
34 }
35
36 public static LuaNumber toNumber(Object obj) { 29 public static LuaNumber toNumber(Object obj) {
37 return toNumber(obj,null); 30 return toNumber(obj,null);
38 } 31 }
39 32
40 public static LuaNumber toNumber(Object obj,Integer base) { 33 public static LuaNumber toNumber(Object obj,Integer base) {
50 } catch(NumberFormatException e) {} 43 } catch(NumberFormatException e) {}
51 } 44 }
52 return null; 45 return null;
53 } 46 }
54 47
55 public static LuaNumber checkNumber(Object obj) throws LuaException { 48 public static Object first(Object[] a) {
56 LuaNumber n = toNumber(obj); 49 return a.length==0 ? null : a[0];
57 if( n == null )
58 throw new LuaException( "attempt to perform arithmetic on a " + type(obj) + " value" );
59 return n;
60 }
61
62 public static LuaFunction checkFunction(Object obj) throws LuaException {
63 if( obj instanceof LuaFunction )
64 return (LuaFunction)obj;
65 throw new LuaException( "attempt to call a " + type(obj) + " value" );
66 } 50 }
67 51
68 } 52 }