stevenlafl / tts-typescript

Typescript Declarations for Tabletop Simulator
MIT License
7 stars 2 forks source link

Issues with local functions #6

Open KlutzyBubbles opened 8 months ago

KlutzyBubbles commented 8 months ago

Tried from the readme and it produces

--[[ Generated with https://github.com/TypeScriptToLua/TypeScriptToLua ]]

local ____modules = {}
local ____moduleCache = {}
local ____originalRequire = require
local function require(file, ...)
    if ____moduleCache[file] then
        return ____moduleCache[file].value
    end
    if ____modules[file] then
        local module = ____modules[file]
        ____moduleCache[file] = { value = (select("#", ...) > 0) and module(...) or module(file) }
        return ____moduleCache[file].value
    else
        if ____originalRequire then
            return ____originalRequire(file)
        else
            error("module '" .. file .. "' not found")
        end
    end
end
____modules = {
["src.index"] = function(...) 
--[[ Generated with https://github.com/TypeScriptToLua/TypeScriptToLua ]]
local ____exports = {}
local function onLoad(saveData)
    print("test")
end
return ____exports
 end,
}
return require("src.index", ...)

When run in game it does nothing unless the local in front of the onLoad function is removed.

Curious to whether you ran into this issue or if there are any solutions, currently i have just modified TypeScriptToLua to output all functions without local however i dont think this would be a viable option long term.

stevenlafl commented 7 months ago

When run in game it does nothing unless the local in front of the onLoad function is removed.

Ahh, that in particular seems like a bug. These type definitions were painstakingly manually written, so it is likely that is just a mistake.

I'll take a look at your PR in a few.

Venusta commented 2 months ago

Any update on this? I have the same issue.

KlutzyBubbles commented 2 months ago

Any update on this? I have the same issue.

The local is a side effect from typescript-to-lua see https://github.com/KlutzyBubbles/tts-typescript-template?tab=readme-ov-file#global-functions for a workaround.