Mercurial Hosting > luan
comparison src/luan/Luan.java @ 1563:8fbcc4747091
remove LuanFunction.luan
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Mon, 09 Nov 2020 01:37:57 -0700 |
parents | b89212fd04b5 |
children | c922446f53aa |
comparison
equal
deleted
inserted
replaced
1562:b89212fd04b5 | 1563:8fbcc4747091 |
---|---|
67 public Map registry() { | 67 public Map registry() { |
68 return registry; | 68 return registry; |
69 } | 69 } |
70 | 70 |
71 public Object eval(String cmd,Object... args) throws LuanException { | 71 public Object eval(String cmd,Object... args) throws LuanException { |
72 return load(cmd,"eval",false).call(args); | 72 return load(cmd,"eval",false).call(this,args); |
73 } | 73 } |
74 | 74 |
75 public Object require(String modName) throws LuanException { | 75 public Object require(String modName) throws LuanException { |
76 return PackageLuan.require(this,modName); | 76 return PackageLuan.require(this,modName); |
77 } | 77 } |
78 | 78 |
79 public static String luanToString(Object obj) throws LuanException { | 79 public String luanToString(Object obj) throws LuanException { |
80 if( obj instanceof LuanTable ) { | 80 if( obj instanceof LuanTable ) { |
81 LuanTable tbl = (LuanTable)obj; | 81 LuanTable tbl = (LuanTable)obj; |
82 return tbl.toStringLuan(); | 82 return tbl.toStringLuan(this); |
83 } | 83 } |
84 if( obj == null ) | 84 if( obj == null ) |
85 return "nil"; | 85 return "nil"; |
86 if( obj instanceof Number ) | 86 if( obj instanceof Number ) |
87 return Luan.toString((Number)obj); | 87 return Luan.toString((Number)obj); |
99 return JavaLuan.__index(this,obj,key); | 99 return JavaLuan.__index(this,obj,key); |
100 throw new LuanException("attempt to index a " + Luan.type(obj) + " value" ); | 100 throw new LuanException("attempt to index a " + Luan.type(obj) + " value" ); |
101 } | 101 } |
102 | 102 |
103 | 103 |
104 public static boolean isLessThan(Object o1,Object o2) throws LuanException { | 104 public boolean isLessThan(Object o1,Object o2) throws LuanException { |
105 if( o1 instanceof Number && o2 instanceof Number ) { | 105 if( o1 instanceof Number && o2 instanceof Number ) { |
106 Number n1 = (Number)o1; | 106 Number n1 = (Number)o1; |
107 Number n2 = (Number)o2; | 107 Number n2 = (Number)o2; |
108 return n1.doubleValue() < n2.doubleValue(); | 108 return n1.doubleValue() < n2.doubleValue(); |
109 } | 109 } |
112 String s2 = (String)o2; | 112 String s2 = (String)o2; |
113 return s1.compareTo(s2) < 0; | 113 return s1.compareTo(s2) < 0; |
114 } | 114 } |
115 LuanFunction fn = getBinHandler("__lt",o1,o2); | 115 LuanFunction fn = getBinHandler("__lt",o1,o2); |
116 if( fn != null ) | 116 if( fn != null ) |
117 return Luan.checkBoolean( Luan.first(fn.call(o1,o2)) ); | 117 return Luan.checkBoolean( Luan.first(fn.call(this,o1,o2)) ); |
118 throw new LuanException( "attempt to compare " + Luan.type(o1) + " with " + Luan.type(o2) ); | 118 throw new LuanException( "attempt to compare " + Luan.type(o1) + " with " + Luan.type(o2) ); |
119 } | 119 } |
120 | 120 |
121 public static LuanFunction getBinHandler(String op,Object o1,Object o2) throws LuanException { | 121 public static LuanFunction getBinHandler(String op,Object o1,Object o2) throws LuanException { |
122 if( o1 instanceof LuanTable ) { | 122 if( o1 instanceof LuanTable ) { |
170 // static | 170 // static |
171 | 171 |
172 public static void main(String[] args) throws LuanException { | 172 public static void main(String[] args) throws LuanException { |
173 Luan luan = new Luan(); | 173 Luan luan = new Luan(); |
174 LuanFunction fn = loadClasspath(luan,"luan/cmd_line.luan"); | 174 LuanFunction fn = loadClasspath(luan,"luan/cmd_line.luan"); |
175 fn.call((Object[])args); | 175 fn.call(luan,(Object[])args); |
176 } | 176 } |
177 | 177 |
178 public static LuanFunction loadClasspath(Luan luan,String classpath) | 178 public static LuanFunction loadClasspath(Luan luan,String classpath) |
179 throws LuanException | 179 throws LuanException |
180 { | 180 { |