Mercurial Hosting > luan
annotate src/luan/interp/DivExpr.java @ 35:e51906de0f11
implement metatables
git-svn-id: https://luan-java.googlecode.com/svn/trunk@36 21e917c8-12df-6dd8-5cb6-c86387c605b9
author | fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9> |
---|---|
date | Tue, 18 Dec 2012 07:05:58 +0000 |
parents | 5cf15507d77e |
children | 8a57ebfdfd78 |
rev | line source |
---|---|
7
bca8fc5d928b
work on expressions
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
1 package luan.interp; |
bca8fc5d928b
work on expressions
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2 |
bca8fc5d928b
work on expressions
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3 import luan.Lua; |
bca8fc5d928b
work on expressions
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4 import luan.LuaNumber; |
bca8fc5d928b
work on expressions
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5 import luan.LuaException; |
bca8fc5d928b
work on expressions
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6 |
bca8fc5d928b
work on expressions
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7 |
bca8fc5d928b
work on expressions
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8 final class DivExpr extends BinaryOpExpr { |
bca8fc5d928b
work on expressions
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9 |
bca8fc5d928b
work on expressions
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10 DivExpr(Expr op1,Expr op2) { |
bca8fc5d928b
work on expressions
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
11 super(op1,op2); |
bca8fc5d928b
work on expressions
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
12 } |
bca8fc5d928b
work on expressions
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
13 |
31
5cf15507d77e
separate interpreter from interface
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
11
diff
changeset
|
14 @Override public Object eval(LuaStateImpl lua) throws LuaException { |
35
e51906de0f11
implement metatables
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
31
diff
changeset
|
15 Object o1 = op1.eval(lua); |
e51906de0f11
implement metatables
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
31
diff
changeset
|
16 Object o2 = op2.eval(lua); |
e51906de0f11
implement metatables
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
31
diff
changeset
|
17 LuaNumber n1 = Lua.toNumber(o1); |
e51906de0f11
implement metatables
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
31
diff
changeset
|
18 LuaNumber n2 = Lua.toNumber(o2); |
e51906de0f11
implement metatables
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
31
diff
changeset
|
19 if( n1 != null && n2 != null ) |
e51906de0f11
implement metatables
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
31
diff
changeset
|
20 return new LuaNumber( n1.value() / n2.value() ); |
e51906de0f11
implement metatables
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
31
diff
changeset
|
21 return arithmetic(lua,"__div",o1,o2); |
7
bca8fc5d928b
work on expressions
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
22 } |
bca8fc5d928b
work on expressions
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
23 } |