Skip to content

How to spread namespace onto _G? #3187

Answered by tomlau10
akd-io asked this question in Q&A
Discussion options

You must be logged in to vote

AFAIK, you cannot use annotation to dynamically add things to global.
You can only use annotation to define them statically.
By statically I mean:

---@meta mylib

if false then
    this_global_is_still_set = true
    -- you will still see this suggestions in the global scope
end

=> even if that code block is wrapped with if false, LuaLS will still analyze it and treat it as global


how to use annotations to tell the language server that all the members are now in the global scope?

The closest that I can think of is to export them manually 🤔
But as stated above, they will be in the global even if you don't call React() beforehand ☹️

---@meta react.lua

---@class React
local React = {}

f…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@akd-io
Comment options

Answer selected by akd-io
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants