Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Lua Development Tools » LDT and Classes(Implementing classes in Lua and using them in LDT)
LDT and Classes [message #1463343] Thu, 06 November 2014 13:22 Go to next message
David L is currently offline David LFriend
Messages: 1
Registered: November 2014
Junior Member
Can anyone suggest a way of implementing classes in Lua that will allow LDT to auto-complete methods and variables?

For example:

LuaClass = {}
   function LuaClass:new(Parameter)
      local o = setmetatable({}, self); self.__index = self;
      
      o.value = Parameter
      return o
    end
    function LuaClass:getValue()
      return self.value
    end


This works as a simple way to implement a class but LDT isn't able to auto-complete the code. If I instance with x = LuaClass:new(10) then I'd like code completion for x:getValue().
Re: LDT and Classes [message #1463401 is a reply to message #1463343] Thu, 06 November 2014 14:30 Go to previous message
Simon Bernard is currently offline Simon BernardFriend
Messages: 339
Registered: July 2009
Senior Member
hi

If your your module is named "LuaClass" (I mean it is at root source folder and is named LuaClass.lua)
local LuaClass = {}

--- @return #LuaClass
function LuaClass:new(Parameter)
      local o = setmetatable({}, self); self.__index = self;
      
      o.value = Parameter
      return o
end

function LuaClass:getValue()
      return self.value
end

return LuaClass


or if you want to do that without module
--- @type LuaClass
local LuaClass = {}

--- @return #LuaClass
function LuaClass:new(Parameter)
      local o = setmetatable({}, self); self.__index = self;
      
      o.value = Parameter
      return o
end

function LuaClass:getValue()
      return self.value
end


You could find more information on documentation language here.
And some object oriented sample here.

HTH

Simon
Previous Topic:Problems with LuaDoc View
Next Topic:Where is Code Formatter in LDT?
Goto Forum:
  


Current Time: Tue Nov 20 11:12:52 GMT 2018

Powered by FUDForum. Page generated in 0.01922 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top