Skip to content

[Req] Middleclass support #1172

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

Closed
FlashHit opened this issue May 26, 2022 · 3 comments
Closed

[Req] Middleclass support #1172

FlashHit opened this issue May 26, 2022 · 3 comments
Labels
feat/LuaCats Annotations Related to Lua Language Server Annotations (LuaCats) question User has a question

Comments

@FlashHit
Copy link

FlashHit commented May 26, 2022

Hey, I want to define classes properly.
We use this middleclass to create classes in lua.
However if I define a class that takes parameters like this:

---@class CustomClass
CustomClass = class("CustomClass")

function CustomClass:initialize(sometable)
    self.sometable = sometable
end

local s_SomeTable = { test = 2 }
--- this shows as unknown instead of CustomClass
local s_CustomClass = CustomClass(s_SomeTable)

It doesn't work. Also CustomClass.static etc. would be unknown.
Is this something I can do? or do you need to add support for it? I want this since really long time.

@sumneko sumneko added question User has a question feat/LuaCats Annotations Related to Lua Language Server Annotations (LuaCats) labels May 27, 2022
@sumneko
Copy link
Collaborator

sumneko commented May 27, 2022

Class must be explicitly defined by ---@class.

@FlashHit
Copy link
Author

FlashHit commented May 27, 2022

Even with that I can’t make it work

@sumneko
Copy link
Collaborator

sumneko commented May 27, 2022

Use

---@class CustomClass
---@overload fun():CustomClass
CustomClass = class("CustomClass")

@sumneko sumneko closed this as completed Jun 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat/LuaCats Annotations Related to Lua Language Server Annotations (LuaCats) question User has a question
Projects
None yet
Development

No branches or pull requests

2 participants