Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork391
-
Assume I am trying to use OOP in Lua in the following manner: localClass= {}Class.__index=ClassClass.myMethod=function ()print("hellow world")endClass.new=function ()localo= {}setmetatable(o,Class)returnoendlocalinst=Class.new()inst:myMethod()^ It seems that when I input till the colon, the language server can not figure out that inst has a metatable which |
BetaWas this translation helpful?Give feedback.
All reactions
Replies: 1 comment 1 reply
-
LuaLS requires annotations to perform better type infer. ---@classClasslocalClass= {}Class.__index=ClassClass.myMethod=function ()print("hellow world")endClass.new=function ()---@classClasslocalo= {}-- you can define other fields for `o` here-- which will be auto "injected" into the class `Class` as member fieldso.x=1o.y=2setmetatable(o,Class)returnoendlocalinst=Class.new()-- server will infer that `Class.new -> Class`inst:my--> now this will have completion for `myMethod` |
BetaWas this translation helpful?Give feedback.
All reactions
-
Thanks a lot. This perfectly solves my problem. I did not know that annotation is necessary, should have read the documentation more carefully. |
BetaWas this translation helpful?Give feedback.
All reactions
👍 1