Mercurial Hosting > luan
comparison src/luan/interp/LenExpr.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 |
---|---|
3 import luan.Lua; | 3 import luan.Lua; |
4 import luan.LuaNumber; | 4 import luan.LuaNumber; |
5 import luan.LuaTable; | 5 import luan.LuaTable; |
6 import luan.LuaFunction; | 6 import luan.LuaFunction; |
7 import luan.LuaException; | 7 import luan.LuaException; |
8 import luan.LuaSource; | |
8 | 9 |
9 | 10 |
10 final class LenExpr extends UnaryOpExpr { | 11 final class LenExpr extends UnaryOpExpr { |
11 | 12 |
12 LenExpr(Expr op) { | 13 LenExpr(LuaSource.Element se,Expr op) { |
13 super(op); | 14 super(se,op); |
14 } | 15 } |
15 | 16 |
16 @Override public Object eval(LuaStateImpl lua) throws LuaException { | 17 @Override public Object eval(LuaStateImpl lua) throws LuaException { |
17 Object o = op.eval(lua); | 18 Object o = op.eval(lua); |
18 if( o instanceof String ) { | 19 if( o instanceof String ) { |
19 String s = (String)o; | 20 String s = (String)o; |
20 return new LuaNumber( s.length() ); | 21 return new LuaNumber( s.length() ); |
21 } | 22 } |
22 LuaFunction fn = lua.getHandlerFunction("__len",o); | 23 LuaFunction fn = lua.getHandlerFunction(se,"__len",o); |
23 if( fn != null ) | 24 if( fn != null ) |
24 return Utils.first(fn.call(lua,o)); | 25 return Lua.first(lua.call(fn,se,"__len",o)); |
25 if( o instanceof LuaTable ) { | 26 if( o instanceof LuaTable ) { |
26 LuaTable t = (LuaTable)o; | 27 LuaTable t = (LuaTable)o; |
27 return t.length(); | 28 return t.length(); |
28 } | 29 } |
29 throw new LuaException( "attempt to get length of a " + Lua.type(o) + " value" ); | 30 throw new LuaException( lua, se, "attempt to get length of a " + Lua.type(o) + " value" ); |
30 } | 31 } |
31 } | 32 } |