-
|
Greetings! I'm trying to find a way to implement a custom ---@generic T
---@param name string
---@param value T
function SET_GLOBAL(name, value)
_G[name] = value
endCombined with |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
|
I don't think this is a good approach. Emmylua's static analysis can almost directly detect unintended global variable definitions. Also, locking global variable definitions using _newindex is not suitable during the loading phase. A better way is to allow global variables to be defined directly while files are loading, and then set the metatable for G after loading is complete. This way, you don't need to use a function like SET_GLOBAL to achieve this. |
Beta Was this translation helpful? Give feedback.
I don't think this is a good approach. Emmylua's static analysis can almost directly detect unintended global variable definitions. Also, locking global variable definitions using _newindex is not suitable during the loading phase. A better way is to allow global variables to be defined directly while files are loading, and then set the metatable for G after loading is complete. This way, you don't need to use a function like SET_GLOBAL to achieve this.