1 module orelang.operator.LoadOperator;
2 import orelang.operator.IOperator,
3        orelang.Interpreter,
4        orelang.Transpiler,
5        orelang.Engine,
6        orelang.Value;
7 import std.algorithm,
8        std.array,
9        std.file;
10 
11 class LoadOperator : IOperator {
12   /**
13    * call
14    */
15   public Value call(Engine engine, Value[] args) {
16     string[] loaded;
17     Value eargs0 = engine.eval(args[0]);
18     Interpreter itpr = new Interpreter(engine);
19 
20     if (eargs0.type == ValueType.Array) {
21       args = eargs0.getArray;
22     }
23 
24     string[] fpaths = args.map!(arg => (engine.eval(arg)).getString ~ ".ore").array;
25 
26     foreach (fpath; fpaths) {
27       if (!exists(fpath)) {
28         throw new Exception("No such file - " ~ fpath);
29       } else {
30         itpr.executer(readText(fpath));
31         loaded ~= fpath;
32       }
33     }
34 
35     Value[] ret;
36 
37     foreach (load; loaded) {
38       ret ~= new Value(load);
39     }
40 
41     return new Value(ret);
42   }
43 }