Mercurial Hosting > luan
comparison core/src/luan/modules/Utils.java @ 646:cdc70de628b5
simplify LuanException
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Tue, 29 Mar 2016 19:58:39 -0600 |
parents | 6ea90dc10375 |
children | a21e9594307d |
comparison
equal
deleted
inserted
replaced
645:859c0dedc8b6 | 646:cdc70de628b5 |
---|---|
6 import java.io.InputStream; | 6 import java.io.InputStream; |
7 import java.io.OutputStream; | 7 import java.io.OutputStream; |
8 import java.io.File; | 8 import java.io.File; |
9 import java.net.URL; | 9 import java.net.URL; |
10 import java.net.MalformedURLException; | 10 import java.net.MalformedURLException; |
11 import luan.LuanState; | |
12 import luan.LuanException; | 11 import luan.LuanException; |
13 import luan.LuanTable; | 12 import luan.LuanTable; |
14 import luan.LuanFunction; | 13 import luan.LuanFunction; |
15 | 14 |
16 | 15 |
17 public final class Utils { | 16 public final class Utils { |
18 private Utils() {} // never | 17 private Utils() {} // never |
19 | 18 |
20 static final int bufSize = 8192; | 19 static final int bufSize = 8192; |
21 | 20 |
22 private static void checkNotNull(LuanState luan,Object v,String expected,int pos) throws LuanException { | 21 private static void checkNotNull(Object v,String expected,int pos) throws LuanException { |
23 if( v == null ) | 22 if( v == null ) |
24 throw new LuanException(luan,"bad argument #"+pos+" ("+expected+" expected, got nil)"); | 23 throw new LuanException("bad argument #"+pos+" ("+expected+" expected, got nil)"); |
25 } | 24 } |
26 | 25 |
27 public static void checkNotNull(LuanState luan,String s,int pos) throws LuanException { | 26 public static void checkNotNull(String s,int pos) throws LuanException { |
28 checkNotNull(luan,s,"string",pos); | 27 checkNotNull(s,"string",pos); |
29 } | 28 } |
30 | 29 |
31 public static void checkNotNull(LuanState luan,String s) throws LuanException { | 30 public static void checkNotNull(String s) throws LuanException { |
32 checkNotNull(luan,s,1); | 31 checkNotNull(s,1); |
33 } | 32 } |
34 | 33 |
35 public static void checkNotNull(LuanState luan,byte[] b,int pos) throws LuanException { | 34 public static void checkNotNull(byte[] b,int pos) throws LuanException { |
36 checkNotNull(luan,b,"binary",pos); | 35 checkNotNull(b,"binary",pos); |
37 } | 36 } |
38 | 37 |
39 public static void checkNotNull(LuanState luan,byte[] b) throws LuanException { | 38 public static void checkNotNull(byte[] b) throws LuanException { |
40 checkNotNull(luan,b,1); | 39 checkNotNull(b,1); |
41 } | 40 } |
42 | 41 |
43 public static void checkNotNull(LuanState luan,LuanTable t,int pos) throws LuanException { | 42 public static void checkNotNull(LuanTable t,int pos) throws LuanException { |
44 checkNotNull(luan,t,"table",pos); | 43 checkNotNull(t,"table",pos); |
45 } | 44 } |
46 | 45 |
47 public static void checkNotNull(LuanState luan,LuanTable t) throws LuanException { | 46 public static void checkNotNull(LuanTable t) throws LuanException { |
48 checkNotNull(luan,t,1); | 47 checkNotNull(t,1); |
49 } | 48 } |
50 | 49 |
51 public static void checkNotNull(LuanState luan,Number n,int pos) throws LuanException { | 50 public static void checkNotNull(Number n,int pos) throws LuanException { |
52 checkNotNull(luan,n,"number",pos); | 51 checkNotNull(n,"number",pos); |
53 } | 52 } |
54 | 53 |
55 public static void checkNotNull(LuanState luan,Number n) throws LuanException { | 54 public static void checkNotNull(Number n) throws LuanException { |
56 checkNotNull(luan,n,1); | 55 checkNotNull(n,1); |
57 } | 56 } |
58 | 57 |
59 public static void checkNotNull(LuanState luan,LuanFunction fn,int pos) throws LuanException { | 58 public static void checkNotNull(LuanFunction fn,int pos) throws LuanException { |
60 checkNotNull(luan,fn,"function",pos); | 59 checkNotNull(fn,"function",pos); |
61 } | 60 } |
62 | 61 |
63 public static void checkNotNull(LuanState luan,LuanFunction fn) throws LuanException { | 62 public static void checkNotNull(LuanFunction fn) throws LuanException { |
64 checkNotNull(luan,fn,1); | 63 checkNotNull(fn,1); |
65 } | 64 } |
66 | 65 |
67 public static String readAll(Reader in) | 66 public static String readAll(Reader in) |
68 throws IOException | 67 throws IOException |
69 { | 68 { |