You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Prepending Lua script to emission prior to source map finalization #1529
In the WarCraft 3 environment, we start with a preexisting war3map.lua file (containing information about preplaced units and other GUI elements), and we also do not have access to the debug library. With the help of the WarCraft 3 community, this exists as a decent enough manual implementation of debug.traceback:
I've tailored this with a custom getinfo that taps into the positions used by TypeScript2Lua to get the name of the current map file.
WarCraft 3 doesn't allow the require syntax either, so we are stuck with just one finalized war3map.lua output file. Therefore, being able to have full control over how the compiled output is framed, prior to source map finalization, would allow extremely powerful source mapping in the WarCraft 3 environment (as we've been restricted to hunting through a tens-of-thousands-of-lines-long Lua file for years).
The problem is, that both war3map.lua AND this custom debug library, need to be placed ABOVE the emitted TypeScript2Lua compiled file. This interferes with the ability to properly use source maps. Therefore, I'd ask if it's possible (or if it can be made possible) to perhaps include a table structure for the compilation, and the output will be merged all into one blob, prior to the source mapping being finalized.
e.g. adding something like this to the TSTL config:
I am not sure if I can use something like the afterPrint Plugin - does this run before or after the source maps were resolved? Would I be able to prepend my own files to the ProcessedFile array passed as the 4th parameter to afterPrint?
You could probably get this to work with plugins somehow, but an easier might be to simply import those pre-existing bundles into your bundle as external lua. I don't know enough of the w3 environment to know if this would work or not but I would use something like this:
And then create custom-debug.d.ts and war3map.d.ts files next to the lua files you are importing. They can be empty or you can put some stuff in there you need from those files.
I tested this and it produces the correct result, it imports the two lua files verbatim into the bundle and will execute them before any user code. This should allow the debug traceback on your bundle to function normally.
Activity
Perryvw commentedon Feb 3, 2024
You could probably get this to work with plugins somehow, but an easier might be to simply import those pre-existing bundles into your bundle as external lua. I don't know enough of the w3 environment to know if this would work or not but I would use something like this:
tsconfig.json:
{ "compilerOptions": { "target": "esnext", "types": ["@typescript-to-lua/language-extensions"] }, "tstl": { "luaBundle": "bundle.lua", "luaBundleEntry": "main.ts", "sourceMapTraceback": true } }main.ts:
And then create
custom-debug.d.tsandwar3map.d.tsfiles next to the lua files you are importing. They can be empty or you can put some stuff in there you need from those files.I tested this and it produces the correct result, it imports the two lua files verbatim into the bundle and will execute them before any user code. This should allow the debug traceback on your bundle to function normally.
BribeFromTheHive commentedon Feb 3, 2024
Thanks so much for clarifying! Maybe it really is a lot less complicated than I thought!