Mercurial Hosting > luan
comparison core/src/luan/LuanState.java @ 578:60c549d43988
remove LuanState.exception()
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Tue, 14 Jul 2015 17:40:48 -0600 |
parents | 4723d22062ce |
children | f22a09e98b04 |
comparison
equal
deleted
inserted
replaced
577:d7a85fbe15f1 | 578:60c549d43988 |
---|---|
63 LuanFunction fn = BasicLuan.load(this,cmd,"eval",env,true); | 63 LuanFunction fn = BasicLuan.load(this,cmd,"eval",env,true); |
64 return fn.call(this); | 64 return fn.call(this); |
65 } | 65 } |
66 | 66 |
67 | 67 |
68 | |
69 public LuanException exception(Object msg) throws LuanException { | |
70 return new LuanException(this,msg); | |
71 } | |
72 | |
73 public Boolean checkBoolean(Object obj) throws LuanException { | 68 public Boolean checkBoolean(Object obj) throws LuanException { |
74 if( obj instanceof Boolean ) | 69 if( obj instanceof Boolean ) |
75 return (Boolean)obj; | 70 return (Boolean)obj; |
76 throw exception( "attempt to use '"+context()+"' (a " + Luan.type(obj) + " value) as a boolean" ); | 71 throw new LuanException(this, "attempt to use '"+context()+"' (a " + Luan.type(obj) + " value) as a boolean" ); |
77 } | 72 } |
78 | 73 |
79 public Boolean checkBoolean(Object obj,LuanElement el) throws LuanException { | 74 public Boolean checkBoolean(Object obj,LuanElement el) throws LuanException { |
80 push(el,null); | 75 push(el,null); |
81 try { | 76 try { |
86 } | 81 } |
87 | 82 |
88 public String checkString(Object obj) throws LuanException { | 83 public String checkString(Object obj) throws LuanException { |
89 if( obj instanceof String ) | 84 if( obj instanceof String ) |
90 return (String)obj; | 85 return (String)obj; |
91 throw exception( "attempt to use '"+context()+"' (a " + Luan.type(obj) + " value) as a string" ); | 86 throw new LuanException(this, "attempt to use '"+context()+"' (a " + Luan.type(obj) + " value) as a string" ); |
92 } | 87 } |
93 | 88 |
94 public LuanFunction checkFunction(Object obj) throws LuanException { | 89 public LuanFunction checkFunction(Object obj) throws LuanException { |
95 if( obj instanceof LuanFunction ) | 90 if( obj instanceof LuanFunction ) |
96 return (LuanFunction)obj; | 91 return (LuanFunction)obj; |
97 throw exception( "attempt to call '"+context()+"' (a " + Luan.type(obj) + " value)" ); | 92 throw new LuanException(this, "attempt to call '"+context()+"' (a " + Luan.type(obj) + " value)" ); |
98 } | 93 } |
99 | 94 |
100 public boolean isLessThan(Object o1,Object o2) throws LuanException { | 95 public boolean isLessThan(Object o1,Object o2) throws LuanException { |
101 if( o1 instanceof Number && o2 instanceof Number ) { | 96 if( o1 instanceof Number && o2 instanceof Number ) { |
102 Number n1 = (Number)o1; | 97 Number n1 = (Number)o1; |
109 return s1.compareTo(s2) < 0; | 104 return s1.compareTo(s2) < 0; |
110 } | 105 } |
111 LuanFunction fn = getBinHandler("__lt",o1,o2); | 106 LuanFunction fn = getBinHandler("__lt",o1,o2); |
112 if( fn != null ) | 107 if( fn != null ) |
113 return checkBoolean( Luan.first(fn.call(this,new Object[]{o1,o2})) ); | 108 return checkBoolean( Luan.first(fn.call(this,new Object[]{o1,o2})) ); |
114 throw exception( "attempt to compare " + Luan.type(o1) + " with " + Luan.type(o2) ); | 109 throw new LuanException(this, "attempt to compare " + Luan.type(o1) + " with " + Luan.type(o2) ); |
115 } | 110 } |
116 | 111 |
117 public String toString(Object obj) throws LuanException { | 112 public String toString(Object obj) throws LuanException { |
118 if( obj instanceof LuanTable ) { | 113 if( obj instanceof LuanTable ) { |
119 LuanTable tbl = (LuanTable)obj; | 114 LuanTable tbl = (LuanTable)obj; |
142 LuanTable tbl = (LuanTable)obj; | 137 LuanTable tbl = (LuanTable)obj; |
143 return tbl.get(this,key); | 138 return tbl.get(this,key); |
144 } | 139 } |
145 if( obj != null && hasJava() ) | 140 if( obj != null && hasJava() ) |
146 return JavaLuan.__index(this,obj,key,false); | 141 return JavaLuan.__index(this,obj,key,false); |
147 throw exception( "attempt to index a " + Luan.type(obj) + " value in '"+context()+"'" ); | 142 throw new LuanException(this, "attempt to index a " + Luan.type(obj) + " value in '"+context()+"'" ); |
148 } | 143 } |
149 | 144 |
150 public String context() { | 145 public String context() { |
151 return stackTrace.get(stackTrace.size()-1).call.text(); | 146 return stackTrace.get(stackTrace.size()-1).call.text(); |
152 } | 147 } |
181 } | 176 } |
182 /* | 177 /* |
183 public Number checkNumber(Object obj) throws LuanException { | 178 public Number checkNumber(Object obj) throws LuanException { |
184 if( obj instanceof Number ) | 179 if( obj instanceof Number ) |
185 return (Number)obj; | 180 return (Number)obj; |
186 throw exception( "attempt to perform arithmetic on '"+context()+"' (a " + Luan.type(obj) + " value)" ); | 181 throw new LuanException(this, "attempt to perform arithmetic on '"+context()+"' (a " + Luan.type(obj) + " value)" ); |
187 } | 182 } |
188 */ | 183 */ |
189 } | 184 } |