icreator Posted April 18, 2011 Share Posted April 18, 2011 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 ) endend и создание объекта потом какCode: local myObj = overtip{ var1 = val1, ... } but Code: Class - get error messможет быть, можно без объявления класса создавать объекты обычным образом? Quote Link to comment Share on other sites More sharing options...
Ciuine Posted April 18, 2011 Share Posted April 18, 2011 Oh, nevermind. Quote Link to comment Share on other sites More sharing options...
ramirez Posted April 19, 2011 Share Posted April 19, 2011 И откуда такой код взялся, интересно? 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 Quote Link to comment Share on other sites More sharing options...
icreator Posted April 20, 2011 Author Share Posted April 20, 2011 а вот нашла в системном коде: 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 ? Quote Link to comment Share on other sites More sharing options...
icreator Posted April 20, 2011 Author Share Posted April 20, 2011 довольно интересно, а я с помощью 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() Quote Link to comment Share on other sites More sharing options...
ramirez Posted April 20, 2011 Share Posted April 20, 2011 То же самое и я написал выше. Quote: только зачем тут do..end ? Чтоб к локальной функции constructor за пределами do..end никто не смог обратиться. Quote Link to comment Share on other sites More sharing options...
icreator Posted April 20, 2011 Author Share Posted April 20, 2011 понятно - блин столько нюансов... Quote Link to comment Share on other sites More sharing options...
Recommended Posts