Mercurial Hosting > luan
comparison 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 |
comparison
equal
deleted
inserted
replaced
2:4da26b11d12a | 3:7a2cdbc5767f |
---|---|
19 if( obj == null ) | 19 if( obj == null ) |
20 return "nil"; | 20 return "nil"; |
21 return obj.toString(); | 21 return obj.toString(); |
22 } | 22 } |
23 | 23 |
24 public static LuaNumber toNumber(Object obj) throws LuaException { | 24 public static String checkString(Object obj) { |
25 return toString(obj); | |
26 } | |
27 | |
28 public static LuaNumber toNumber(Object obj) { | |
25 if( obj instanceof LuaNumber ) | 29 if( obj instanceof LuaNumber ) |
26 return (LuaNumber)obj; | 30 return (LuaNumber)obj; |
27 if( obj instanceof String ) { | 31 if( obj instanceof String ) { |
28 String s = (String)obj; | 32 String s = (String)obj; |
29 try { | 33 try { |
30 return new LuaNumber( Double.parseDouble(s) ); | 34 return new LuaNumber( Double.parseDouble(s) ); |
31 } catch(NumberFormatException e) {} | 35 } catch(NumberFormatException e) {} |
32 } | 36 } |
33 throw new LuaException( "attempt to perform arithmetic on a " + type(obj) + " value" ); | 37 return null; |
34 } | 38 } |
35 | 39 |
36 public static LuaFunction toFunction(Object obj) throws LuaException { | 40 public static LuaNumber checkNumber(Object obj) throws LuaException { |
41 LuaNumber n = toNumber(obj); | |
42 if( n == null ) | |
43 throw new LuaException( "attempt to perform arithmetic on a " + type(obj) + " value" ); | |
44 return n; | |
45 } | |
46 | |
47 public static LuaFunction checkFunction(Object obj) throws LuaException { | |
37 if( obj instanceof LuaFunction ) | 48 if( obj instanceof LuaFunction ) |
38 return (LuaFunction)obj; | 49 return (LuaFunction)obj; |
39 throw new LuaException( "attempt to call a " + type(obj) + " value" ); | 50 throw new LuaException( "attempt to call a " + type(obj) + " value" ); |
40 } | 51 } |
41 | 52 |