tomblind / local-lua-debugger-vscode

Local Lua Debugger for VSCode
MIT License
107 stars 26 forks source link

Bootstrap script for Defold #39

Open thejustinwalsh opened 3 years ago

thejustinwalsh commented 3 years ago

This may be useful for other engines as well where the require statement is using custom loaders...

The gist of it is:

//@ts-expect-error package
const path = [...package.path.split(";")];
const debuggerPath = path.filter((path) => path.includes("tomblind.local-lua-debugger"))[0];
print(debuggerPath);
if (debuggerPath != null) {
  const [debuggerModule, err] = loadfile(`${debuggerPath.substr(0, debuggerPath.indexOf("?.lua"))}lldebugger.lua`);
  if (debuggerModule) {
    //@ts-expect-error package
    // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
    package.loaded["lldebugger"] = debuggerModule();
  } else print(err);
}

if (os.getenv("LOCAL_LUA_DEBUGGER_VSCODE") == "1") {
  const r = require;
  // eslint-disable-next-line @typescript-eslint/no-var-requires, @typescript-eslint/no-unsafe-assignment
  const lldebugger = r("lldebugger");
  // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
  lldebugger.start();
}

Some of this code is working around a few bugs, strict mode, and aslant configs I have setup.

tomblind commented 3 years ago

I'm thinking I'll add an env variable LOCAL_LUA_DEBUGGER_FILEPATH that contains the full path to the script to help environments like this. Then, loading could be as simple as:

package.loaded["lldebugger"] = assert(loadfile(os.getenv("LOCAL_LUA_DEBUGGER_FILEPATH")))()
require("lldebugger").start()
tomblind commented 3 years ago

added in ae45175

thejustinwalsh commented 3 years ago

That is much less code than I was using. Haha might not even need an extension anymore, but still going to do it for good measure.

I can add in checks to not load the module if it is a release build, and ensure start doesn't fail in the case where the module is not loaded etc.

Some quality of life stuff over in Defold land.

astrochili commented 3 years ago

Waiting for the release to update my interlayer debugger as well. 👍

tomblind commented 3 years ago

FYI: I've added a minimal setup example in the README