comparison src/luan/LuanState.java @ 1283:503bde9a7c80

add luan.require() and table.call()
author Franklin Schmidt <fschmidt@gmail.com>
date Fri, 21 Dec 2018 09:12:09 -0700
parents 9fa8b8389578
children f41919741100
comparison
equal deleted inserted replaced
1282:2531942abaf3 1283:503bde9a7c80
12 import org.slf4j.Logger; 12 import org.slf4j.Logger;
13 import org.slf4j.LoggerFactory; 13 import org.slf4j.LoggerFactory;
14 import luan.impl.LuanCompiler; 14 import luan.impl.LuanCompiler;
15 import luan.modules.BasicLuan; 15 import luan.modules.BasicLuan;
16 import luan.modules.JavaLuan; 16 import luan.modules.JavaLuan;
17 import luan.modules.PackageLuan;
17 18
18 19
19 public final class LuanState implements LuanCloneable { 20 public final class LuanState implements LuanCloneable {
20 private static final Logger logger = LoggerFactory.getLogger(LuanState.class); 21 private static final Logger logger = LoggerFactory.getLogger(LuanState.class);
21 22
54 public void onClose(Closeable c) { 55 public void onClose(Closeable c) {
55 if( onClose != null ) 56 if( onClose != null )
56 onClose.onClose(c); 57 onClose.onClose(c);
57 } 58 }
58 59
59 public final Object eval(String cmd,Object... args) throws LuanException { 60 public Object eval(String cmd,Object... args) throws LuanException {
60 return Luan.load(cmd,"eval").call(this,args); 61 return Luan.load(cmd,"eval").call(this,args);
61 } 62 }
62 /* 63
63 public final Object eval(String cmd,LuanTable env) throws LuanException { 64 public Object require(String modName) throws LuanException {
64 LuanFunction fn = BasicLuan.load(this,cmd,"eval",env,true); 65 return PackageLuan.require(this,modName);
65 return fn.call(this);
66 } 66 }
67 */
68 67
69 public String toString(Object obj) throws LuanException { 68 public String toString(Object obj) throws LuanException {
70 if( obj instanceof LuanTable ) { 69 if( obj instanceof LuanTable ) {
71 LuanTable tbl = (LuanTable)obj; 70 LuanTable tbl = (LuanTable)obj;
72 return tbl.toStringLuan(); 71 return tbl.toStringLuan();