Is there a way to declare table.deepcopy() as builtin somehow? #3268
-
I know, normally there is no I want to prevent to write this every time: ---@diagnostic disable-next-line: undefined-field
local icon_copy = table.deepcopy(icon_layer) |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
There are various ways this can be done. You can simply add a file in your workspace, say, under ---@meta
---@generic T: table
---@param t T
---@return T
table.deepcopy = function(t) end Using generics allows more detailed information retrieved from the given table to persist in the returned value. A simpler version, if generics aren't working for you, is just the following: ---@meta
---@param t table
---@return table
table.deepcopy = function(t) end So long as that file is included in diagnostics and is not being excluded via your settings, that should do it. A cleaner solution would be to put that file somewhere outside your project, and then point to it using workspace.library. There is also likely a more complete solution someone has made out there that provides all the types for Factorio already. I found an addon someone has already made for Factorio on GitHub. I recommend checking out the LuaLS wiki to learn more about addons, annotations, settings, and more. |
Beta Was this translation helpful? Give feedback.
There are various ways this can be done.
You can simply add a file in your workspace, say, under
types/
and add the following:Using generics allows more detailed information retrieved from the given table to persist in the returned value. A simpler version, if generics aren't working for you, is just the following:
So long as that file is included in diagnostics and is not being excluded via your settings, that should do it.
A cleaner solution would be to put that file somewhere outside your project, and then point to it …