lua-debug icon indicating copy to clipboard operation
lua-debug copied to clipboard

How to handle multiple script roots?

Open sewbacca opened this issue 3 years ago • 3 comments

I have a subfolder, in which scripts are without prefix (e.g. main.lua) and all other folders are reachable via package.path (though the debug console says it has mixed / and \ (i'm on win)). If I set sourcemap, either the subfolder or the other "script roots" are found, but I couldn't get both working at the same time.

{
	"name": "Launch Debugger 2",
	"type": "lua",
	"request": "attach",
	"address": "127.0.0.1:4278",
	"sourceMaps": [
		[
			"*\\src\\*", // This is in package.path
			"${workspaceFolder}/src/*",
		],
		[
			"./*",
			"${workspaceFolder}/examples/component_explorer/*",
		]
	]
},

sewbacca avatar Jun 20 '22 00:06 sewbacca

You can change the chunkname so that they can be distinguished correctly.

actboy168 avatar Jun 21 '22 07:06 actboy168

How so? The modules are loaded via require(). Do you suggest to create my own require() function? And if so, how should I go about writing it? How is the path inferred from the chunkname? It's not that I haven't written my own require function, I am more interested in how the debugger interprets the chunkname. Thanks for your feedback :)

sewbacca avatar Jun 21 '22 10:06 sewbacca

If you don't modify require, you shouldn't need to set sourceMaps. The debugger understands chunknames using the rules on the lua documentation.

actboy168 avatar Jun 27 '22 07:06 actboy168