Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow custom function definitions in table #150

Open
nlebedenco opened this issue Jan 29, 2023 · 0 comments
Open

Allow custom function definitions in table #150

nlebedenco opened this issue Jan 29, 2023 · 0 comments

Comments

@nlebedenco
Copy link

Environment

Name Version
IDEA version CL2022.3.2
Luanalysis version v1.4.0
OS Windows 10

Lua

Name Setting
Language level Lua 5.1

Type Safety

Name Setting
Strict nil checks
Unknown type (any) is indexable ☑️
Unknown type (any) is callabale ☑️

What are the steps to reproduce this issue?

  1. Add a def file to the project declaring custom functions in the global table module. For example:
--- Creates a pre-sized table, just like the C API equivalent
--- `lua_createtable`. This is useful for big tables if the final table size is
--- known and automatic table resizing is too expensive.
---@overload fun(narr:number):table
---@param narr number
---@param nrec number
---@return table
function table.new(narr, nrec) end

--- Clears all keys and values from a table, but preserves the allocated array/hash sizes.
--- This is useful when a table, which is linked from
--- multiple places, needs to be cleared and/or when recycling a table for use
--- by the same context. This avoids managing backlinks, saves an allocation
--- and the overhead of incremental array/hash part growth.
---
--- Please note, this function is meant for very specific situations. In most
--- cases it's better to replace the (usually single) link with a new table
--- and let the GC do its work.
---@param t table
function table.clear(t) end

What happens?

Custom function definitions are ignored and uses are reported as errors.

What were you expecting to happen?

Custom function definitions should be merged with the std definitions as is the case for example with the math module.

Any other comments?

The "table" type is not the same thing as the "table" module and this is an important distinction. As far as the module goes it could have been given a different name altogether like "container" just as the "math" module is not called "number". It just happens that the type and the module share the same name in this case. Also consider that many lua frameworks add custom functions to std modules as extensions (for example, Premake) which causes a lot of false errors to be reported.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant