{"id":182018,"date":"2013-06-03T23:13:03","date_gmt":"2013-06-03T19:13:03","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=182018"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=182018","title":{"rendered":"<span class=\"post_title\">\u041a\u043b\u0430\u0441\u0441\u044b \u0432 lua, \u0438\u043b\u0438 \u0438\u0437\u0431\u0430\u0432\u043b\u044f\u0435\u043c\u0441\u044f \u043e\u0442 \u0434\u0432\u043e\u0435\u0442\u043e\u0447\u0438\u044f<\/span>"},"content":{"rendered":"<div class=\"content html_format\">   \t\u041a\u0430\u043a \u0432\u0441\u0435\u043c \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u043e, \u0432 lua \u043d\u0435\u0442 \u043a\u0430\u043a \u0442\u0430\u043a\u043e\u0432\u044b\u0445 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432. \u041e\u0434\u043d\u0430\u043a\u043e \u0435\u0441\u0442\u044c \u043c\u0435\u0442\u0430\u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0438 \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0441\u0430\u0445\u0430\u0440.<br \/>  \u0421 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u0445 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c\u043e\u0432 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u0434\u043e\u0431\u0438\u0435 \u043a\u043b\u0430\u0441\u0441\u043e\u0432.<br \/>  \u0412 \u0438\u0442\u043e\u0433\u0435 \u0438 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f \u043d\u0435\u0447\u0442\u043e \u0442\u0430\u043a\u043e\u0435:  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0421\u0430\u043c\u044b\u0439 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u043a\u043b\u0430\u0441\u0441<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"lua\">local MyClass = {} -- the table representing the class, which will double as the metatable for the instances MyClass.__index = MyClass -- failed table lookups on the instances should fallback to the class table, to get methods  -- syntax equivalent to &quot;MyClass.new = function...&quot; function MyClass.new(init)   local self = setmetatable({}, MyClass)   self.value = init   return self end  function MyClass.set_value(self, newval)   self.value = newval end  function MyClass.get_value(self)   return self.value end  local i = MyClass.new(5) -- tbl:name(arg) is a shortcut for tbl.name(tbl, arg), except tbl is evaluated only once print(i:get_value()) --&gt; 5 i:set_value(6) print(i:get_value()) --&gt; 6 <\/code><\/pre>\n<p>  (\u0432\u0437\u044f\u0442\u043e \u0441 <a href=\"http:\/\/lua-users.org\/wiki\/ObjectOrientationTutorial\">lua-users.org\/wiki\/ObjectOrientationTutorial<\/a>)  <\/div>\n<\/div>\n<p>  \u0412\u0441\u0451 \u044d\u0442\u043e \u043a\u043e\u043d\u0435\u0447\u043d\u043e \u0445\u043e\u0440\u043e\u0448\u043e, \u0434\u0430\u0436\u0435 \u043f\u0440\u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u043e\u0439 \u0441\u043d\u043e\u0440\u043e\u0432\u043a\u0435 \u043c\u043e\u0436\u043d\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u0435\u2026<br \/>  \u041d\u043e \u0433\u0434\u0435 public \u0438 private \u0447\u043b\u0435\u043d\u044b \u043a\u043b\u0430\u0441\u0441\u0430? \u0414\u0435\u0444\u0430\u043a\u0442\u043e \u0432 \u044d\u0442\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043e\u043d\u0438 \u0432\u0441\u0435 public. \u0414\u0430 \u0435\u0449\u0451 \u0438 \u043d\u0430\u0434\u043e \u043f\u043e\u043c\u043d\u0438\u0442\u044c, \u0433\u0434\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u0432\u043e\u0435\u0442\u043e\u0447\u0438\u0435:  <\/p>\n<pre><code class=\"lua\">MyClass:myFunc() <\/code><\/pre>\n<p>  \u0430 \u0433\u0434\u0435 \u043f\u0440\u043e\u0441\u0442\u043e \u043e\u0434\u043d\u0443 \u0442\u043e\u0447\u043a\u0443:  <\/p>\n<pre><code class=\"lua\">MyClass.myOtherFunc() <\/code><\/pre>\n<p>  \u0410 \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0447\u043b\u0435\u043d\u044b \u043a\u043b\u0430\u0441\u0441\u0430? \u041d\u0435\u0443\u0436\u0435\u043b\u0438 \u043f\u0440\u0438\u0434\u0451\u0442\u0441\u044f \u043e\u0442\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c\u0441\u044f?<br \/>  <a name=\"habracut\"><\/a><\/p>\n<p>  \u0412\u043e\u0442 \u044f \u0438 \u043d\u0435 \u0437\u0430\u0445\u043e\u0442\u0435\u043b \u043e\u0442\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c\u0441\u044f, \u0438 \u043d\u0430\u0447\u0430\u043b \u043a\u043e\u043b\u0445\u043e\u0437\u0438\u0442\u044c\u2026<\/p>\n<p>  \u0418\u0442\u0430\u043a, \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e \u0432\u0430\u043c \u043c\u043e\u0439 \u043a\u043e\u043b\u0445\u043e\u0437:  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041c\u043e\u0439 \u043a\u043e\u043b\u0445\u043e\u0437<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"lua\">createClass = function() \tlocal creator = {} \tcreator.__private = { \t\tobject_class = {}, \t} \t \tcreator.__oncall = function(class_creator)\t\t \t\t-- Get the class definition so we can make needed variables private, static, etc. \t\tlocal this = class_creator() \t\t-- Initialize class from class definition \t\t__init = function() \t\t\t-- Init Public Static \t\t\tlocal class = {} \t\t\tif (type(this.__public_static) == &quot;table&quot;) then \t\t\t\tclass = this.__public_static \t\t\tend \t\t\t \t\t\t-- Init Object \t\t\tlocal thisClass = this \t\t\tlocal __constructor = function(...) \t\t\t\tlocal object = {} \t\t\t\tlocal this = class_creator()  \t\t\t\t-- Init Public \t\t\t\tif (type(this.__public) == &quot;table&quot;) then \t\t\t\t\tobject = this.__public \t\t\t\tend  \t\t\t\t-- Init static values of the class \t\t\t\tthis.__public_static = thisClass.__public_static \t\t\t\tthis.__private_static = thisClass.__private_static  \t\t\t\t-- Call Constructor \t\t\t\tif (type(this.__construct) == &quot;function&quot;) then \t\t\t\t\tthis.__construct(...) \t\t\t\tend \t\t\t\t \t\t\t\t-- Returning constructed object \t\t\t\treturn object \t\t\tend \t\t\treturn {class = class, constructor = __constructor} \t\tend  \t\t-- Creating class (returning constructor) \t\tlocal class_data = __init() \t\tlocal class = class_data.class \t\tlocal constructor = class_data.constructor  \t\t-- Set class metatable (with setting constructor) \t\tlocal class_metatable = { \t\t\t__newindex = function(t, key, value) \t\t\t\tif type(t[key])==&quot;nil&quot; or type(t[key])==&quot;function&quot; then \t\t\t\t\terror(&quot;Attempt to redefine class&quot;) \t\t\t\tend \t\t\t\trawset(t, key, value) \t\t\tend, \t\t\t__metatable = false, \t\t\t__call = function(t, ...) \t\t\t\tif type(t) == nil then \t\t\t\t\terror(&quot;Class object create failed!&quot;) \t\t\t\tend \t\t\t\tlocal obj = constructor(...) \t\t\t\tcreator.__private.object_class[obj] = t \t\t\t\tlocal object_metatable = { \t\t\t\t\t__newindex = function(t, key, value) \t\t\t\t\t\tclass = creator.__private.object_class[t] \t\t\t\t\t\tif type(class[key])~=&quot;nil&quot; and type(class[key])~=&quot;function&quot; then \t\t\t\t\t\t\trawset(class, key, value) \t\t\t\t\t\t\treturn \t\t\t\t\t\tend \t\t\t\t\t\tif type(t[key])~=&quot;nil&quot; and type(t[key])~=&quot;function&quot; then \t\t\t\t\t\t\trawset(t, key, value) \t\t\t\t\t\t\treturn \t\t\t\t\t\tend \t\t\t\t\t\terror(&quot;Attempt to redefine object&quot;) \t\t\t\t\tend, \t\t\t\t\t__index = t, \t\t\t\t\t__metatable = false, \t\t\t\t} \t\t\t\tsetmetatable(obj, object_metatable) \t\t\t\treturn obj \t\t\tend, \t\t}  \t\t-- Setting class metatable to the class itself \t\tsetmetatable(class, class_metatable)  \t\t-- Returning resulting class \t\treturn class \tend \t \treturn creator.__oncall end createClass = createClass() <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u0410 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043a\u0430\u043a? \u041e\u0447\u0435\u043d\u044c \u043f\u0440\u043e\u0441\u0442\u043e, \u0432\u043e\u0442 \u0432\u0430\u043c \u0448\u0430\u0431\u043b\u043e\u043d:  <\/p>\n<pre><code class=\"lua\">myclass_prototype = function() \tlocal this = {} \tthis.__public_static = { \t\t-- Public Static Variables \t\tstatvalue = 5, \t\t-- Public Static Funcs \t\tstatfunc = function() \t\t\tprint(this.__public_static.statvalue) \t\tend, \t}  \tthis.__private_static = { \t\t-- Private Static Variables \t\tprivstatdat = 2, \t\t-- Private Static Funcs \t\tprivstatfunc = function() \t\t\tprint(this.__private_static.privstatdat) \t\tend, \t}  \tthis.__public = { \t\t-- Public Variables \t\tpubdata = 3, \t\t-- Public Funcs \t\tpubfunc  = function(newprivate) \t\t\tprint(this.__public.pubdata) \t\t\tthis.__private.privdata = newprivate \t\tend, \t}  \tthis.__private = { \t\t-- Private Variables \t\tprivdata = 1, \t\t-- Private Funcs \t\tlistallprivate = function() \t\t\tprint(this.__private.privdata) \t\tend, \t}  \tthis.__construct = function() \t\t-- Constructor \tend  \treturn this end  myclass=createClass(myclass_prototype) <\/code><\/pre>\n<p>  \u041a\u0430\u043a \u0432\u0438\u0434\u0438\u0442\u0435, \u043f\u0440\u0438 \u043a\u0430\u0436\u0434\u043e\u043c \u0432\u044b\u0437\u043e\u0432\u0435 \u0438\u0437\u043d\u0443\u0442\u0440\u0438 \u043a\u043b\u0430\u0441\u0441\u0430 \u043f\u0440\u0438\u0434\u0451\u0442\u0441\u044f \u043a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u043f\u0443\u0442\u044c, \u0430 \u043b\u044f \u00abthis.__private.privdata\u00bb, \u0437\u0430\u0442\u043e \u0432\u043e\u0442 \u0432\u0430\u043c \u043f\u0440\u0438\u043c\u0435\u0440 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430!  <\/p>\n<pre><code class=\"lua\">myobject = myclass() myobject.pubfunc(999) <\/code><\/pre>\n<p>  \u041f\u0440\u0438 \u0432\u044b\u0437\u043e\u0432\u0435 \u044d\u0442\u043e\u0433\u043e \u043a\u043e\u0434\u0430 \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u043d \u043e\u0431\u044a\u0435\u043a\u0442 myobject \u0438\u0437 \u043a\u043b\u0430\u0441\u0441\u0430 myclass, \u0438 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0437\u0432\u0430\u043d\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f pubfunc, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0432\u044b\u0441\u0432\u0435\u0442\u0438\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435 \u043f\u0443\u0431\u043b\u0438\u0447\u043d\u043e\u0439 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u0438 \u0438\u0437\u043c\u0435\u043d\u0438\u0442 \u043f\u0440\u0438\u0432\u0430\u0442\u043d\u0443\u044e.<br \/>  \u0418 \u043d\u0438\u043a\u0430\u043a\u0438\u0445 \u0437\u0430\u043c\u043e\u0440\u043e\u0447\u0435\u043a \u0441 \u0434\u0432\u043e\u0435\u0442\u043e\u0447\u0438\u044f\u043c\u0438!<br \/>  \u041a\u0441\u0442\u0430\u0442\u0438, \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0432\u044b\u0437\u043e\u0432\u044b \u0442\u043e\u0436\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0442. \u041a\u0430\u043a \u0438\u0437 \u043a\u043b\u0430\u0441\u0441\u0430, \u0442\u0430\u043a \u0438 \u0438\u0437 \u043e\u0431\u044a\u0435\u043a\u0442\u0430.<\/p>\n<p>  \u0418\u0442\u0430\u043a, \u0432\u043a\u0440\u0430\u0442\u0446\u0435 \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0443, \u0447\u0442\u043e \u0437\u0430 \u043c\u0430\u0433\u0438\u044f \u0437\u0434\u0435\u0441\u044c \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442. \u0410 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0442\u0443\u0442 \u0436\u043e\u043d\u0433\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0442\u0430\u043a \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u043c\u044b\u043c\u0438 upvalues. upvalues \u2014 \u044d\u0442\u043e \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0438\u0437\u043d\u0443\u0442\u0440\u0438 \u0432\u0438\u0434\u043d\u044b, \u0430 \u0441\u043d\u0430\u0440\u0443\u0436\u0438 \u2014 \u043d\u0435\u0442! \u041e\u0447\u0435\u043d\u044c \u043f\u043e\u0445\u043e\u0436\u0435 \u043d\u0430 private, \u043d\u0435 \u0442\u0430\u043a \u043b\u0438?<br \/>  \u0422\u0430\u043a \u0432\u043e\u0442, \u0441\u043e\u0437\u0434\u0430\u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u044e-\u00ab\u043f\u0440\u043e\u0442\u043e\u0442\u0438\u043f\u00bb, \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u043b\u0438 \u043d\u043e\u0432\u0443\u044e \u043e\u0431\u043b\u0430\u0441\u0442\u044c \u0432\u0438\u0434\u0438\u043c\u043e\u0441\u0442\u0438, \u0438 \u0432 \u043d\u0435\u0451 \u043f\u043e\u043c\u0435\u0441\u0442\u0438\u043b\u0438 \u0432\u0441\u0435 \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u043e\u0441\u0442\u0438 \u043d\u0430\u0448\u0435\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430, \u0432\u044b\u043d\u0435\u0441\u044f \u043d\u0430\u0440\u0443\u0436\u0443 \u0442\u043e\u043b\u044c\u043a\u043e public \u0438 public static \u0447\u043b\u0435\u043d\u044b \u043a\u043b\u0430\u0441\u0441\u0430. \u0410 \u0432\u0441\u044e \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u0443\u044e \u043c\u0430\u0433\u0438\u044e \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0442 \u043c\u0435\u0442\u0430\u0442\u0430\u0431\u043b\u0438\u0446\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c, \u0447\u0442\u043e \u0438\u043c\u0435\u043d\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442\u044c \u043f\u0440\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u0435 \u00ab\u043d\u0435\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0433\u043e\u00bb \u0447\u043b\u0435\u043d\u0430 \u0432\u043d\u0435\u0448\u043d\u0435\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u044b, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043d\u0430\u0448 \u043a\u043b\u0430\u0441\u0441\/\u043e\u0431\u044a\u0435\u043a\u0442.<br \/>  \u0421\u0443\u043c\u0431\u0443\u0440\u043d\u043e \u0437\u0432\u0443\u0447\u0438\u0442, \u0437\u043d\u0430\u044e, \u043d\u043e \u043b\u0443\u0447\u0448\u0435 \u043d\u0435 \u043c\u043e\u0433\u0443 \u043e\u0431\u044a\u044f\u0441\u043d\u0438\u0442\u044c \u2014 \u043d\u0435 \u0441\u043f\u0435\u0446 \ud83d\ude42<\/p>\n<p>  \u0414\u043e\u043b\u0433\u043e \u0434\u0443\u043c\u0430\u043b, \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u0435 \u043f\u0440\u0438 \u0442\u0430\u043a\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u0435, \u043d\u043e \u0442\u0430\u043a \u0438 \u043d\u0435 \u043f\u0440\u0438\u0434\u0443\u043c\u0430\u043b \u2014 upvalues \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0441\u0435\u0440\u044c\u0451\u0437\u043d\u043e \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u0432\u0430\u0435\u0442 \u043d\u0430\u0448\u0438 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f, \u0430 \u0438\u0437\u0432\u0440\u0430\u0449\u0435\u043d\u0441\u0442\u0432\u0430\u043c\u0438 \u0432\u0440\u043e\u0434\u0435 debug \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043d\u0435 \u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u2014 \u043e\u043d\u0430 \u043d\u0435 \u0432\u0435\u0437\u0434\u0435 \u0432\u043a\u043b\u044e\u0447\u0435\u043d\u0430. \u0415\u0441\u043b\u0438 \u043a\u0442\u043e \u0434\u043e\u0434\u0443\u043c\u0430\u0435\u0442\u0441\u044f, \u0431\u0443\u0434\u0443 \u0440\u0430\u0434 \u0443\u0432\u0438\u0434\u0435\u0442\u044c!<\/p>\n<p>  PS: \u0435\u0441\u043b\u0438 \u0434\u043b\u044f \u043a\u043e\u0433\u043e-\u0442\u043e \u043c\u043e\u0439 \u043f\u043e\u0441\u0442 \u043d\u0435\u0447\u0442\u043e \u043e\u0447\u0435\u0432\u0438\u0434\u043d\u043e\u0435 \u2014 \u0447\u0442\u043e\u0436, \u0437\u043d\u0430\u0447\u0438\u0442 \u044f \u0441\u0435\u0431\u044f \u043f\u0435\u0440\u0435\u043e\u0446\u0435\u043d\u0438\u043b \ud83d\ude42 \u041d\u0435 \u0441\u0443\u0434\u0438\u0442\u0435 \u0441\u0442\u0440\u043e\u0433\u043e, \u043c\u043e\u0436\u0435\u0442 \u043a\u043e\u043c\u0443-\u0442\u043e \u0437\u0430\u0447\u0435\u043c-\u0442\u043e \u043f\u0440\u0438\u0433\u043e\u0434\u0438\u0442\u0441\u044f \u044d\u0442\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u0435!    \t<\/p>\n<div class=\"clear\"><\/div>\n<\/p><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/habrahabr.ru\/post\/182018\/\"> http:\/\/habrahabr.ru\/post\/182018\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"content html_format\">   \t\u041a\u0430\u043a \u0432\u0441\u0435\u043c \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u043e, \u0432 lua \u043d\u0435\u0442 \u043a\u0430\u043a \u0442\u0430\u043a\u043e\u0432\u044b\u0445 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432. \u041e\u0434\u043d\u0430\u043a\u043e \u0435\u0441\u0442\u044c \u043c\u0435\u0442\u0430\u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0438 \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0441\u0430\u0445\u0430\u0440.<br \/>  \u0421 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u0445 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c\u043e\u0432 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u0434\u043e\u0431\u0438\u0435 \u043a\u043b\u0430\u0441\u0441\u043e\u0432.<br \/>  \u0412 \u0438\u0442\u043e\u0433\u0435 \u0438 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f \u043d\u0435\u0447\u0442\u043e \u0442\u0430\u043a\u043e\u0435:  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0421\u0430\u043c\u044b\u0439 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u043a\u043b\u0430\u0441\u0441<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"lua\">local MyClass = {} -- the table representing the class, which will double as the metatable for the instances MyClass.__index = MyClass -- failed table lookups on the instances should fallback to the class table, to get methods  -- syntax equivalent to &quot;MyClass.new = function...&quot; function MyClass.new(init)   local self = setmetatable({}, MyClass)   self.value = init   return self end  function MyClass.set_value(self, newval)   self.value = newval end  function MyClass.get_value(self)   return self.value end  local i = MyClass.new(5) -- tbl:name(arg) is a shortcut for tbl.name(tbl, arg), except tbl is evaluated only once print(i:get_value()) --&gt; 5 i:set_value(6) print(i:get_value()) --&gt; 6 <\/code><\/pre>\n<p>  (\u0432\u0437\u044f\u0442\u043e \u0441 <a href=\"http:\/\/lua-users.org\/wiki\/ObjectOrientationTutorial\">lua-users.org\/wiki\/ObjectOrientationTutorial<\/a>)  <\/div>\n<\/div>\n<p>  \u0412\u0441\u0451 \u044d\u0442\u043e \u043a\u043e\u043d\u0435\u0447\u043d\u043e \u0445\u043e\u0440\u043e\u0448\u043e, \u0434\u0430\u0436\u0435 \u043f\u0440\u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u043e\u0439 \u0441\u043d\u043e\u0440\u043e\u0432\u043a\u0435 \u043c\u043e\u0436\u043d\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u0435\u2026<br \/>  \u041d\u043e \u0433\u0434\u0435 public \u0438 private \u0447\u043b\u0435\u043d\u044b \u043a\u043b\u0430\u0441\u0441\u0430? \u0414\u0435\u0444\u0430\u043a\u0442\u043e \u0432 \u044d\u0442\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043e\u043d\u0438 \u0432\u0441\u0435 public. \u0414\u0430 \u0435\u0449\u0451 \u0438 \u043d\u0430\u0434\u043e \u043f\u043e\u043c\u043d\u0438\u0442\u044c, \u0433\u0434\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u0432\u043e\u0435\u0442\u043e\u0447\u0438\u0435:  <\/p>\n<pre><code class=\"lua\">MyClass:myFunc() <\/code><\/pre>\n<p>  \u0430 \u0433\u0434\u0435 \u043f\u0440\u043e\u0441\u0442\u043e \u043e\u0434\u043d\u0443 \u0442\u043e\u0447\u043a\u0443:  <\/p>\n<pre><code class=\"lua\">MyClass.myOtherFunc() <\/code><\/pre>\n<p>  \u0410 \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0447\u043b\u0435\u043d\u044b \u043a\u043b\u0430\u0441\u0441\u0430? \u041d\u0435\u0443\u0436\u0435\u043b\u0438 \u043f\u0440\u0438\u0434\u0451\u0442\u0441\u044f \u043e\u0442\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c\u0441\u044f?  <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-182018","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/182018","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=182018"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/182018\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=182018"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=182018"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=182018"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}