GlassBricks / typed-factorio

Complete and featureful Typescript defintions for the Factorio modding API
MIT License
33 stars 3 forks source link

Require of different mod with Lua snippet (Lua API global Variable Viewer (gvv)) #11

Closed JasonLandbridge closed 2 years ago

JasonLandbridge commented 2 years ago

Hi there,

First of all, huge thank you for all the work you have been doing for typed-factorio!

I'm currently developing a mod which I would like to debug by using: https://mods.factorio.com/mod/gvv

The mod requires the use of the following lua snippet:

    if script.active_mods["gvv"] then
        require("__gvv__.gvv")()
    end

I have been struggeling but so far I have managed to get it working by doing the following:

//debug.lua
local debug = {}

function debug:setup_gvv()
    if script.active_mods["gvv"] then
        require("__gvv__.gvv")()
    end
end

return debug
// control.ts
setup_gvv();

This works and I am able to use GVV succesfully. However I keep receiving the following error in the console of my IDE

error TSTL: Could not resolve lua source files for require path '__gvv__.gvv' in file debug.lua.

Am I importing it wrong or is there a different way to translate the Lua snippet to Typescript?

Very much thank you in advance!

GlassBricks commented 2 years ago

This is an issue with TypescriptToLua, you can find more details here (and maybe give it an upvote): https://github.com/TypeScriptToLua/TypeScriptToLua/issues/1152

For a workaround, either extract "__gvv__.gvv" to a local variable before passing it to require, or change it to "@NoResolution:__gvv__.gvv"

JasonLandbridge commented 2 years ago

It worked, thank you so much!

Upvoted the thread as well 👍