Files

igs.src
  • import_code("/home/me/projects/igs/meta.src")
  • input_code = function(line = 0)
  • code = user_input("igs("+line+")> ")
  • if code.len > 0 and code.values[-1] == char(92) then
  • return code[0:-1] + char(10) + input_code(line + 1)
  • end if
  • return code
  • end function
  • while true
  • arbitrary_code = input_code
  • Meta.init()
  • Meta.eval(arbitrary_code)
  • end while
  • Meta.console
meta.src
  • Scoper = {}
  • Scoper.get_scope = function()
  • scope = {}
  • scope.map = map
  • scope.list = list
  • scope.number = number
  • scope.string = string
  • scope.globals = globals
  • return scope
  • end function
  • Scoper.shallow_copy = function(obj1, obj2)
  • for i in obj2.indexes
  • obj1[@i] = @obj2[@i]
  • end for
  • end function
  • Scoper.transfer_scope = function(scope)
  • self.shallow_copy(map, scope.map)
  • self.shallow_copy(list, scope.list)
  • self.shallow_copy(number, scope.number)
  • self.shallow_copy(string, scope.string)
  • self.shallow_copy(globals, scope.globals)
  • end function
  • Meta = {}
  • Meta.shell = get_shell
  • Meta.computer = Meta.shell.host_computer
  • // PREPEND_MARK
  • Meta.prepend_code = Meta.computer.File("/home/me/projects/igs/boilerplates/prepend.src").get_content
  • // APPEND_MARK
  • Meta.append_code = Meta.computer.File("/home/me/projects/igs/boilerplates/append.src").get_content
  • // required options:
  • // build_full_path, example /home/me/evals/evalscript.src
  • Meta.init = function(build_full_path = "/home/guest/evalscript.src")
  • self.build_full_path = build_full_path
  • self.build_path = self.build_full_path.split("/")[0:-1].join("/")
  • self.build_name = self.build_full_path.split("/")[-1]
  • self.build_bin_name = self.build_name.split(".")[0]
  • self.build_bin_full_path = self.build_path + "/" + self.build_bin_name
  • end function
  • Meta.eval = function(code)
  • eval_script_code = self.prepend_code + char(10) + code + char(10) + self.append_code
  • self.computer.touch(self.build_path, self.build_name)
  • eval_script = self.computer.File(self.build_full_path)
  • eval_script.set_content(eval_script_code)
  • get_shell.build(self.build_full_path, self.build_path)
  • compiler_out = get_shell.build(self.build_full_path, self.build_path)
  • if compiler_out then
  • print compiler_out
  • return
  • end if
  • get_custom_object.parent_scope = Scoper.get_scope
  • get_shell.launch(self.build_bin_full_path)
  • Scoper.transfer_scope(get_custom_object.child_scope)
  • if get_custom_object.hasIndex("child_scope") then Scoper.transfer_scope(get_custom_object.child_scope)
  • end function
  • Meta.console = function()
  • input_code = function(line = 0)
  • code = user_input("igs("+line+")> ")
  • if code.len > 0 and code.values[-1] == char(92) then
  • return code[0:-1] + char(10) + input_code(line + 1)
  • end if
  • return code
  • end function
  • while true
  • arbitrary_code = input_code
  • self.init()
  • self.eval(arbitrary_code)
  • end while
  • end function
static/meta.src
  • Scoper = {}
  • Scoper.get_scope = function()
  • scope = {}
  • scope.map = map
  • scope.list = list
  • scope.number = number
  • scope.string = string
  • scope.globals = globals
  • return scope
  • end function
  • Scoper.shallow_copy = function(obj1, obj2)
  • for i in obj2.indexes
  • obj1[@i] = @obj2[@i]
  • end for
  • end function
  • Scoper.transfer_scope = function(scope)
  • self.shallow_copy(map, scope.map)
  • self.shallow_copy(list, scope.list)
  • self.shallow_copy(number, scope.number)
  • self.shallow_copy(string, scope.string)
  • self.shallow_copy(globals, scope.globals)
  • end function
  • Meta = {}
  • Meta.shell = get_shell
  • Meta.computer = Meta.shell.host_computer
  • // PREPEND_MARK
  • Meta.prepend_code = "get_scope = function()
  • scope = {}
  • scope.map = map
  • scope.list = list
  • scope.number = number
  • scope.string = string
  • scope.globals = globals
  • return scope
  • end function
  • shallow_copy = function(obj1, obj2)
  • for i in obj2.indexes
  • obj1[@i] = @obj2[@i]
  • end for
  • end function
  • transfer_scope = function(scope)
  • shallow_copy(map, scope.map)
  • shallow_copy(list, scope.list)
  • shallow_copy(number, scope.number)
  • shallow_copy(string, scope.string)
  • shallow_copy(globals, scope.globals)
  • end function
  • parent_scope = get_custom_object.parent_scope
  • transfer_scope(parent_scope)
  • "
  • // APPEND_MARK
  • Meta.append_code = "get_custom_object.child_scope = get_scope"
  • // required options:
  • // build_full_path, example /home/me/evals/evalscript.src
  • Meta.init = function(build_full_path = "/home/guest/evalscript.src")
  • self.build_full_path = build_full_path
  • self.build_path = self.build_full_path.split("/")[0:-1].join("/")
  • self.build_name = self.build_full_path.split("/")[-1]
  • self.build_bin_name = self.build_name.split(".")[0]
  • self.build_bin_full_path = self.build_path + "/" + self.build_bin_name
  • end function
  • Meta.eval = function(code)
  • eval_script_code = self.prepend_code + char(10) + code + char(10) + self.append_code
  • self.computer.touch(self.build_path, self.build_name)
  • eval_script = self.computer.File(self.build_full_path)
  • eval_script.set_content(eval_script_code)
  • get_shell.build(self.build_full_path, self.build_path)
  • compiler_out = get_shell.build(self.build_full_path, self.build_path)
  • if compiler_out then
  • print compiler_out
  • return
  • end if
  • get_custom_object.parent_scope = Scoper.get_scope
  • get_shell.launch(self.build_bin_full_path)
  • Scoper.transfer_scope(get_custom_object.child_scope)
  • if get_custom_object.hasIndex("child_scope") then Scoper.transfer_scope(get_custom_object.child_scope)
  • end function
  • Meta.console = function()
  • input_code = function(line = 0)
  • code = user_input("igs("+line+")> ")
  • if code.len > 0 and code.values[-1] == char(92) then
  • return code[0:-1] + char(10) + input_code(line + 1)
  • end if
  • return code
  • end function
  • while true
  • arbitrary_code = input_code
  • self.init()
  • self.eval(arbitrary_code)
  • end while
  • end function