Skip to content

External global variables #3233

Answered by tomlau10
TracerDS asked this question in Q&A
Jul 19, 2025 · 1 comments · 2 replies
Discussion options

You must be logged in to vote

Is there a way to assign a value of the global variables in the config file somehow?

I assume you are talking about the diagnostics.globals settings: https://luals.github.io/wiki/settings/#diagnosticsglobals
AFAIK, this is actually NOT the best practice because the server cannot infer type from it, it is only used to mute relevant undefined global warnings.


What you actually want might be create a meta definition file and then define your globals with values there 🤔
https://luals.github.io/wiki/definition-files/

  • global.d.lua
---@meta

MyGlobalVar = 123

This pattern is used by LuaLS's repo as well: https://github.com/LuaLS/lua-language-server/blob/master/script/global.d.lua

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@TracerDS
Comment options

@tomlau10
Comment options

Answer selected by TracerDS
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