01Scoper = {}
02
03Scoper.get_scope = function(optional_locals_scope = null)
04 scope = {}
05
06 scope.map = map
07 scope.list = list
08 scope.number = number
09 scope.string = string
10 scope.globals = globals
11 if optional_locals_scope == null then
12 scope.locals = {}
13 else
14 scope.locals = optional_locals_scope
15 end if
16
17 return scope
18end function
19
20Scoper.shallow_copy = function(obj1, obj2)
21 for i in obj2.indexes
22 obj1[@i] = @obj2[@i]
23 end for
24end function
25
26Scoper.transfer_scope = function(scope)
27 self.shallow_copy(map, scope.map)
28 self.shallow_copy(list, scope.list)
29 self.shallow_copy(number, scope.number)
30 self.shallow_copy(string, scope.string)
31 self.shallow_copy(globals, scope.globals)
32end function
33
34
35Meta = {}
36Meta.shell = get_shell
37Meta.computer = Meta.shell.host_computer
38Meta.prepend_code = Meta.computer.File("/home/me/projects/igs/boilerplates/prepend.src").get_content
40Meta.append_code = Meta.computer.File("/home/me/projects/igs/boilerplates/append.src").get_content
42
43Meta.init = function(build_full_path = "/home/guest/evalscript.src")
46 self.build_full_path = build_full_path
47 self.build_path = self.build_full_path.split("/")[0:-1].join("/")
48 self.build_name = self.build_full_path.split("/")[-1]
49 self.build_bin_name = self.build_name.split(".")[0]
50 self.build_bin_full_path = self.build_path + "/" + self.build_bin_name
51end function
52
53Meta.eval = function(code, optional_locals_scope = null)
54 eval_script_code = self.prepend_code + char(10) + code + char(10) + self.append_code
55
56 self.computer.touch(self.build_path, self.build_name)
57 eval_script = self.computer.File(self.build_full_path)
58
59 eval_script.set_content(eval_script_code)
60 compiler_out = get_shell.build(self.build_full_path, self.build_path)
61 if compiler_out then
62 print compiler_out
63 return
64 end if
65
66 get_custom_object.parent_scope = Scoper.get_scope(optional_locals_scope)
67 get_shell.launch(self.build_bin_full_path)
68 if get_custom_object.hasIndex("child_scope") then Scoper.transfer_scope(get_custom_object.child_scope)
69end function
70
71Meta.console = function(optional_locals_scope = null)
72 prompt_code = function(line = 0)
73 code = user_input("igs("+line+")> ")
74 if code == "continue" then return 0
75 if code.len > 0 and code.values[-1] == char(92) then
76 return code[0:-1] + char(10) + prompt_code(line + 1)
77 end if
78 return code
79 end function
80
81 while true
82 arbitrary_code = prompt_code
83 if not arbitrary_code then return
84
85 self.eval(arbitrary_code, optional_locals_scope)
86 end while
87end function