{"id":343167,"date":"2022-12-26T15:02:13","date_gmt":"2022-12-26T15:02:13","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=343167"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=343167","title":{"rendered":"<span>\u0421\u043e\u0437\u0434\u0430\u0451\u043c \u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c \u0441\u0441\u044b\u043b\u043a\u0438 \u043d\u0430 \u0438\u0433\u0440\u043e\u0432\u044b\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u044b (\u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438) \u0432 C++ \u0438 Lua<\/span>"},"content":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-1\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\"><a href=\"https:\/\/habr.com\/ru\/company\/piter\/blog\/707672\/\"><\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/9t\/c_\/ew\/9tc_ewnjnrmzxybaxnxuhoi0qac.png\" alt=\"image\" data-src=\"https:\/\/habrastorage.org\/webt\/9t\/c_\/ew\/9tc_ewnjnrmzxybaxnxuhoi0qac.png\"\/><\/div>\n<p><\/a><br \/>  \u041e\u0447\u0435\u043d\u044c \u0447\u0430\u0441\u0442\u043e \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0441 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u043e\u0439 \u0441\u0441\u044b\u043b\u043e\u043a \u043d\u0430 \u0438\u0433\u0440\u043e\u0432\u044b\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u044b (\u043d\u0430\u0437\u043e\u0432\u0443 \u044d\u0442\u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044f\u043c\u0438). \u0418\u043d\u043e\u0433\u0434\u0430 \u0440\u0435\u0447\u044c \u0438\u0434\u0451\u0442 \u043e\u0431 \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044f\u0445 \u00ab\u043f\u0440\u0435\u0434\u043e\u043a-\u043f\u043e\u0442\u043e\u043c\u043e\u043a\u00bb \u043c\u0435\u0436\u0434\u0443 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044f\u043c\u0438. \u0411\u044b\u0432\u0430\u0435\u0442, \u0447\u0442\u043e \u043f\u043e\u043b\u0435\u0437\u043d\u043e \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 \u043e\u0431\u044a\u0435\u043a\u0442 \u043f\u0440\u0438 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u043e \u0441\u043e\u0431\u044b\u0442\u0438\u044f\u0445, \u0432 \u043a\u043b\u0430\u0441\u0441\u0435 \u043f\u043b\u0430\u043d\u0438\u0440\u043e\u0432\u0449\u0438\u043a\u0430 \u0437\u0430\u0434\u0430\u0447 \u0438 \u0442.\u0434.<\/p>\n<p>  \u0418\u043d\u043e\u0433\u0434\u0430 \u043c\u043e\u0436\u043d\u043e \u043e\u0431\u043e\u0439\u0442\u0438\u0441\u044c \u043f\u0440\u043e\u0441\u0442\u044b\u043c \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0435\u043c, \u0441\u0441\u044b\u043b\u043a\u043e\u0439 \u0438\u043b\u0438 std::reference_wrapper. \u041d\u043e \u043f\u0440\u0438 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 \u043e\u0431\u044b\u0447\u043d\u044b\u043c\u0438 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044f\u043c\u0438 \u0438 \u0441\u0441\u044b\u043b\u043a\u0430\u043c\u0438 \u0435\u0441\u0442\u044c \u0442\u0430\u043a\u0430\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430: \u0435\u0441\u043b\u0438 \u0432\u044b \u0438\u043c\u0438 \u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0435\u0441\u044c, \u0442\u043e \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c \u0443\u0432\u0435\u0440\u0435\u043d\u044b, \u0447\u0442\u043e \u0442\u0430 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0430 \u0441\u0441\u044b\u043b\u043a\u0430, \u043e\u0441\u0442\u0430\u0451\u0442\u0441\u044f \u0436\u0438\u0432\u0430 \u0438 \u043d\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u0449\u0430\u0435\u0442\u0441\u044f \u0432 \u043f\u0430\u043c\u044f\u0442\u0438 \u0431\u0435\u0437 \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u044f \u0442\u0435\u0445 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432, \u0447\u0442\u043e \u0434\u0435\u0440\u0436\u0430\u0442 \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 \u043d\u0435\u0451. \u041f\u043e\u0436\u0430\u043b\u0443\u0439, \u0432 \u0445\u043e\u0440\u043e\u0448\u043e \u0441\u043f\u0440\u043e\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0439 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0435 \u044d\u0442\u043e \u0434\u043e\u0441\u0442\u0438\u0436\u0438\u043c\u043e.<\/p>\n<p>  \u041e\u0434\u043d\u0430\u043a\u043e \u0443\u0441\u0442\u0430\u0440\u0435\u0432\u0448\u0438\u0435 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0438\/\u0441\u0441\u044b\u043b\u043a\u0438 \u043f\u0440\u043e\u0432\u043e\u0446\u0438\u0440\u0443\u044e\u0442 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0433\u043d\u0443\u0441\u043d\u0435\u0439\u0448\u0438\u0435 \u0431\u0430\u0433\u0438. \u042d\u0442\u0438 \u0431\u0430\u0433\u0438 \u0441\u043b\u043e\u0436\u043d\u043e \u043e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u0442\u044c, \u043d\u0435 \u0442\u0430\u043a \u043b\u0435\u0433\u043a\u043e \u0432\u044b\u044f\u0432\u0438\u0442\u044c, \u0438 \u043e\u043d\u0438 \u043c\u043e\u0433\u0443\u0442 \u043e\u0431\u0440\u0443\u0448\u0438\u0442\u044c \u0432\u0430\u0448\u0443 \u0438\u0433\u0440\u0443. \u041d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 \u043c\u043e\u0433\u0443\u0442 \u0437\u0430\u043d\u0438\u043c\u0430\u0442\u044c \u0432 \u043f\u0430\u043c\u044f\u0442\u0438 \u0438\u043d\u044b\u0435 \u0430\u0434\u0440\u0435\u0441\u0430, \u043d\u0435\u0436\u0435\u043b\u0438 \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u043b\u043e\u0441\u044c (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u043e\u0441\u043b\u0435 \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u0432\u044b \u043f\u0435\u0440\u0435\u0437\u0430\u0433\u0440\u0443\u0437\u0438\u0442\u0435 \u0443\u0440\u043e\u0432\u0435\u043d\u044c \u0438\u043b\u0438 \u0440\u0435\u0448\u0438\u0442\u0435 \u0437\u0430\u043d\u043e\u0432\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0441 \u043d\u0443\u043b\u044f \u0432\u0441\u0435\u0445 \u0432\u0440\u0430\u0433\u043e\u0432). \u041a\u043e\u043d\u0435\u0447\u043d\u043e, \u043c\u043e\u0436\u043d\u043e \u0438 \u0432\u0440\u0443\u0447\u043d\u0443\u044e \u043e\u0431\u043d\u043e\u0432\u0438\u0442\u044c \u0432\u0441\u0435 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0438 \u043d\u0430 \u0442\u0435 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u044b \u0440\u0430\u043d\u0435\u0435 \u0441\u0441\u044b\u043b\u0430\u043b\u0438\u0441\u044c. \u041d\u043e, \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u043e, \u044d\u0442\u043e \u043b\u0443\u0447\u0448\u0435 \u0434\u0435\u043b\u0430\u0442\u044c \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438, \u0447\u0442\u043e\u0431\u044b \u043d\u0435 \u043e\u0441\u0442\u0430\u0432\u0430\u043b\u043e\u0441\u044c \u043d\u0438\u043a\u0430\u043a\u043e\u0439 \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u0438 \u0437\u0430\u0431\u044b\u0442\u044c \u043a\u0430\u043a\u0438\u0435-\u043b\u0438\u0431\u043e \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u0442\u043e\u043c \u0443\u0441\u0442\u0430\u0440\u0435\u044e\u0442.<\/p>\n<p>  \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0440\u0435\u0448\u0438\u0442\u044c \u0432\u0441\u0435 \u044d\u0442\u0438 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b. \u041d\u043e\u0432\u0435\u0439\u0448\u0435\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 (\u0441\u0432\u044f\u0437\u0430\u043d\u043d\u043e\u0435 \u0441 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435\u043c \u0441\u0441\u044b\u043b\u043e\u043a \u0432 Lua) \u0431\u044b\u043b\u043e \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0435\u043d\u043e \u043c\u043d\u043e\u044e \u043d\u0435 \u0442\u0430\u043a \u0434\u0430\u0432\u043d\u043e \u0438 \u043f\u043e\u0431\u0443\u0434\u0438\u043b\u043e \u043c\u0435\u043d\u044f \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u044d\u0442\u0443 \u0441\u0442\u0430\u0442\u044c\u044e, \u043d\u043e \u044f \u0445\u043e\u0447\u0443 \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c, \u0447\u0442\u043e \u0435\u0441\u0442\u044c \u0438 \u0434\u0440\u0443\u0433\u0438\u0435 \u0441\u043f\u043e\u0441\u043e\u0431\u044b \u0440\u0435\u0448\u0438\u0442\u044c \u044d\u0442\u0443 \u0437\u0430\u0434\u0430\u0447\u0443. \u041f\u0440\u0438\u0441\u0442\u0443\u043f\u0438\u043c! <a name=\"habracut\"><\/a><\/p>\n<h2>shared_ptr \u0438 weak_ptr<\/h2>\n<p>  \u041d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u0441 \u043e\u0431\u044b\u0447\u043d\u044b\u043c\u0438 \u0441\u0441\u044b\u043b\u043a\u0430\u043c\u0438 \u0440\u0435\u0448\u0430\u0435\u043c\u044b \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 std::shared_ptr \u0438 std::weak_ptr. \u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u0451\u043c \u043d\u0430\u0448\u0438 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 \u0442\u0430\u043a, \u043a\u0430\u043a \u044d\u0442\u043e \u0434\u0435\u043b\u0430\u043b\u043e\u0441\u044c \u0431\u044b \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 std::make_shared. \u041f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e \u0441\u043e\u0437\u0434\u0430\u0451\u043c \u0432\u0441\u0435 \u0441\u0441\u044b\u043b\u043a\u0438 \u043d\u0430 \u043d\u0438\u0445 \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 std::weak_ptr, \u0447\u0442\u043e \u043d\u0435 \u043f\u043e\u0432\u043b\u0438\u044f\u0435\u0442 \u043d\u0430 \u0432\u0440\u0435\u043c\u044f \u0436\u0438\u0437\u043d\u0438 \u0432\u0430\u0448\u0435\u0439 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438. \u041f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0435\u0439 std::weak_ptr::expired, \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c, \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u0430 \u043b\u0438 \u0441\u0441\u044b\u043b\u043a\u0430 \u0434\u043e \u0441\u0438\u0445 \u043f\u043e\u0440. <\/p>\n<p>  \u042d\u0442\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u043d\u0435\u0441\u043e\u0432\u0435\u0440\u0448\u0435\u043d\u043d\u043e. \u041f\u0440\u0435\u0436\u0434\u0435 \u0432\u0441\u0435\u0433\u043e, \u043f\u043e\u0442\u043e\u043c\u0443, \u0447\u0442\u043e \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0432\u0441\u0435 \u0432\u0430\u0448\u0438 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 \u0432 \u0432\u0438\u0434\u0435 shared_ptr, \u0430 \u044d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u0432\u043b\u0435\u0447\u044c \u0441\u0435\u0440\u044c\u0451\u0437\u043d\u044b\u0435 \u0438\u0437\u0434\u0435\u0440\u0436\u043a\u0438 \u043f\u043e \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044e \u0441 unique_ptr. \u0412 \u043a\u043e\u043d\u0446\u0435 \u043a\u043e\u043d\u0446\u043e\u0432, \u043b\u0443\u0447\u0448\u0435 \u043d\u0435 \u0434\u0435\u043b\u0430\u0442\u044c \u0432\u0440\u0435\u043c\u044f \u0436\u0438\u0437\u043d\u0438 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0435\u0439 \u0440\u0430\u0437\u0434\u0435\u043b\u044f\u0435\u043c\u044b\u043c, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u043b\u0443\u0447\u0448\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0441\u0435\u043c\u0430\u043d\u0442\u0438\u043a\u043e\u0439 unique_ptr. \u041a\u0440\u043e\u043c\u0435 \u0442\u043e\u0433\u043e, \u0440\u0430\u0437\u0434\u0435\u043b\u044f\u0435\u043c\u044b\u0435 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0438 \u043d\u0435 \u0440\u0435\u0448\u0430\u044e\u0442 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443 \u043f\u0435\u0440\u0435\u043c\u0435\u0449\u0435\u043d\u0438\u044f \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0435\u0439 \u0432 \u043f\u0430\u043c\u044f\u0442\u0438: \u0432\u044b \u043d\u0435 \u0441\u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u043e\u043c\u0435\u043d\u044f\u0442\u044c \u0442\u043e, \u0447\u0442\u043e \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0432 shared_ptr \u0438 \u0437\u0430\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0432\u0441\u0435 weak_ptr \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043e\u0431\u043d\u043e\u0432\u0438\u0442\u044c \u0438\u0445 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0438. <\/p>\n<h2>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0445 id<\/h2>\n<p>  \u041f\u0440\u043e\u0431\u043b\u0435\u043c\u0443 \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0431\u044b \u0440\u0435\u0448\u0438\u0442\u044c, \u043f\u0440\u043e\u0441\u0442\u043e \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u044f \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0435 id \u0434\u043b\u044f \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0435\u0439 \u0438 \u0445\u0440\u0430\u043d\u044f \u0438\u043c\u0435\u043d\u043d\u043e \u044d\u0442\u0438 id, \u0430 \u043d\u0435 \u043e\u0431\u044b\u0447\u043d\u044b\u0435 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0438 \u0438\u043b\u0438 \u0441\u0441\u044b\u043b\u043a\u0438. \u0415\u0441\u0442\u044c \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u0432 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c id \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0435\u0439. Id \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0432 \u0432\u0438\u0434\u0435 \u043e\u0431\u044b\u0447\u043d\u044b\u0445 \u0446\u0435\u043b\u044b\u0445 \u0447\u0438\u0441\u0435\u043b \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 EntityManager \u0438 \u0441\u0447\u0451\u0442\u0447\u0438\u043a\u0430, \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0431\u0443\u0434\u0435\u0442 \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u0442\u044c\u0441\u044f \u043f\u043e \u043c\u0435\u0440\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043d\u043e\u0432\u044b\u0445 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0435\u0439: \u043f\u0435\u0440\u0432\u0430\u044f \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c \u043f\u043e\u043b\u0443\u0447\u0438\u0442 id=0, \u0432\u0442\u043e\u0440\u0430\u044f id=1 \u0438 \u0442.\u0434. \u0415\u0449\u0435 id \u043c\u043e\u0436\u043d\u043e \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 \u043a\u0430\u043a\u043e\u0433\u043e-\u043d\u0438\u0431\u0443\u0434\u044c \u0445\u0435\u0448\u0438\u0440\u0443\u044e\u0449\u0435\u0433\u043e \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430 \u0438\u043b\u0438 <a href=\"https:\/\/en.wikipedia.org\/wiki\/Universally_unique_identifier\">UUID<\/a>. \u0427\u0442\u043e \u0431\u044b \u043d\u0438 \u0441\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c, \u0432\u0430\u0448\u0438 id \u0434\u043e\u043b\u0436\u043d\u044b \u043e\u0441\u0442\u0430\u0432\u0430\u0442\u044c\u0441\u044f \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u043c\u0438, \u0435\u0441\u043b\u0438 \u0432\u044b \u0442\u043e\u043b\u044c\u043a\u043e \u0441\u0430\u043c\u0438 \u043d\u0435 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u0435 \u043a id \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u0443\u044e \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u0443\u044e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432\u0440\u0435\u043c\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 \u0438\u043b\u0438 \u043a\u0430\u043a\u0438\u0435-\u043d\u0438\u0431\u0443\u0434\u044c \u0442\u0435\u0433\u0438).<\/p>\n<p>  \u0412\u043e\u0442 \u043a\u0430\u043a \u043c\u043e\u0433 \u0431\u044b \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0432\u0430\u0448 \u043a\u043b\u0430\u0441\u0441 EntityManager:<\/p>\n<pre><code class=\"javascript\">class EntityManager { public:     Entity* getEntity(EntityId id) const;     bool entityExists(EntityId id) const;     \/\/ ... private:     std::unordered_map&lt;EntityId, std::unique_ptr&lt;Entity>> entities;     \/\/ ... };<\/code><\/pre>\n<p>  \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f id, \u0442\u0430\u043a\u0436\u0435 \u043b\u0435\u0433\u0447\u0435 \u0440\u0435\u0448\u0438\u0442\u044c \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443 \u0441 \u0432\u043e\u0441\u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435\u043c: \u043c\u043e\u0436\u043d\u043e \u0441 \u043b\u0435\u0433\u043a\u043e\u0441\u0442\u044c\u044e \u0432\u043e\u0441\u0441\u043e\u0437\u0434\u0430\u0442\u044c\/\u043f\u0435\u0440\u0435\u0437\u0430\u0433\u0440\u0443\u0437\u0438\u0442\u044c \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c \u0438 \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u0440\u0438\u0441\u0432\u043e\u0438\u0442\u044c \u0435\u0439 \u0442\u043e\u0442 \u0436\u0435 \u0441\u0430\u043c\u044b\u0439 id, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u044b\u043b \u0443 \u043d\u0435\u0451 \u0440\u0430\u043d\u044c\u0448\u0435. \u0414\u0430, \u043e\u043d\u0430 \u0441\u0442\u0430\u043d\u0435\u0442 \u0437\u0430\u043d\u0438\u043c\u0430\u0442\u044c \u043d\u043e\u0432\u044b\u0439 \u0430\u0434\u0440\u0435\u0441 \u0432 \u043f\u0430\u043c\u044f\u0442\u0438, \u043d\u043e, \u043a\u043e\u0433\u0434\u0430 \u043a\u0442\u043e-\u043d\u0438\u0431\u0443\u0434\u044c \u043f\u043e\u0432\u0442\u043e\u0440\u043d\u043e \u0432\u044b\u0437\u043e\u0432\u0435\u0442 getEntity, \u0435\u043c\u0443 \u0431\u0443\u0434\u0435\u0442 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0435\u043d\u0430 \u043e\u0431\u043d\u043e\u0432\u043b\u0451\u043d\u043d\u0430\u044f \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c. \u042d\u0442\u0438 id \u0442\u0430\u043a\u0436\u0435 \u043c\u043e\u0436\u043d\u043e \u0441 \u043b\u0451\u0433\u043a\u043e\u0441\u0442\u044c\u044e \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c \u043f\u043e \u0441\u0435\u0442\u0438 \u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0442\u044c \u0432 \u0444\u0430\u0439\u043b\u0430\u0445. <\/p>\n<p>  \u041f\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 id \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0435\u0439 \u0432\u0430\u0448 \u043a\u043e\u0434 \u043f\u0440\u0438\u043c\u0435\u0442 \u0432\u0438\u0434:<\/p>\n<pre><code class=\"javascript\">auto entityPtr = g_EntityManager.getEntity(entityId); entityPtr->doSomething();<\/code><\/pre>\n<p>  \u0420\u0430\u0437\u0443\u043c\u0435\u0435\u0442\u0441\u044f, \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u044e\u0442 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0438\u0437\u0434\u0435\u0440\u0436\u043a\u0438, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0442\u0435\u043f\u0435\u0440\u044c \u0443 \u043d\u0430\u0441 \u043f\u043e\u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0443\u0440\u043e\u0432\u0435\u043d\u044c \u043a\u043e\u0441\u0432\u0435\u043d\u043d\u043e\u0441\u0442\u0438: \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0438\u0441\u043a\u0430\u0442\u044c \u0432 unordered_map \u0432\u043d\u0443\u0442\u0440\u0438 EntityManager, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043e\u0431\u044b\u0447\u043d\u0443\u044e \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c, \u043d\u043e, \u0435\u0441\u043b\u0438 \u0432\u044b \u043d\u0435 \u0445\u043e\u0442\u0438\u0442\u0435 \u0434\u0435\u043b\u0430\u0442\u044c \u044d\u0442\u043e\u0433\u043e \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u0447\u0430\u0441\u0442\u043e (\u0441\u043a\u043e\u0440\u0435\u0435 \u0432\u0441\u0435\u0433\u043e \u2013 \u043d\u0435 \u0445\u043e\u0442\u0438\u0442\u0435), \u0442\u043e \u0432\u0430\u0441 \u044d\u0442\u043e \u0443\u0441\u0442\u0440\u043e\u0438\u0442!<\/p>\n<p>  \u0417\u0434\u0435\u0441\u044c \u043c\u043e\u0436\u043d\u043e \u0432\u043d\u0435\u0441\u0442\u0438 \u0438 \u0435\u0449\u0435 \u043e\u0434\u043d\u043e \u0443\u043b\u0443\u0447\u0448\u0435\u043d\u0438\u0435: \u043c\u043e\u0436\u043d\u043e \u043e\u0431\u0435\u0440\u043d\u0443\u0442\u044c \u0432\u0430\u0448 id \u0432 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443, \u0430 \u0437\u0430\u0442\u0435\u043c \u043f\u0435\u0440\u0435\u0433\u0440\u0443\u0437\u0438\u0442\u044c operator-> \u0442\u0430\u043a, \u0447\u0442\u043e\u0431\u044b \u043e\u043f\u0438\u0441\u0430\u0442\u0435\u043b\u044c \u0434\u0435\u0439\u0441\u0442\u0432\u043e\u0432\u0430\u043b \u043a\u0430\u043a \u043e\u0431\u044b\u0447\u043d\u044b\u0439 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c:<\/p>\n<pre><code class=\"javascript\">struct EntityHandle {     EntityId id;     EntityManager* entityManager;      EntityHandle(EntityId id, EntityManager* entityManager) :         id(id), entityManager(entityManager)     {}      Entity* operator->() const {         return get();     }      Entity* get() const {         assert(entityManager->entityExists(id));         return entityManager->getEntity(id);     } };<\/code><\/pre>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0436\u043d\u043e \u0434\u0435\u043b\u0430\u0442\u044c \u0442\u0430\u043a\u0438\u0435 \u0432\u0435\u0449\u0438:<\/p>\n<pre><code class=\"javascript\">EntityHandle handle(someEntityId, &amp;g_EntityManager); handle->doSomething();  \/\/ or...  auto entityPtr = handle.get(); entityPtr->doSomething();<\/code><\/pre>\n<p>  \u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435: \u0442\u0430\u043a\u0436\u0435 \u0443 \u043d\u0430\u0441 \u043f\u043e\u044f\u0432\u0438\u043b\u0430\u0441\u044c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u0430\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u043e\u0448\u0438\u0431\u043e\u043a, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0449\u0430\u044f \u0432\u044b\u0434\u0432\u0438\u0433\u0430\u0442\u044c \u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0442\u044c \u0443\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u0438\u044f \u043e \u0442\u043e\u043c, \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u044b \u043b\u0438 \u0441\u0441\u044b\u043b\u043a\u0438. \u041e\u0442\u043b\u0438\u0447\u043d\u043e! \u0422\u0435\u043f\u0435\u0440\u044c \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0441\u0441\u044b\u043b\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 \u0432 \u0441\u043a\u0440\u0438\u043f\u0442\u0430\u0445 \u043d\u0430 Lua.<\/p>\n<h2>\u0421\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u0441\u0441\u044b\u043b\u043e\u043a \u043d\u0430 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 \u0432 Lua<\/h2>\n<p>  <\/p>\n<blockquote><p>\u041f\u043e\u043b\u043d\u0430\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0437\u0434\u0435\u0441\u044c: <a href=\"https:\/\/gist.github.com\/eliasdaler\/f5c2ee50fc7e42bf3ee18ad7d46d18f8\">\u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u043d\u0430 C++<\/a>, <a href=\"https:\/\/gist.github.com\/eliasdaler\/f3516d3deabc32b465a7c244ff082cf0\">\u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u043d\u0430 Lua<\/a>.<\/p><\/blockquote>\n<p>  \u041f\u0440\u0435\u0436\u0434\u0435 \u0432\u0441\u0435\u0433\u043e, \u043e\u0442\u043c\u0435\u0442\u0438\u043c \u043e\u0447\u0435\u0432\u0438\u0434\u043d\u043e\u0435: \u044d\u0442\u043e\u0442 \u043f\u043e\u0434\u0445\u043e\u0434 \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u043c \u0438 \u0432 Lua. \u0412\u0430\u0448 \u043e\u043f\u0438\u0441\u0430\u0442\u0435\u043b\u044c \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c \u0441\u043e\u0431\u043e\u0439 \u043f\u0440\u043e\u0441\u0442\u043e \u0447\u0438\u0441\u043b\u043e \u0438\u043b\u0438 \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u0441 \u043c\u0435\u0442\u0430-\u043c\u0435\u0442\u043e\u0434\u043e\u043c __index, \u0442\u0430\u043a, \u0447\u0442\u043e \u043e\u043f\u0438\u0441\u0430\u0442\u0435\u043b\u0435\u043c \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0442\u043e\u0447\u043d\u043e, \u043a\u0430\u043a \u043e\u0431\u044b\u0447\u043d\u043e\u0439 \u0441\u0441\u044b\u043b\u043a\u043e\u0439. \u041d\u043e \u0435\u0441\u0442\u044c \u0438 \u0431\u043e\u043b\u0435\u0435 \u0441\u0438\u043c\u043f\u0430\u0442\u0438\u0447\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0435\u0434\u0430\u0432\u043d\u043e \u043c\u043d\u0435 \u043f\u043e\u0434\u0432\u0435\u0440\u043d\u0443\u043b\u0441\u044f. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043a\u0430\u043a \u043e\u043d \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442.<\/p>\n<p>  \u041d\u0430\u0447\u043d\u0451\u043c \u0441 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043e\u043f\u0438\u0441\u0430\u0442\u0435\u043b\u0435\u0439 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u0430\u043c\u0438 \u0441 \u043e\u0431\u044b\u0447\u043d\u044b\u043c\u0438 \u0441\u0441\u044b\u043b\u043a\u0430\u043c\u0438 C++, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u0443\u0434\u0443\u0442 \u0445\u0440\u0430\u043d\u0438\u0442\u044c\u0441\u044f \u0432 \u044d\u0442\u0438\u0445 \u0442\u0430\u0431\u043b\u0438\u0446\u0430\u0445 \u043a\u0430\u043a \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0435. \u0422\u0430\u043a\u0436\u0435 \u0437\u0434\u0435\u0441\u044c \u0435\u0441\u0442\u044c \u0431\u0443\u043b\u0435\u0432\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 isValid, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043f\u043e\u043c\u043e\u0436\u0435\u0442 \u043d\u0430\u043c \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c, \u043f\u043e-\u043f\u0440\u0435\u0436\u043d\u0435\u043c\u0443 \u043b\u0438 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u0435\u043d \u043e\u043f\u0438\u0441\u0430\u0442\u0435\u043b\u044c. \u0422\u0430\u043a\u0436\u0435 \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0438 \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u0430\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u0441\u0441\u044b\u043b\u043e\u043a \u0432 Lua, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043c\u043e\u0436\u043d\u043e \u0441 \u043b\u0451\u0433\u043a\u043e\u0441\u0442\u044c\u044e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043e\u0442\u043a\u0443\u0434\u0430 \u0443\u0433\u043e\u0434\u043d\u043e, \u043d\u0435 \u0432\u044b\u0437\u044b\u0432\u0430\u044f C++. \u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043f\u0440\u0438\u044f\u0442\u043d\u043e, \u0447\u0442\u043e \u0432\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0435 \u0438\u043c\u0435\u043d\u043d\u043e <b>\u0441\u0441\u044b\u043b\u043a\u0438<\/b> \u043d\u0430 \u0432\u0430\u0448\u0438 \u043e\u043f\u0438\u0441\u0430\u0442\u0435\u043b\u0438, \u0430 \u043d\u0435 \u043a\u043e\u043f\u0438\u0438. \u042d\u0442\u043e \u043e\u0442\u043b\u0438\u0447\u043d\u043e, \u0442\u0430\u043a \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0431\u0435\u0437 \u0442\u0440\u0443\u0434\u0430 \u0441\u0440\u0430\u0432\u043d\u0438\u0442\u044c \u0434\u0432\u0430 \u043e\u043f\u0438\u0441\u0430\u0442\u0435\u043b\u044f \u0438\u043b\u0438 \u0434\u0430\u0436\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0438\u0445 \u043a\u0430\u043a \u0442\u0430\u0431\u043b\u0438\u0447\u043d\u044b\u0435 \u043a\u043b\u044e\u0447\u0438. \u0412\u044b \u043d\u0435 \u0440\u0430\u0441\u0442\u0440\u0430\u0447\u0438\u0432\u0430\u0435\u0442\u0435 \u043f\u0430\u043c\u044f\u0442\u044c, \u043d\u043e \u044d\u0442\u0430 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0432\u0441\u0451 \u0440\u0430\u0432\u043d\u043e \u043d\u0435 \u0442\u0430\u043a \u0441\u0435\u0440\u044c\u0451\u0437\u043d\u0430, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0438 \u043e\u0447\u0435\u043d\u044c \u043b\u0435\u0433\u043a\u043e\u0432\u0435\u0441\u043d\u044b\u0435.<\/p>\n<p>  \u0415\u0441\u043b\u0438 \u0432\u044b \u0445\u043e\u0442\u0438\u0442\u0435 \u0443\u0434\u0430\u043b\u0438\u0442\u044c \u0438\u043b\u0438 \u0432\u043e\u0441\u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043a\u0430\u043a\u0443\u044e-\u043b\u0438\u0431\u043e \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c, \u0442\u043e \u0434\u043e\u043b\u0436\u043d\u044b \u0443\u0432\u0435\u0434\u043e\u043c\u0438\u0442\u044c \u043e\u0431 \u044d\u0442\u043e\u043c \u0433\u043b\u0430\u0432\u043d\u044b\u0439 \u043e\u043f\u0438\u0441\u0430\u0442\u0435\u043b\u044c Lua, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0445\u0440\u0430\u043d\u0438\u0442\u044c\u0441\u044f \u0432 \u043a\u0430\u043a\u043e\u0439-\u043d\u0438\u0431\u0443\u0434\u044c \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 Lua. \u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0432\u0441\u0435 \u0432\u0430\u0448\u0438 \u043e\u043f\u0438\u0441\u0430\u0442\u0435\u043b\u0438 \u043d\u0430 Lua \u0431\u0443\u0434\u0443\u0442 \u0441\u0441\u044b\u043b\u043a\u0430\u043c\u0438 \u043d\u0430 \u0433\u043b\u0430\u0432\u043d\u044b\u0439 \u043e\u043f\u0438\u0441\u0430\u0442\u0435\u043b\u044c, \u043e \u043d\u0438\u0445 \u043c\u043e\u0436\u043d\u043e \u043d\u0435 \u0432\u043e\u043b\u043d\u043e\u0432\u0430\u0442\u044c\u0441\u044f: \u043a\u0430\u043a \u0442\u043e\u043b\u044c\u043a\u043e \u0432\u044b \u043e\u0431\u043d\u043e\u0432\u0438\u0442\u0435 \u0433\u043b\u0430\u0432\u043d\u044b\u0439 \u043e\u043f\u0438\u0441\u0430\u0442\u0435\u043b\u044c, \u043e\u043d \u043e\u0431\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u043f\u043e\u0432\u0441\u044e\u0434\u0443.<br \/>  \u0415\u0449\u0451 \u043e\u0434\u043d\u043e \u0434\u043e\u0441\u0442\u043e\u0438\u043d\u0441\u0442\u0432\u043e \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c: \u043a\u0430\u043a \u0442\u043e\u043b\u044c\u043a\u043e \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c \u0443\u0434\u0430\u043b\u044f\u0435\u0442\u0441\u044f, \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c isValid \u0432 false \u0438 \u043e\u0431\u044b\u0447\u043d\u0443\u044e \u0441\u0441\u044b\u043b\u043a\u0443 \u0432 nil \u2013 \u043f\u0440\u043e\u0441\u0442\u043e \u0434\u043b\u044f \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u0438. <\/p>\n<p>  \u041f\u0435\u0440\u0435\u0439\u0434\u0451\u043c \u043a \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438! \u0412\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u0441\u044f <a href=\"https:\/\/github.com\/ThePhD\/sol2\">sol2<\/a> \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u0434\u043b\u044f \u0441\u0432\u044f\u0437\u044b\u0432\u0430\u043d\u0438\u044f Lua\/C++. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043d\u0430\u043f\u0438\u0448\u0435\u043c \u043f\u0440\u043e\u0441\u0442\u044b\u0435 \u043a\u043b\u0430\u0441\u0441\u044b Entity \u0438 EntityManager \u0434\u043b\u044f \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f:<\/p>\n<pre><code class=\"javascript\">using EntityId = int;  class Entity { public:     explicit Entity(EntityId id) :         name(\"John\"), id(id)     {}      const std::string&amp; getName() const { return name; }     void setName(const std::string&amp; n) { name = n; }     EntityId getId() const { return id; } private:     std::string name;     EntityId id; };  sol::state lua; \/\/ \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u2013 \u044d\u0442\u043e \u043f\u043b\u043e\u0445\u043e, \u043d\u043e \u043c\u044b \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u0441\u044f \u0438\u043c\u0438, \u0447\u0442\u043e\u0431\u044b \u0443\u043f\u0440\u043e\u0441\u0442\u0438\u0442\u044c \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e   class EntityManager { public:     EntityManager() : idCounter(0) {}      Entity&amp; createEntity()     {         auto id = idCounter;         ++idCounter;          auto inserted = entities.emplace(id, std::make_unique&lt;Entity>(id));         auto it = inserted.first; \/\/ \u0438\u0442\u0435\u0440\u0430\u0442\u043e\u0440 \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u043e\u0439 \u043f\u0430\u0440\u044b id\/\u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c          auto&amp; e = *it->second; \/\/ \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u0430\u044f \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c         lua[\"createHandle\"](e);         return e;     }      void removeEntity(EntityId id)     {         lua[\"onEntityRemoved\"](id);         entities.erase(id);     } private:     std::unordered_map&lt;EntityId, std::unique_ptr&lt;Entity>> entities;     EntityId idCounter; };<\/code><\/pre>\n<p>  \u0412\u043e\u0442 \u043a\u0430\u043a \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043e\u043f\u0438\u0441\u0430\u0442\u0435\u043b\u044c \u043d\u0430 Lua:<\/p>\n<pre><code class=\"javascript\">function createHandle(cppRef)     local handle = {         cppRef = cppRef,         isValid = true     }     setmetatable(handle, mt)     Handles[cppRef:getId()] = handle     return handle end<\/code><\/pre>\n<p>  \u0412 \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 Handles \u0445\u0440\u0430\u043d\u044f\u0442\u0441\u044f \u0432\u0441\u0435 \u043e\u043f\u0438\u0441\u0430\u0442\u0435\u043b\u0438, \u0442\u0430\u043a \u0447\u0442\u043e \u043c\u044b \u0441\u043c\u043e\u0436\u0435\u043c \u0441 \u043b\u0435\u0433\u043a\u043e\u0441\u0442\u044c\u044e \u0432\u0437\u044f\u0442\u044c \u0438\u0445 \u043e\u0442\u0442\u0443\u0434\u0430 \u043f\u043e\u0437\u0436\u0435. \u041a\u0430\u043a \u0432\u0438\u0434\u0438\u0442\u0435, \u0437\u0434\u0435\u0441\u044c \u043c\u044b \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0446\u0435\u043b\u043e\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u044b\u0435 id \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043a\u043b\u044e\u0447\u0430 \u0442\u0430\u0431\u043b\u0438\u0446\u044b. \u041f\u043e\u044d\u0442\u043e\u043c\u0443, \u0435\u0441\u043b\u0438 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c \u0431\u0443\u0434\u0435\u0442 \u0443\u0434\u0430\u043b\u0435\u043d\u0430, \u043c\u044b \u0441\u043c\u043e\u0436\u0435\u043c \u043b\u0435\u0433\u043a\u043e \u043d\u0430\u0439\u0442\u0438 \u0435\u0451 \u043e\u043f\u0438\u0441\u0430\u0442\u0435\u043b\u044c \u0438 \u0432\u043d\u0435\u0441\u0442\u0438 \u043d\u0443\u0436\u043d\u044b\u0435 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f.<\/p>\n<p>  \u0423 \u044d\u0442\u043e\u0439 \u043c\u0435\u0442\u0430-\u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0435\u0441\u0442\u044c \u0432\u0430\u0436\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f: \u043e\u043d\u0430 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043d\u0430\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043e\u043f\u0438\u0441\u0430\u0442\u0435\u043b\u044c, \u043a\u0430\u043a \u0435\u0441\u043b\u0438 \u0431\u044b \u043e\u043d \u0431\u044b\u043b \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b\u044c\u043d\u043e\u0439 \u0441\u0441\u044b\u043b\u043a\u043e\u0439. \u0412\u043e\u0442 \u043a\u0430\u043a \u044d\u0442\u043e \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442\u0441\u044f:<\/p>\n<pre><code class=\"javascript\">local mt = { } mt.__index = function(handle, key)     if not handle.isValid then         print(debug.traceback())         error(\"Error: handle is not valid!\", 2)     end      return function(handle, ...) return Entity[key](handle.cppRef, ...) end end<\/code><\/pre>\n<p>  \u0411\u044b\u0441\u0442\u0440\u043e \u043d\u0430\u043f\u043e\u043c\u043d\u044e: \u043c\u0435\u0442\u0430\u0442\u0430\u0431\u043b\u0438\u0447\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f __index \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f, \u043a\u043e\u0433\u0434\u0430 \u043a\u043b\u044e\u0447 \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u043d\u0435 \u043d\u0430\u0439\u0434\u0435\u043d, \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u044e\u0442\u0441\u044f \u0441\u0430\u043c\u0430 \u0442\u0430\u0431\u043b\u0438\u0446\u0430 (\u043d\u0430\u0448 \u043e\u043f\u0438\u0441\u0430\u0442\u0435\u043b\u044c) \u0438 \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u044e\u0449\u0438\u0439 \u043a\u043b\u044e\u0447.<\/p>\n<p>  \u0412\u043e\u0442 \u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0449\u0438\u0439, \u043a\u0430\u043a \u0432\u0441\u0435 \u044d\u0442\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442. \u0415\u0441\u043b\u0438 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0442\u0430\u043a: <\/p>\n<pre><code class=\"javascript\">handle:setName(\"John\")<\/code><\/pre>\n<p>  \u0442\u043e Lua \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442, \u0435\u0441\u0442\u044c \u043b\u0438 \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435-\u043e\u043f\u0438\u0441\u0430\u0442\u0435\u043b\u0435 \u043a\u043b\u044e\u0447 \u201csetName\u201d, \u043d\u043e \u0435\u0433\u043e \u0442\u0430\u043c \u043d\u0435\u0442. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043c\u0435\u0442\u0430\u0442\u0430\u0431\u043b\u0438\u0447\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f __index, \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u043c\u0438 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043e\u043f\u0438\u0441\u0430\u0442\u0435\u043b\u044c \u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u201cJohn\u201d. \u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f \u043e\u0431\u0451\u0440\u0442\u043a\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430 Entity, \u0438 \u044d\u0442\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f. \u0422\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043d\u0430\u043c \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f \u2013 \u044d\u0442\u043e \u0437\u0430\u043c\u044b\u043a\u0430\u043d\u0438\u0435, \u0432\u044b\u0437\u044b\u0432\u0430\u044e\u0449\u0435\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430 \u043a\u043b\u0430\u0441\u0441\u0430 Entity \u043f\u043e \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0439 \u043e\u0431\u044b\u0447\u043d\u043e\u0439 \u0441\u0441\u044b\u043b\u043a\u0435. \u041f\u043e\u0447\u0435\u043c\u0443 \u0436\u0435 \u043d\u0430\u043c \u043f\u0440\u043e\u0441\u0442\u043e \u043d\u0435 \u0432\u0435\u0440\u043d\u0443\u0442\u044c Entity[key]? \u0412 \u0442\u0430\u043a\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0432\u043e\u0437\u043d\u0438\u043a\u043b\u0430 \u0431\u044b \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430: \u0432 Entity[key]\u0431\u044b\u043b \u0431\u044b \u043f\u0435\u0440\u0435\u0434\u0430\u043d \u043d\u0430\u0448 \u043e\u043f\u0438\u0441\u0430\u0442\u0435\u043b\u044c, \u0442\u043e\u0433\u0434\u0430 \u043a\u0430\u043a \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043e\u0436\u0438\u0434\u0430\u0435\u0442, \u0447\u0442\u043e \u0435\u0439 \u0431\u0443\u0434\u0435\u0442 \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u0430 \u043e\u0431\u044b\u0447\u043d\u0430\u044f \u0441\u0441\u044b\u043b\u043a\u0430 (cppRef:setName(\u00abJohn\u00bb), \u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e \u044d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e \u0432\u044b\u0437\u043e\u0432\u0443 Entity.setName(cppRef, \u00abJohn\u00bb)).<\/p>\n<p>  \u041f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u043e\u0448\u0438\u0431\u043e\u043a, \u043e\u0440\u0433\u0430\u043d\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u0430\u044f \u043d\u0430\u043c\u0438 \u0437\u0434\u0435\u0441\u044c, \u0438\u0441\u043a\u043b\u044e\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0432\u0430\u0436\u043d\u0430 \u0438 \u043f\u043e\u043b\u0435\u0437\u043d\u0430! \u041e\u043d\u0430 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0441 \u043b\u0451\u0433\u043a\u043e\u0441\u0442\u044c\u044e \u043e\u0442\u043b\u0430\u0436\u0438\u0432\u0430\u0442\u044c \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0433\u0443\u0442 \u0432\u043e\u0437\u043d\u0438\u043a\u043d\u0443\u0442\u044c \u0432 \u043a\u043e\u0434\u0435: \u043c\u044b \u0434\u0430\u0436\u0435 \u0432\u044b\u0432\u043e\u0434\u0438\u043c \u043d\u0430 \u044d\u043a\u0440\u0430\u043d \u0441\u0442\u0435\u043a \u0432\u044b\u0437\u043e\u0432\u043e\u0432, \u0447\u0442\u043e\u0431\u044b \u043d\u0430\u0439\u0442\u0438 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0435 \u043c\u0435\u0441\u0442\u043e, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043e\u0442\u043a\u0430\u0437\u0430\u043b \u043d\u0430\u0448 \u043a\u043e\u0434!<br \/>  \u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435: \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0432\u0442\u043e\u0440\u043e\u0433\u043e \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 error \u043c\u044b \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u043c \u201c2\u201d. \u042d\u0442\u043e\u0442 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442 \u0441\u043e\u043e\u0431\u0449\u0430\u0435\u0442, \u0447\u0442\u043e \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u043d\u0435 \u0432 \u0442\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u0447\u0442\u043e \u0435\u0435 \u0432\u044b\u0437\u0432\u0430\u043b\u0430, \u0430 \u0432 \u0434\u0440\u0443\u0433\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u043d\u043e\u0439 \u043d\u0438\u0436\u0435 \u0432 \u0441\u0442\u0435\u043a\u0435 \u0432\u044b\u0437\u043e\u0432\u043e\u0432.<\/p>\n<p>  \u0415\u0449\u0451 \u043e\u0434\u043d\u043e \u043e\u0442\u043b\u0438\u0447\u043d\u043e\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e \u0434\u0430\u043d\u043d\u043e\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0432 \u043d\u0435\u0439 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0438 \u043d\u0430 \u0441\u0442\u043e\u0440\u043e\u043d\u0435 Lua, \u0430 \u043d\u0435 \u043d\u0430 \u0441\u0442\u043e\u0440\u043e\u043d\u0435 C++. \u0412\u0441\u044f\u043a\u0438\u0439 \u0440\u0430\u0437, \u043a\u043e\u0433\u0434\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f C++ \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0438\u0437 Lua, \u0441\u043b\u043e\u0436\u043d\u043e \u043a\u0430\u043a \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u043e\u0442\u043b\u043e\u0432\u0438\u0442\u044c \u0438 \u0432\u044b\u0431\u0440\u043e\u0441\u0438\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0443 \u0438\u0437 C++. \u041f\u0440\u0438\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c Lua \u043a\u0430\u043a C++, \u0447\u0442\u043e\u0431\u044b \u0432\u0441\u0451 \u043f\u0440\u043e\u0448\u043b\u043e \u0431\u0435\u0437 \u043e\u0442\u043a\u0430\u0437\u043e\u0432. \u0415\u0441\u043b\u0438 \u0432\u044b\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0443 \u0434\u043e \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c C++, \u0442\u043e \u043c\u044b \u0441\u043c\u043e\u0436\u0435\u043c \u043b\u0435\u0433\u043a\u043e \u043e\u0442\u043b\u043e\u0432\u0438\u0442\u044c \u0435\u0451 \u043d\u0430 \u0441\u0442\u043e\u0440\u043e\u043d\u0435 Lua \u0438 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c. \u0427\u0443\u0442\u044c \u043d\u0438\u0436\u0435 \u043c\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043a\u0430\u043a \u044d\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u0442\u0441\u044f. <\/p>\n<p>  \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u0440\u043e\u0442\u0435\u0441\u0442\u0438\u0440\u0443\u0435\u043c \u043d\u0430\u0448\u0443 \u0441\u0441\u044b\u043b\u043a\u0443:<\/p>\n<pre><code class=\"javascript\">function test(cppRef)     local handle = createHandle(cppRef)     testHandle(handle) end  function testHandle(handle)     print(\"Hello, my name is \" .. handle:getName())     handle:setName(\"Mark\")     print(\"My name is \" .. handle:getName() .. \" now!\") end<\/code><\/pre>\n<p>  \u0412\u044b\u0432\u043e\u0434:<\/p>\n<p>  \u0420\u0430\u0431\u043e\u0442\u0430\u0435\u0442! \u0427\u0442\u043e \u0436\u0435 \u043d\u0430\u043c \u0434\u0435\u043b\u0430\u0442\u044c, \u043a\u043e\u0433\u0434\u0430 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c \u0443\u0434\u0430\u043b\u044f\u0435\u0442\u0441\u044f? \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u044e:<\/p>\n<pre><code class=\"javascript\">function onEntityRemoved(id)     local handle = Handles[id];     handle.cppRef = nil     handle.isValid = false     Handles[id] = nil end<\/code><\/pre>\n<p>  \u0415\u0451 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0432\u044b\u0437\u0432\u0430\u0442\u044c \u0434\u043e \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u0443\u044e\u0449\u0430\u044f \u043d\u0430\u0441 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c \u0431\u0443\u0434\u0435\u0442 \u0443\u0434\u0430\u043b\u0435\u043d\u0430. \u042d\u0442\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043c\u0435\u0441\u0442\u0438\u0442\u044c \u0432 \u0434\u0435\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 Entity \u0438\u043b\u0438 \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u044e removeEntity \u043e\u0442 EntityManager. \u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435: \u0441\u0430\u043c \u043e\u043f\u0438\u0441\u0430\u0442\u0435\u043b\u044c \u043e\u0442 \u044d\u0442\u043e\u0433\u043e \u043d\u0435 \u0443\u0434\u0430\u043b\u044f\u0435\u0442\u0441\u044f: \u043a\u0442\u043e-\u043d\u0438\u0431\u0443\u0434\u044c \u043f\u043e-\u043f\u0440\u0435\u0436\u043d\u0435\u043c\u0443 \u043c\u043e\u0436\u0435\u0442 \u043d\u0430 \u043d\u0435\u0433\u043e \u0441\u0441\u044b\u043b\u0430\u0442\u044c\u0441\u044f. \u041d\u043e \u0432\u0441\u0435 \u0440\u0430\u0432\u043d\u043e \u043f\u043e\u043b\u0435\u0437\u043d\u043e \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0442\u044c \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b Handles \u0432 nil, \u0442\u0430\u043a \u043a\u0430\u043a \u0435\u0441\u043b\u0438 \u043a\u0442\u043e-\u043d\u0438\u0431\u0443\u0434\u044c \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u0442 \u043f\u043e\u0434\u043e\u0431\u0440\u0430\u0442\u044c \u044d\u0442\u043e\u0442 \u043e\u043f\u0438\u0441\u0430\u0442\u0435\u043b\u044c \u043f\u043e\u0437\u0436\u0435, \u0432 \u043e\u0442\u0432\u0435\u0442 \u043e\u043d \u043f\u043e\u043b\u0443\u0447\u0438\u0442 nil. \u0415\u0449\u0451 \u0432\u0430\u0436\u043d\u0435\u0435 \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u0447\u0442\u043e isValid \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0432 false. \u041f\u043e\u044d\u0442\u043e\u043c\u0443, \u043a\u043e\u0433\u0434\u0430 \u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0440\u0430\u0437 \u043a\u0442\u043e-\u043d\u0438\u0431\u0443\u0434\u044c \u043f\u043e\u043f\u044b\u0442\u0430\u0435\u0442\u0441\u044f \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043e\u043f\u0438\u0441\u0430\u0442\u0435\u043b\u0435\u043c, \u0432\u043e\u0437\u043d\u0438\u043a\u043d\u0435\u0442 \u043e\u0448\u0438\u0431\u043a\u0430. <\/p>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u0447\u0442\u043e \u043f\u0440\u043e\u0438\u0437\u043e\u0439\u0434\u0451\u0442, \u0435\u0441\u043b\u0438 \u043f\u043e\u043f\u044b\u0442\u0430\u0442\u044c\u0441\u044f \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043d\u0435\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u0441\u0441\u044b\u043b\u043a\u043e\u0439. \u0422\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u0434\u0430\u0436\u0435 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0443 \u043e\u0448\u0438\u0431\u043e\u043a \u043c\u043e\u0436\u0435\u043c \u043f\u0440\u043e\u0432\u043e\u0434\u0438\u0442\u044c \u043d\u0430 \u0441\u0442\u043e\u0440\u043e\u043d\u0435 Lua!<\/p>\n<pre><code class=\"javascript\">function testBadReference()     local handle = Handles[0] -- \u044d\u0442\u043e\u0442 \u043e\u043f\u0438\u0441\u0430\u0442\u0435\u043b\u044c \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0438 \u043f\u0440\u043e\u0431\u043b\u0435\u043c \u043d\u0435 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442     handle.isValid = false -- \u043d\u043e \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0438\u043c, \u0447\u0442\u043e \u044d\u0442\u043e\u0442 \u043e\u0431\u044a\u0435\u043a\u0442 \u0431\u044b\u043b \u0443\u0434\u0430\u043b\u0435\u043d!     local _, err = pcall(testHandle, handle)     if err then         print(err)     end end<\/code><\/pre>\n<p>  \u0412\u044b\u0437\u043e\u0432 \u044d\u0442\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0438\u0437 C++ \u043d\u0435 \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442 \u043a \u043e\u0442\u043a\u0430\u0437\u0443 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u043e\u0438\u0437\u043e\u0448\u0451\u043b \u0431\u044b, \u0435\u0441\u043b\u0438 \u0431\u044b \u043c\u044b \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438\u0441\u044c \u0443\u0441\u0442\u0430\u0440\u0435\u0432\u0448\u0435\u0439 \u0441\u0441\u044b\u043b\u043a\u043e\u0439. \u0412\u043c\u0435\u0441\u0442\u043e \u044d\u0442\u043e\u0433\u043e \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043f\u043e\u043b\u0435\u0437\u043d\u043e\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u043e\u0431 \u043e\u0448\u0438\u0431\u043a\u0435 \u0438 \u0441\u0442\u0435\u043a \u0432\u044b\u0437\u043e\u0432\u043e\u0432:<\/p>\n<pre><code class=\"javascript\">stack traceback:     script.lua:23: in function 'getName'     script.lua:57: in function &lt;script.lua:56>     [C]: in function 'pcall'     script.lua:65: in function &lt;script.lua:62> script.lua:57: Error: handle is not valid!<\/code><\/pre>\n<p>  \u0427\u0442\u043e \u043d\u0430\u0441\u0447\u0451\u0442 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438? \u041c\u043e\u0438 \u0442\u0435\u0441\u0442\u044b \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0442, \u0447\u0442\u043e \u043d\u0430 \u0432\u044b\u0437\u043e\u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430 \u0421++ \u0443\u0445\u043e\u0434\u0438\u0442 \u043e\u043a\u043e\u043b\u043e <b>600 \u043d\u0430\u043d\u043e\u0441\u0435\u043a\u0443\u043d\u0434<\/b>. \u041d\u0435\u0442 \u0442\u0430\u043a \u043f\u043b\u043e\u0445\u043e, \u043d\u043e \u043a\u043e\u0433\u043e-\u0442\u043e \u0432\u0441\u0451 \u0440\u0430\u0432\u043d\u043e \u043c\u043e\u0436\u0435\u0442 \u043d\u0435 \u0443\u0441\u0442\u0440\u043e\u0438\u0442\u044c. \u0412 \u0442\u0430\u043a\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043b\u0435\u0433\u043a\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043e\u0431\u044b\u0447\u043d\u0443\u044e \u0441\u0441\u044b\u043b\u043a\u0443, \u0430 \u0437\u0430\u0442\u0435\u043c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0435\u044e \u0431\u0435\u0437 \u043a\u0430\u043a\u0438\u0445-\u043b\u0438\u0431\u043e \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0438\u0437\u0434\u0435\u0440\u0436\u0435\u043a \u043d\u0430 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0443 \u043e\u0448\u0438\u0431\u043e\u043a: <\/p>\n<pre><code class=\"javascript\">local rawRef = handle.cppRef print(\"Raw reference used. Name: \" .. rawRef:getName())<\/code><\/pre>\n<p>  \u0422\u0430\u043a\u0436\u0435 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0443\u0441\u043a\u043e\u0440\u0438\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044e __index. \u042f \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0438\u043b, \u0447\u0442\u043e \u0441\u0430\u043c\u0430\u044f \u0441\u0435\u0440\u044c\u0451\u0437\u043d\u0430\u044f \u0438\u0437\u0434\u0435\u0440\u0436\u043a\u0430 \u2013 \u0432\u0441\u044f\u043a\u0438\u0439 \u0440\u0430\u0437 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0437\u0430\u043c\u044b\u043a\u0430\u043d\u0438\u0435\u2026 \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u0440\u043e\u0441\u0442\u043e \u0437\u0430\u043f\u043e\u043c\u043d\u0438\u043c \u043d\u0430\u0448\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0438-\u043e\u0431\u0451\u0440\u0442\u043a\u0438! \u041f\u0435\u0440\u0432\u044b\u043c \u0434\u0435\u043b\u043e\u043c \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0442\u0430\u0431\u043b\u0438\u0446\u0443, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0431\u0443\u0434\u0443\u0442 \u0445\u0440\u0430\u043d\u0438\u0442\u044c\u0441\u044f \u043d\u0430\u0448\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0438-\u043e\u0431\u0451\u0440\u0442\u043a\u0438:<\/p>\n<pre><code class=\"javascript\">local memoizedFuncs = {}<\/code><\/pre>\n<p>  A \u0437\u0430\u0442\u0435\u043c \u0438\u0437\u043c\u0435\u043d\u0438\u043c \u043d\u0430\u0448 \u043c\u0435\u0442\u043e\u0434 __index \u0432\u043e\u0442 \u0442\u0430\u043a:<\/p>\n<pre><code class=\"javascript\">mt.__index = function(handle, key)     if not handle.isValid then         print(debug.traceback())         error(\"Error: handle is not valid!\", 2)     end      local f = memoizedFuncs[key]     if not f then         f = function(handle, ...) return Entity[key](handle.cppRef, ...) end         memoizedFuncs[key] = f     end     return f end<\/code><\/pre>\n<p>  \u0417\u0430\u043c\u044b\u043a\u0430\u043d\u0438\u0435 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c\u0441\u044f \u0432\u0441\u0435\u0433\u043e \u043e\u0434\u043d\u0430\u0436\u0434\u044b, \u0430 \u0437\u0430\u0442\u0435\u043c \u2013 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043f\u043e\u0432\u0442\u043e\u0440\u043d\u043e. \u0412 \u0442\u0430\u043a\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0432\u0441\u044f \u0440\u0430\u0431\u043e\u0442\u0430 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0443\u0441\u043a\u043e\u0440\u0438\u0442\u0441\u044f! \u0418\u0437\u0434\u0435\u0440\u0436\u043a\u0438 \u0441\u043e\u0441\u0442\u0430\u0432\u044f\u0442 \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u043f\u043e <b>200 \u043d\u0430\u043d\u043e\u0441\u0435\u043a\u0443\u043d\u0434<\/b> \u043d\u0430 \u0432\u044b\u0437\u043e\u0432.<\/p>\n<p>  \u0427\u0442\u043e \u0435\u0449\u0451? \u041f\u0440\u0438 \u0432\u044b\u0437\u043e\u0432\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0447\u0435\u0440\u0435\u0437 __index \u0442\u0430\u043a\u0436\u0435 \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u044e\u0442 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0438\u0437\u0434\u0435\u0440\u0436\u043a\u0438. \u041f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0438\u043c, \u0447\u0442\u043e \u043c\u044b \u043e\u0447\u0435\u043d\u044c \u0447\u0430\u0441\u0442\u043e \u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u0441\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0435\u0439 getName \u0438 \u0445\u043e\u0442\u0438\u043c \u0432\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0435\u0451 \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0443-\u043e\u043f\u0438\u0441\u0430\u0442\u0435\u043b\u044c, \u0447\u0442\u043e\u0431\u044b \u044d\u0442\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0432\u044b\u0437\u044b\u0432\u0430\u043b\u0430\u0441\u044c \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u044d\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u0435\u043c! <\/p>\n<pre><code class=\"javascript\">function createHandle(cppRef)     local handle = {         cppRef = cppRef,         isValid = true     }     handle.getName = function(handle, ...)         return Entity.getName(handle.cppRef, ...)     end      setmetatable(handle, mt)     Handles[cppRef:getId()] = handle     return handle end<\/code><\/pre>\n<p>  \u0421\u0435\u043a\u0443\u043d\u0434\u043e\u0447\u043a\u0443\u2026 \u0430 \u0447\u0442\u043e \u043f\u0440\u043e\u0438\u0437\u043e\u0439\u0434\u0435\u0442, \u0435\u0441\u043b\u0438 \u0432\u044b\u0437\u0432\u0430\u0442\u044c \u0447\u0435\u0440\u0435\u0437 getName \u043d\u0435\u0438\u0441\u043f\u0440\u0430\u0432\u043d\u044b\u0439 \u043e\u043f\u0438\u0441\u0430\u0442\u0435\u043b\u044c? \u0412\u0435\u0434\u044c \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u043e\u0448\u0438\u0431\u043e\u043a \u043d\u0435\u0442! \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u044d\u0442\u043e \u0438\u0441\u043f\u0440\u0430\u0432\u0438\u043c:<\/p>\n<p>  f<\/p>\n<pre><code class=\"javascript\">unction getWrappedSafeFunction(f)     return function(handle, ...)             if not handle.isValid then                 print(debug.traceback())                 error(\"Error: handle is not valid!\", 2)             end             return f(handle.cppRef, ...)         end end<\/code><\/pre>\n<p>  \u0430 \u0437\u0430\u0442\u0435\u043c \u0432 createHandle \u043d\u0430\u043f\u0438\u0448\u0435\u043c:<\/p>\n<pre><code class=\"javascript\">handle.getName = getWrappedSafeFunction(Entity.getName)<\/code><\/pre>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u0438\u0437\u0434\u0435\u0440\u0436\u043a\u0438 \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442 \u0432\u0441\u0435\u0433\u043e <b>70 \u043d\u0430\u043d\u043e\u0441\u0435\u043a\u0443\u043d\u0434<\/b>. \u0412\u0441\u0435 \u043e\u043d\u0438 \u0441\u0432\u044f\u0437\u0430\u043d\u044b \u0441 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u043c \u0432\u044b\u0437\u043e\u0432\u043e\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u043e\u0439 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0438 \u0438\u0437\u0432\u043b\u0435\u0447\u0435\u043d\u0438\u0435\u043c \u043e\u0431\u044b\u0447\u043d\u043e\u0439 \u0441\u0441\u044b\u043b\u043a\u0438 \u0438\u0437 \u0442\u0430\u0431\u043b\u0438\u0446\u044b-\u043e\u043f\u0438\u0441\u0430\u0442\u0435\u043b\u044f, \u043d\u043e \u044f \u0434\u0443\u043c\u0430\u044e, \u0447\u0442\u043e \u044d\u0442\u0430 \u043f\u043b\u0430\u0442\u0430 \u043e\u0447\u0435\u043d\u044c \u043d\u0435\u0432\u0435\u043b\u0438\u043a\u0430 \u0441 \u0443\u0447\u0451\u0442\u043e\u043c \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u043c\u044b \u0432\u044b\u0438\u0433\u0440\u0430\u043b\u0438.<\/div>\n<\/div>\n<\/div>\n<p> <!----> <!----><\/div>\n<p> <!----> <!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/company\/piter\/blog\/707672\/\"> https:\/\/habr.com\/ru\/company\/piter\/blog\/707672\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-1\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\"><a href=\"https:\/\/habr.com\/ru\/company\/piter\/blog\/707672\/\"><\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/9t\/c_\/ew\/9tc_ewnjnrmzxybaxnxuhoi0qac.png\" alt=\"image\" data-src=\"https:\/\/habrastorage.org\/webt\/9t\/c_\/ew\/9tc_ewnjnrmzxybaxnxuhoi0qac.png\"\/><\/div>\n<p><\/a><br \/>  \u041e\u0447\u0435\u043d\u044c \u0447\u0430\u0441\u0442\u043e \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0441 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u043e\u0439 \u0441\u0441\u044b\u043b\u043e\u043a \u043d\u0430 \u0438\u0433\u0440\u043e\u0432\u044b\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u044b (\u043d\u0430\u0437\u043e\u0432\u0443 \u044d\u0442\u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044f\u043c\u0438). \u0418\u043d\u043e\u0433\u0434\u0430 \u0440\u0435\u0447\u044c \u0438\u0434\u0451\u0442 \u043e\u0431 \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044f\u0445 \u00ab\u043f\u0440\u0435\u0434\u043e\u043a-\u043f\u043e\u0442\u043e\u043c\u043e\u043a\u00bb \u043c\u0435\u0436\u0434\u0443 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044f\u043c\u0438. \u0411\u044b\u0432\u0430\u0435\u0442, \u0447\u0442\u043e \u043f\u043e\u043b\u0435\u0437\u043d\u043e \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 \u043e\u0431\u044a\u0435\u043a\u0442 \u043f\u0440\u0438 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u043e \u0441\u043e\u0431\u044b\u0442\u0438\u044f\u0445, \u0432 \u043a\u043b\u0430\u0441\u0441\u0435 \u043f\u043b\u0430\u043d\u0438\u0440\u043e\u0432\u0449\u0438\u043a\u0430 \u0437\u0430\u0434\u0430\u0447 \u0438 \u0442.\u0434.<\/p>\n<p>  \u0418\u043d\u043e\u0433\u0434\u0430 \u043c\u043e\u0436\u043d\u043e \u043e\u0431\u043e\u0439\u0442\u0438\u0441\u044c \u043f\u0440\u043e\u0441\u0442\u044b\u043c \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0435\u043c, \u0441\u0441\u044b\u043b\u043a\u043e\u0439 \u0438\u043b\u0438 std::reference_wrapper. \u041d\u043e \u043f\u0440\u0438 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 \u043e\u0431\u044b\u0447\u043d\u044b\u043c\u0438 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044f\u043c\u0438 \u0438 \u0441\u0441\u044b\u043b\u043a\u0430\u043c\u0438 \u0435\u0441\u0442\u044c \u0442\u0430\u043a\u0430\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430: \u0435\u0441\u043b\u0438 \u0432\u044b \u0438\u043c\u0438 \u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0435\u0441\u044c, \u0442\u043e \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c \u0443\u0432\u0435\u0440\u0435\u043d\u044b, \u0447\u0442\u043e \u0442\u0430 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0430 \u0441\u0441\u044b\u043b\u043a\u0430, \u043e\u0441\u0442\u0430\u0451\u0442\u0441\u044f \u0436\u0438\u0432\u0430 \u0438 \u043d\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u0449\u0430\u0435\u0442\u0441\u044f \u0432 \u043f\u0430\u043c\u044f\u0442\u0438 \u0431\u0435\u0437 \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u044f \u0442\u0435\u0445 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432, \u0447\u0442\u043e \u0434\u0435\u0440\u0436\u0430\u0442 \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 \u043d\u0435\u0451. \u041f\u043e\u0436\u0430\u043b\u0443\u0439, \u0432 \u0445\u043e\u0440\u043e\u0448\u043e \u0441\u043f\u0440\u043e\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0439 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0435 \u044d\u0442\u043e \u0434\u043e\u0441\u0442\u0438\u0436\u0438\u043c\u043e.<\/p>\n<p>  \u041e\u0434\u043d\u0430\u043a\u043e \u0443\u0441\u0442\u0430\u0440\u0435\u0432\u0448\u0438\u0435 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0438\/\u0441\u0441\u044b\u043b\u043a\u0438 \u043f\u0440\u043e\u0432\u043e\u0446\u0438\u0440\u0443\u044e\u0442 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0433\u043d\u0443\u0441\u043d\u0435\u0439\u0448\u0438\u0435 \u0431\u0430\u0433\u0438. \u042d\u0442\u0438 \u0431\u0430\u0433\u0438 \u0441\u043b\u043e\u0436\u043d\u043e \u043e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u0442\u044c, \u043d\u0435 \u0442\u0430\u043a \u043b\u0435\u0433\u043a\u043e \u0432\u044b\u044f\u0432\u0438\u0442\u044c, \u0438 \u043e\u043d\u0438 \u043c\u043e\u0433\u0443\u0442 \u043e\u0431\u0440\u0443\u0448\u0438\u0442\u044c \u0432\u0430\u0448\u0443 \u0438\u0433\u0440\u0443. \u041d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 \u043c\u043e\u0433\u0443\u0442 \u0437\u0430\u043d\u0438\u043c\u0430\u0442\u044c \u0432 \u043f\u0430\u043c\u044f\u0442\u0438 \u0438\u043d\u044b\u0435 \u0430\u0434\u0440\u0435\u0441\u0430, \u043d\u0435\u0436\u0435\u043b\u0438 \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u043b\u043e\u0441\u044c (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u043e\u0441\u043b\u0435 \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u0432\u044b \u043f\u0435\u0440\u0435\u0437\u0430\u0433\u0440\u0443\u0437\u0438\u0442\u0435 \u0443\u0440\u043e\u0432\u0435\u043d\u044c \u0438\u043b\u0438 \u0440\u0435\u0448\u0438\u0442\u0435 \u0437\u0430\u043d\u043e\u0432\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0441 \u043d\u0443\u043b\u044f \u0432\u0441\u0435\u0445 \u0432\u0440\u0430\u0433\u043e\u0432). \u041a\u043e\u043d\u0435\u0447\u043d\u043e, \u043c\u043e\u0436\u043d\u043e \u0438 \u0432\u0440\u0443\u0447\u043d\u0443\u044e \u043e\u0431\u043d\u043e\u0432\u0438\u0442\u044c \u0432\u0441\u0435 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0438 \u043d\u0430 \u0442\u0435 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u044b \u0440\u0430\u043d\u0435\u0435 \u0441\u0441\u044b\u043b\u0430\u043b\u0438\u0441\u044c. \u041d\u043e, \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u043e, \u044d\u0442\u043e \u043b\u0443\u0447\u0448\u0435 \u0434\u0435\u043b\u0430\u0442\u044c \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438, \u0447\u0442\u043e\u0431\u044b \u043d\u0435 \u043e\u0441\u0442\u0430\u0432\u0430\u043b\u043e\u0441\u044c \u043d\u0438\u043a\u0430\u043a\u043e\u0439 \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u0438 \u0437\u0430\u0431\u044b\u0442\u044c \u043a\u0430\u043a\u0438\u0435-\u043b\u0438\u0431\u043e \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u0442\u043e\u043c \u0443\u0441\u0442\u0430\u0440\u0435\u044e\u0442.<\/p>\n<p>  \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0440\u0435\u0448\u0438\u0442\u044c \u0432\u0441\u0435 \u044d\u0442\u0438 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b. \u041d\u043e\u0432\u0435\u0439\u0448\u0435\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 (\u0441\u0432\u044f\u0437\u0430\u043d\u043d\u043e\u0435 \u0441 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435\u043c \u0441\u0441\u044b\u043b\u043e\u043a \u0432 Lua) \u0431\u044b\u043b\u043e \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0435\u043d\u043e \u043c\u043d\u043e\u044e \u043d\u0435 \u0442\u0430\u043a \u0434\u0430\u0432\u043d\u043e \u0438 \u043f\u043e\u0431\u0443\u0434\u0438\u043b\u043e \u043c\u0435\u043d\u044f \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u044d\u0442\u0443 \u0441\u0442\u0430\u0442\u044c\u044e, \u043d\u043e \u044f \u0445\u043e\u0447\u0443 \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c, \u0447\u0442\u043e \u0435\u0441\u0442\u044c \u0438 \u0434\u0440\u0443\u0433\u0438\u0435 \u0441\u043f\u043e\u0441\u043e\u0431\u044b \u0440\u0435\u0448\u0438\u0442\u044c \u044d\u0442\u0443 \u0437\u0430\u0434\u0430\u0447\u0443. \u041f\u0440\u0438\u0441\u0442\u0443\u043f\u0438\u043c! <\/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-343167","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/343167","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=343167"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/343167\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=343167"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=343167"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=343167"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}