Mercurial Hosting > luan
comparison core/src/luan/impl/$Luan.java @ 649:37f0cf43f191
UnaryExpr now compiled
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Wed, 30 Mar 2016 22:42:27 -0600 |
parents | e387e4021afe |
children | d658eab7bf4c |
comparison
equal
deleted
inserted
replaced
648:e387e4021afe | 649:37f0cf43f191 |
---|---|
1 package luan.impl; | 1 package luan.impl; |
2 | 2 |
3 import java.util.List; | 3 import java.util.List; |
4 import java.util.ArrayList; | 4 import java.util.ArrayList; |
5 import luan.Luan; | 5 import luan.Luan; |
6 import luan.LuanState; | |
6 import luan.LuanTable; | 7 import luan.LuanTable; |
8 import luan.LuanFunction; | |
7 import luan.LuanException; | 9 import luan.LuanException; |
8 | 10 |
9 | 11 |
10 public final class $Luan { | 12 public final class $Luan { |
11 private $Luan() {} // never | 13 private $Luan() {} // never |
26 | 28 |
27 public static Object first(Object obj) { | 29 public static Object first(Object obj) { |
28 return Luan.first(obj); | 30 return Luan.first(obj); |
29 } | 31 } |
30 | 32 |
31 public static int len(LuanStateImpl luan,Object o) throws LuanException { | 33 public static int len(LuanState luan,Object o) throws LuanException { |
32 if( o instanceof String ) { | 34 if( o instanceof String ) { |
33 String s = (String)o; | 35 String s = (String)o; |
34 return s.length(); | 36 return s.length(); |
35 } | 37 } |
36 if( o instanceof byte[] ) { | 38 if( o instanceof byte[] ) { |
41 LuanTable t = (LuanTable)o; | 43 LuanTable t = (LuanTable)o; |
42 return t.length(luan); | 44 return t.length(luan); |
43 } | 45 } |
44 throw new LuanException( "attempt to get length of a " + Luan.type(o) + " value" ); | 46 throw new LuanException( "attempt to get length of a " + Luan.type(o) + " value" ); |
45 } | 47 } |
48 | |
49 public static Object unm(LuanState luan,Object o) throws LuanException { | |
50 if( o instanceof Number ) | |
51 return -((Number)o).doubleValue(); | |
52 if( o instanceof LuanTable ) { | |
53 LuanFunction fn = Luan.getHandlerFunction("__unm",(LuanTable)o); | |
54 if( fn != null ) { | |
55 return Luan.first(fn.call(luan,new Object[]{o})); | |
56 } | |
57 } | |
58 throw new LuanException("attempt to perform arithmetic on a "+Luan.type(o)+" value"); | |
59 } | |
60 | |
61 public static Boolean not(Object o) throws LuanException { | |
62 return !Luan.checkBoolean(o); | |
63 } | |
64 | |
46 } | 65 } |