def run(self):
    cmd = []

    filename = self.findLuaFile()

    if filename is None:
      sublime.error_message("Can't find an open '.lua' file to determine the location of 'main.lua'")
      return
    mainlua = _corona_utils.ResolveMainLua(filename)
    if mainlua is None:
      sublime.error_message("Can't locate 'main.lua' for this project (try opening it in an editor tab)")
      return

    simulator_path, simulator_flags, simulator_version = _corona_utils.GetSimulatorCmd(mainlua)

    cmd = [simulator_path]
    cmd += simulator_flags
    cmd.append(mainlua)

    print(_corona_utils.PACKAGE_NAME + ": Running: " + str(cmd))

    # Save our changes before we run
    self.window.run_command("save_all")

    # Supplying the "file_regex" allows users to double-click errors and warnings in the
    # build panel and go to that point in the code
    if sublime.platform() == 'osx':
      self.window.run_command('exec', {'cmd': cmd, "file_regex": "^[^/]*(/[^:]*):([0-9]+):([0-9]*)(.*)$" })
    else: # windows
      self.window.run_command('exec', {'cmd': cmd, "file_regex": "(?i)^[^C-Z]*([C-Z]:[^:]*):([0-9]+):([0-9]*)(.*)$" })
예제 #2
0
  def run(self):
    cmd = []

    filename = self.findLuaFile()

    if filename is None:
      sublime.error_message("Can't find an open '.lua' file to determine the location of 'main.lua'")
      return
    mainlua = _corona_utils.ResolveMainLua(filename)
    if mainlua is None:
      sublime.error_message("Can't locate 'main.lua' for this project (try opening it in an editor tab)")
      return

    simulator_path, simulator_flags, simulator_version = _corona_utils.GetSimulatorCmd(mainlua)

    print(_corona_utils.PACKAGE_NAME + ": Running: " + str(cmd))

    # Exit the debugger if it's running
    self.window.run_command("corona_debugger", {"cmd": "exit"})

    # Save our changes before we run
    self.window.run_command("save_all")

    # Supplying the "file_regex" allows users to double-click errors and warnings in the
    # build panel and go to that point in the code
    if sublime.platform() == 'osx':
      # On OS X, running the command as a string argument to the shell allows
      # the "corona_sdk_simulator_show_console" option to work (otherwise
      # stdout gets screwed up and hangs)
      try:  # py3
          from shlex import quote
      except ImportError:  # py2
          from pipes import quote

      cmd = [ simulator_path ]
      cmd += simulator_flags
      cmd.append(mainlua)
      # quote command arguments
      cmdStr = ' '.join([ quote(arg) for arg in cmd ])
      self.window.run_command('exec', {'cmd': cmdStr, "file_regex": "^(?:ERROR: |WARNING: )*(/[^:]*):([0-9]+):([0-9]?)(.*)$", "shell": "/bin/sh"})
    else: # windows
      cmd = [ simulator_path ]
      cmd += simulator_flags
      cmd.append(mainlua)
      self.window.run_command('exec', {'cmd': cmd, "file_regex": "(?i)^(?:ERROR: |WARNING: )[^C-Z]*([C-Z]:[^:]*):([0-9]+):([0-9]*)(.*)$" })
    def run(self,
            cmd=None,
            arg_filename=None,
            arg_lineno=None,
            arg_toggle=True):
        debug("CoronaDebuggerCommand: " + cmd)
        global coronaDbg
        global corona_sdk_version
        global corona_sdk_debug
        self.view = self.window.active_view()

        if self.view is None:
            sublime.error_message(
                "Cannot find an active view.  You may need to restart Sublime Text."
            )
            return

        # if we aren't started yet and a step is asked for, do a start
        if (coronaDbg is None or
                not coronaDbg.isRunning()) and cmd in ['run', 'step', 'over']:
            cmd = "start"

        if cmd == "start":
            if corona_sdk_debug:
                # Show Sublime Console
                self.window.run_command("show_panel", {"panel": "console"})
                # sublime.log_commands(True)

            # Hide the build panel (since the "Console" pane duplicates it)
            self.window.run_command("hide_panel", {"panel": "output.exec"})

            if coronaDbg is not None:
                debug("Cleaning up debugger thread")
                coronaDbg.join()
                coronaDbg = None

            self.saved_layout = self.window.get_layout()

            # Figure out where the PUT and the Simulator are
            filename = self.window.active_view().file_name()
            if filename is None or not filename.endswith(".lua"):
                filename = None
                # No current .lua file, see if we have one open
                for view in self.window.views():
                    if view.file_name() and view.file_name().endswith(".lua"):
                        if filename is None or not filename.endswith(
                                "main.lua"
                        ):  # prefer a 'main.lua' if there is one
                            filename = view.file_name()

            if filename is None:
                sublime.error_message(
                    "Can't find an open '.lua' file to determine the location of 'main.lua'"
                )
                return
            mainlua = _corona_utils.ResolveMainLua(filename)
            if mainlua is None:
                sublime.error_message(
                    "Can't locate 'main.lua' for this project (try opening it in an editor tab)"
                )
                return
            self.window.open_file(
                mainlua
            )  # make sure main.lua is open as that's the first place we'll stop
            projectDir = os.path.dirname(mainlua)
            if not projectDir:
                sublime.error_message(
                    "Cannot find 'main.lua' for '" + self.view.file_name() +
                    "'.  This does not look like a Corona app")
                return

            dbg_path, dbg_flags, dbg_version = _corona_utils.GetSimulatorCmd(
                mainlua, True)
            dbg_cmd = [dbg_path]
            dbg_cmd += dbg_flags
            dbg_cmd.append(mainlua)
            debug("debugger cmd: " + str(dbg_cmd))

            debug("dbg_version: " + str(dbg_version))
            if dbg_version:
                corona_sdk_version = dbg_version.rpartition(".")[2]
                debug("corona_sdk_version: " + str(corona_sdk_version))

            global consoleOutputQ, variablesOutputQ, luaStackOutputQ, debuggerCmdQ
            consoleOutputQ = coronaQueue.Queue()
            variablesOutputQ = coronaQueue.Queue()
            luaStackOutputQ = coronaQueue.Queue()
            debuggerCmdQ = coronaQueue.Queue()

            coronaDbg = CoronaDebuggerThread(projectDir, self.debuggerFinished)
            if coronaDbg.setup():
                if self.window.num_groups() == 1:
                    self.initializeWindowPanes()
                else:
                    # Clear the existing windows
                    variables_output(' ')
                    stack_output(' ')
                self.window.focus_group(0)
                RunSubprocess(dbg_cmd, self.window)
                coronaDbg.start()

        elif cmd == "restart":
            if coronaDbg is not None:
                self.window.run_command("corona_debugger", {"cmd": "exit"})
            sublime.set_timeout(
                lambda: self.window.run_command("corona_debugger",
                                                {"cmd": "start"}), 0)

        elif cmd == "exit":
            debugger_status("exiting debugger...")
            StopSubprocess()
            if coronaDbg is None:
                self.closeWindowPanes()
            else:
                coronaDbg.doCommand(cmd)
                coronaDbg.stop()
                coronaDbg.join()
                coronaDbg = None
        elif cmd in ["run", "step", "over"]:
            coronaDbg.doCommand(cmd)
            coronaDbg.doCommand('backtrace')
            if not corona_sdk_version or (int(corona_sdk_version) < 2489
                                          or int(corona_sdk_version) > 2515):
                coronaDbg.doCommand('locals')
        elif cmd == "dump":
            self.dumpVariable()
        elif cmd == "setb":
            # toggle a breakpoint at the current cursor position
            if arg_filename is None:
                filename = self.view.file_name()
                (lineno, col) = self.view.rowcol(self.view.sel()[0].begin())
                lineno += 1
            else:
                filename = arg_filename
                lineno = int(arg_lineno)

            if self.toggle_breakpoint(filename, lineno, arg_toggle):
                cmd = "setb"
            else:
                cmd = "delb"

            cmd += " " + '"' + filename + '"'
            cmd += " " + str(lineno)
            debug("setb: " + cmd)

            if coronaDbg is not None:
                coronaDbg.doCommand(cmd)

        else:
            print("CoronaDebuggerCommand: Unrecognized command: " + cmd)