Jump to content
Alloder.pro  about Allods with love 😱
Search In
  • More options...
Find results that contain...
Find results in...

Servers monitoring and the Addons Editor

We present you two legends. All dreams come true.

Servers monitoring The Addons Editor

Digest April

We talk about what was done and updated in the past month. We help keep abreast of events.

Read more

Game tooltips

Tooltips provide a way for 3rd party fansites and extensions to display detailed information on mouseover.

Read more

Classes and Objects in addons


icreator
 Share

Recommended Posts

Code:

Class( "overtip", { handlers = {} } )
--------------------------------------------------------------------------------
-- INIT
--------------------------------------------------------------------------------
function overtip:init( widget )
self.widget = self.widget or widget

self.wtOvertip = self.widget:GetChildChecked( "Overtip", false )
self.wtOvertip:SetFade( OVERTIP_TEXT_OPACITY )
self.wtMark = self.widget:GetChildChecked( "Image", false )
self.bar = progressbar{ widget = self.widget:GetChildChecked( "Progress", false ) }
self.bar:init()
end
--------------------------------------------------------------------------------
-- PUBLIC
--------------------------------------------------------------------------------
function overtip:Show( state )
if state ~= self.visible then
self.visible = state
self.widget:Show( self.visible )
end
end


и создание объекта потом как
Code:

local myObj = overtip{ var1 = val1, ... }


but
Code:
Class

- get error mess

может быть, можно без объявления класса создавать объекты обычным образом?
Link to comment
Share on other sites

И откуда такой код взялся, интересно?

Quote:
может быть, можно без объявления класса создавать объекты обычным образом?

Любая таблица - объект, созданный обычным образом. В чем проблема-то?

Если так сильно не хватает такого Class, то вот:

Code:

local function r( cl, t )

return setmetatable( t or {}, { __index = cl } )

end

local function d( t )

return setmetatable( t or {}, { __call = r } )

end

function Class( name, t )

Global( name, d( t ) )

end

Link to comment
Share on other sites

а вот нашла в системном коде:

Code:

function addmetatable( tab, mt )

local _mt = getmetatable( tab )

_mt = type( _mt ) == "table" and _mt or {}

for k, v in mt do

_mt [ k ]  = v

end

setmetatable( tab, _mt )

end

-- ScriptClassesImplementation.lua

-- REQUIRES: ScriptStandardExtension.lua

--------------------------------------------------------------------------------

do

local constructor = function( cl, object )

local object = object or {}

addmetatable( object, { __index = cl } )

return object

end

------------------------------------------------------------------------------

function class( proto )

addmetatable( proto, { __call = constructor } )

return proto

end

------------------------------------------------------------------------------

function Class( name, object )

Global( name, class( object ) )

end

end

--------------------------------------------------------------------------------

только зачем тут do..end ?

Link to comment
Share on other sites

довольно интересно, а я с помощью

Code:

function Clone( value )

if type( value ) == "table" then

local new = {}

for id, val in value do

new [ id ]  = Clone( val )

end

return new

else

return value

end

end

---------------------

Global( "mark", {} )

mark.new = function (self)

return Clone(self)

end

------------------

создание объекта:

local myObj = mark:new()

Link to comment
Share on other sites

То же самое и я написал выше.

Quote:
только зачем тут do..end ?

Чтоб к локальной функции constructor за пределами do..end никто не смог обратиться.

Link to comment
Share on other sites

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

By using our site you agree to the Terms of Use