<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Lua ООП конспект]]></title><description><![CDATA[<p dir="auto">Пригодится для создания больших плагинов в Cheat Engine. Более ~500 строк</p>
<p dir="auto">Наследование</p>
<pre><code>ClassX = {}

	function ClassX:New(_argument1, _argument2)

		local obj = {}
		obj.argument1 = _argument1
		obj.argument2 = _argument2

		-- Через "self"
		function obj:GetValue1() return obj.argument1 end
		function obj:GetValue2() return obj.argument2 end

		setmetatable(obj, self)
		obj.__index = ClassX
		return obj
	end

	someObject = ClassX:New("A", "B")
	print(someObject.GetValue1())
	print(someObject.GetValue2())


   	Woman = {}
	--наследуемся
	setmetatable(Woman ,{__index = ClassX})
	--проверяем
	masha = Woman:New("Марья","Ивановна")
	print(masha:GetValue1())  ---&gt;результат: Марья
</code></pre>
<p dir="auto">Инкапсуляция</p>
<pre><code>Person = {}
	function Person:new(name)
		--приватное свойство
		local private = {}
		private.age = 18

		local obj = {}
		--публичное свойство
		obj.name = name or "Вася"   -- "Вася" - это значение по умолчанию

		function obj:getAge() return private.age end

		setmetatable(obj,self)
		self.__index = self
		return obj
	end

	vasya = Person:new()
	print(vasya.name)          --&gt; результат: Вася
	print(vasya.age)           --&gt; результат: nil
	print(vasya:getAge())     --&gt; результат: 18
</code></pre>
<p dir="auto">Полиморфизм</p>
<pre><code>Person = {}
	function Person:New(name)
		local private = {}
		private.age = 18

		local obj = {}
		obj.name = name or "Вася"
		-- Защищенный от переорпеделения
		function obj:GetName() return "Person protected "..self.name end
		-- Переопределяемый
		function Person:GetName2() return "Person "..self.name	end

		setmetatable(obj, self)
		self.__index = self
		return obj
	end

	--создадим класс, унаследованный от Person
	Woman = {}
	setmetatable(Woman,{__index = Person})
	function Woman:GetName() return "Woman protected "..self.name end
	function Woman:GetName2() return "Woman "..self.name end

	--проверим
	masha = Woman:New()
	print(masha:GetName())   --&gt; Person protected Вася
	print(masha:GetName2())  --&gt; Woman Вася
</code></pre>
<p dir="auto"><a href="https://habr.com/ru/articles/259265/" target="_blank" rel="noopener noreferrer nofollow ugc">ref</a></p>
]]></description><link>https://celua.ru/topic/58/lua-ооп-конспект</link><generator>RSS for Node</generator><lastBuildDate>Tue, 18 Aug 2026 11:52:48 GMT</lastBuildDate><atom:link href="https://celua.ru/topic/58.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 07 Apr 2023 22:02:19 GMT</pubDate><ttl>60</ttl></channel></rss>