Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bootstrap script for Defold #39

Open
thejustinwalsh opened this issue Sep 8, 2021 · 5 comments
Open

Bootstrap script for Defold #39

thejustinwalsh opened this issue Sep 8, 2021 · 5 comments

Comments

@thejustinwalsh
Copy link

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

The gist of it is:

  • Look for "tomblind.local-lua-debugger" in LUA_PATH
  • Use loadfile to load then execute the lldebugger.lua file from the extension
  • Add it to the path.loaded table
  • Somewhere later require and start the debugger
//@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
Copy link
Owner

tomblind commented Sep 8, 2021

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
Copy link
Owner

tomblind commented Sep 8, 2021

added in ae45175

@thejustinwalsh
Copy link
Author

thejustinwalsh commented Sep 8, 2021

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
Copy link

astrochili commented Sep 19, 2021

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

@tomblind
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants