{"id":3333,"date":"2024-09-23T13:06:38","date_gmt":"2024-09-23T04:06:38","guid":{"rendered":"https:\/\/roblog.jp\/studio\/?p=3333"},"modified":"2024-09-23T13:35:02","modified_gmt":"2024-09-23T04:35:02","slug":"lua%e3%81%a7%e3%83%a1%e3%82%bf%e3%83%86%e3%83%bc%e3%83%96%e3%83%ab%e3%82%92%e6%89%b1%e3%81%a3%e3%81%a6%e3%81%bf%e3%82%88%e3%81%86%ef%bc%81%e3%82%b9%e3%82%af%e3%83%aa%e3%83%97%e3%83%88%e8%a7%a3","status":"publish","type":"post","link":"https:\/\/roblog.jp\/studio\/lua%e3%81%a7%e3%83%a1%e3%82%bf%e3%83%86%e3%83%bc%e3%83%96%e3%83%ab%e3%82%92%e6%89%b1%e3%81%a3%e3%81%a6%e3%81%bf%e3%82%88%e3%81%86%ef%bc%81%e3%82%b9%e3%82%af%e3%83%aa%e3%83%97%e3%83%88%e8%a7%a3\/","title":{"rendered":"Lua\u3067\u30e1\u30bf\u30c6\u30fc\u30d6\u30eb\u3092\u6271\u3063\u3066\u307f\u3088\u3046\uff01\u30b9\u30af\u30ea\u30d7\u30c8\u89e3\u8aac Roblox Studio"},"content":{"rendered":"\n<p>\u3053\u3093\u306b\u3061\u306f\uff01<\/p>\n\n\n\n<p>\u3042\u306a\u305f\u306f\u3001\u300c\u30e1\u30bf\u30c6\u30fc\u30d6\u30eb\u300d\u3068\u3044\u3046\u8a00\u8449\u3092\u805e\u3044\u305f\u3053\u3068\u306f\u3042\u308a\u307e\u3059\u304b\uff1f<\/p>\n\n\n\n<p>\u300c\u30e1\u30bf\u30c6\u30fc\u30d6\u30eb\u3001\u805e\u3044\u305f\u3053\u3068\u306f\u3042\u308b\u3057\u3001\u4fbf\u5229\u3060\u3051\u3069\u3001\u306a\u3093\u3060\u304b\u96e3\u3057\u305d\u3046\u2026\u3002\u300d<\/p>\n\n\n\n<p>\u300c\u6d77\u5916\u306e\u89e3\u8aac\u52d5\u753b\u3092\u898b\u305f\u3051\u3069\u3001\u96e3\u3057\u304f\u3066\u632b\u6298\u3057\u305f\u2026\u3002\u300d<\/p>\n\n\n\n<p>\u305d\u3093\u306a\u65b9\u304c\u3053\u306e\u8a18\u4e8b\u306b\u305f\u3069\u308a\u7740\u3044\u305f\u306e\u3067\u306f\u306a\u3044\u3067\u3057\u3087\u3046\u304b\u3002<\/p>\n\n\n\n<p>\u3053\u306e\u8a18\u4e8b\u3067\u306f\u3001\u30e1\u30bf\u30c6\u30fc\u30d6\u30eb\u306e\u57fa\u672c\u7684\u306a\u4f7f\u3044\u65b9\u3092\u3001\u305f\u304f\u3055\u3093\u306e\u30b3\u30fc\u30c9\u30b5\u30f3\u30d7\u30eb\u3068\u5171\u306b\u89e3\u8aac\u3057\u307e\u3059\uff01\u305c\u3072\u5f79\u7acb\u3066\u3066\u304f\u3060\u3055\u3044\u306d\u3002<\/p>\n\n\n\n<div class=\"wp-block-sgb-block-simple sgb-box-simple sgb-box-simple--title-normal sgb-box-simple--with-border\"><div style=\"background-color:var(--wp--preset--color--sango-main);color:#FFF\" class=\"sgb-box-simple__title\">\u3053\u306e\u8a18\u4e8b\u306e\u5bfe\u8c61\u8005<\/div><div class=\"sgb-box-simple__body\" style=\"border-color:var(--wp--preset--color--sango-main);background-color:#FFF\"><div style=\"--sgb-list-icon-color: var(--sgb-main-color);--sgb-list-border-color: var(--sgb-main-color);\">\n<ul class=\"wp-block-list is-style-sango-list-check\">\n<li>\u4e2d\u5b66\u751f\u4ee5\u4e0a\u3082\u3057\u304f\u306f\u4e2d\u5b66\u751f\u30ec\u30d9\u30eb\u306e\u56fd\u8a9e\u529b\u304c\u3042\u308b<\/li>\n\n\n\n<li>\u30e1\u30bf\u30c6\u30fc\u30d6\u30eb\u3092\u9664\u304fLua\u306e\u57fa\u672c\u306b\u3064\u3044\u3066\u3042\u308b\u7a0b\u5ea6\u7406\u89e3\u3057\u3066\u3044\u308b<\/li>\n\n\n\n<li>\u7279\u306b\u3001\u300c\u30e1\u30bf\u30c6\u30fc\u30d6\u30eb\u3063\u3066\u306a\u306b\uff1f\u300d\u3063\u3066\u4eba\u306b\u30aa\u30b9\u30b9\u30e1\uff01<\/li>\n<\/ul>\n<\/div><\/div><\/div>\n\n\n\n<p>\u305d\u308c\u3067\u306f\u3001\u59cb\u3081\u3066\u3044\u304d\u307e\u3057\u3087\u3046\uff01<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"i-0\">\u30e1\u30bf\u30c6\u30fc\u30d6\u30eb\u3068\u306f\uff1f<\/h2>\n\n\n\n<p>\u305d\u3082\u305d\u3082\u3001\u30e1\u30bf\u30c6\u30fc\u30d6\u30eb\u306e\u300c\u30e1\u30bf\u300d\u3068\u306f\u4f55\u306a\u306e\u3067\u3057\u3087\u3046\u304b\uff1f<\/p>\n\n\n\n<p>\u30e1\u30bf\u306b\u306f\u300c\u9ad8\u3044\u6b21\u5143\u306e\u300d\u3084\u300c\u8d85\u8d8a\u3057\u305f\u300d\u3068\u3044\u3046\u610f\u5473\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u30e1\u30bf\u30c6\u30fc\u30d6\u30eb\u3082\u3001\u8d85\u7c21\u5358\u306b\u8a00\u3048\u3070\u3001\u901a\u5e38\u306e\u30c6\u30fc\u30d6\u30eb\u306e\u4e0a\u4f4d\u4e92\u63db\u3002\u30e1\u30bf\u30c6\u30fc\u30d6\u30eb\u3092\u4f7f\u3046\u3053\u3068\u3067\u3001\u30c6\u30fc\u30d6\u30eb\u306e\u52d5\u4f5c\u306e\u30ab\u30b9\u30bf\u30de\u30a4\u30ba\u3092\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u4f8b\u3048\u3070\u2026\u3002\u30c6\u30fc\u30d6\u30eb\u3063\u3066<strong>\u3075\u3064\u3046\u306f<\/strong>\u8db3\u3057\u7b97\u3067\u304d\u307e\u305b\u3093\u3088\u306d\u3002<\/p>\n\n\n\n<p>\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u30b3\u30fc\u30c9\u304c\u3042\u308b\u3068\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"lua\" class=\"language-lua\">local table1 = {1, 2, 3}\nprint(table1 + 1)<\/code><\/pre>\n\n\n\n<p>\u3053\u306e\u30b3\u30fc\u30c9\u306f\u3001\u6b21\u306e\u3088\u3046\u306a\u30a8\u30e9\u30fc\u304c\u3067\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"lua\" class=\"language-lua\">  22:48:29.093  ServerScriptService.Script:2: attempt to perform arithmetic (add) on table and number  -  \u30b5\u30fc\u30d0\u30fc - Script:2\n  22:48:29.093  Stack Begin  -  Studio\n  22:48:29.093  Script 'ServerScriptService.Script', Line 2  -  Studio - Script:2\n  22:48:29.093  Stack End  <\/code><\/pre>\n\n\n\n<p>\u300c\u30c6\u30fc\u30d6\u30eb\u3068\u6570\u5024\u3067\u7b97\u8853 (\u52a0\u6cd5)\u3092\u5b9f\u884c\u3057\u3088\u3046\u3068\u3057\u305f\u300d\u3068\u3044\u3046\u30a8\u30e9\u30fc\u304c\u3067\u307e\u3057\u305f\u3002<\/p>\n\n\n\n<p>\u8981\u3059\u308b\u306b\u3001<strong>\u300c\u30c6\u30fc\u30d6\u30eb\u3068\u6570\u5b57\u3067\u8db3\u3057\u7b97\u3067\u304d\u306a\u3044\u3088\uff01\u300d<\/strong>\u3063\u3066\u30a8\u30e9\u30fc\u3067\u3059\u306d\u3002<\/p>\n\n\n\n<p>\u666e\u901a\u306e\u30c6\u30fc\u30d6\u30eb\u3067\u306f\u3053\u3046\u306a\u308a\u307e\u3059\u3002\u3057\u304b\u3057\u3001<strong>\u30e1\u30bf\u30c6\u30fc\u30d6\u30eb\u3092\u6d3b\u7528\u3059\u308c\u3070\u3001\u30c6\u30fc\u30d6\u30eb\u3068\u6570\u5024\u3001\u306f\u305f\u307e\u305f\u30c6\u30fc\u30d6\u30eb\u3068\u30c6\u30fc\u30d6\u30eb\u3067\u8db3\u3057\u7b97\u3057\u305f\u308a\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u308b\u306e\u3067\u3059\u3002<\/strong><\/p>\n\n\n\n<p>\u30e1\u30bf\u30c6\u30fc\u30d6\u30eb\u3092\u4f7f\u3046\u3053\u3068\u3067\u3001\u8db3\u3057\u7b97\u306e\u6f14\u7b97\u5b50(+)\u3060\u3051\u3067\u306a\u304f\u3001\u4ed6\u306e\u7b97\u8853\u6f14\u7b97\u5b50(-, *, \/\u306a\u3069)\u3084\u3001\u6bd4\u8f03\u6f14\u7b97\u5b50(==, &lt;=\u306a\u3069)\u306e\u6f14\u7b97\u5b50\u306e\u52d5\u4f5c\u3092\u8a2d\u5b9a\u3059\u308b\u3053\u3068\u3082\u53ef\u80fd\u3067\u3059\u3002<\/p>\n\n\n\n<p>\u30c6\u30fc\u30d6\u30eb\u3068\u6570\u5024\u3001\u30c6\u30fc\u30d6\u30eb\u3068\u30c6\u30fc\u30d6\u30eb\u3092\u6bd4\u8f03\u6f14\u7b97\u5b50\u3067\u6bd4\u8f03\u3057\u3066\u3001true\u3084false\u3092\u8fd4\u3059\u3001\u3068\u3044\u3063\u305f\u3053\u3068\u3082\u3067\u304d\u308b\u3093\u3067\u3059\uff01<\/p>\n\n\n\n<p>\u3053\u308c\u3067\u3001\u30e1\u30bf\u30c6\u30fc\u30d6\u30eb\u3067\u5b9f\u73fe\u53ef\u80fd\u306a\u3053\u3068\u306e5\u5272\u3050\u3089\u3044\u3092\u8aac\u660e\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3057\u305f\uff01\u307e\u3060\u3067\u304d\u308b\u3053\u3068\u306f\u3042\u308a\u307e\u3059\u304c\u3001\u5f8c\u307b\u3069\u7d39\u4ecb\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u305d\u308c\u3067\u306f\u65e9\u901f\u3001\u30e1\u30bf\u30c6\u30fc\u30d6\u30eb\u3092\u6271\u3063\u3066\u307f\u307e\u3057\u3087\u3046\uff01<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"i-1\">\u30e1\u30bf\u30c6\u30fc\u30d6\u30eb\u306e\u57fa\u672c\u3092\u5b66\u307c\u3046<\/h2>\n\n\n\n<p>\u3053\u306e\u7ae0\u3067\u306f\u3001\u30e1\u30bf\u30c6\u30fc\u30d6\u30eb\u306e\u300c\u57fa\u672c\u300d\u306e\u7fd2\u5f97\u3092\u76ee\u6307\u3057\u3066\u3044\u304d\u307e\u3059\uff01<\/p>\n\n\n\n<p>\u300c\u30e1\u30bf\u30c6\u30fc\u30d6\u30eb\u3092\u4f7f\u3048\u3070\u3001\u30c6\u30fc\u30d6\u30eb\u3067\u7b97\u8853\u6f14\u7b97\u5b50\u304c\u4f7f\u3048\u308b\uff01\uff01\u300d\u3068\u3044\u3063\u3066\u3082\u3001\u305d\u3046\u7c21\u5358\u3067\u306f\u3042\u308a\u307e\u305b\u3093\u2026\u3002<\/p>\n\n\n\n<p>\u305d\u3082\u305d\u3082\u3001\u30c6\u30fc\u30d6\u30eb\u3068\u6570\u5024\u304c\u8db3\u3057\u7b97\u3067\u304d\u306a\u3044\u306e\u306f\u3001\u30c6\u30fc\u30d6\u30eb\u3068\u6570\u5024\u304c\u8db3\u3057\u7b97\u3059\u308b\u305f\u3081\u306e\u4ed5\u7d44\u307f\u304c\u5099\u308f\u3063\u3066\u3044\u306a\u3044\u304b\u3089\u306a\u306e\u3067\u3059\u3002<\/p>\n\n\n\n<p>\u30e1\u30bf\u30c6\u30fc\u30d6\u30eb\u3092\u4f7f\u3063\u3066\u3001\u30c6\u30fc\u30d6\u30eb\u3092\u8db3\u3057\u7b97\u3067\u304d\u308b\u3088\u3046\u306b\u3059\u308b\u5834\u5408\u3001<strong>\u300c\u3069\u306e\u3088\u3046\u306b\u30c6\u30fc\u30d6\u30eb\u3068\u6f14\u7b97\u5b50\u306e\u5f8c\u308d\u306e\u5024\u3092\u4f7f\u3063\u3066\u3001\u8a08\u7b97\u3059\u308b\u304b\u300d<\/strong>\u3092\u5b9a\u7fa9\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u305d\u308c\u3092\u8e0f\u307e\u3048\u3066\u3001\u30e1\u30bf\u30c6\u30fc\u30d6\u30eb\u3092\u6271\u3063\u3066\u3044\u304d\u307e\u3057\u3087\u3046\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-2\">\u30b5\u30f3\u30d7\u30eb\u30b3\u30fc\u30c9\u3092\u5b9f\u884c\u3057\u3066\u307f\u308b<\/h3>\n\n\n\n<p>\u3067\u306f\u3001\u3053\u3053\u3067\u306f\u3001\u300c\u6570\u5024\u304c\u6570\u500b\u5165\u3063\u305f\u30c6\u30fc\u30d6\u30eb\u300d\u306b\u30e1\u30bf\u30c6\u30fc\u30d6\u30eb\u3092\u8a2d\u5b9a\u3057\u3001\u6570\u5024\u3092\u8db3\u3059\u3068\u3001\u30c6\u30fc\u30d6\u30eb\u5185\u306e\u5168\u8981\u7d20\u304c\u305d\u306e\u6570\u5024\u3067\u8db3\u3057\u7b97\u3055\u308c\u308b\u3068\u3044\u3046\u3082\u306e\u3092\u4f5c\u3063\u3066\u307f\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u3053\u308c\u3092\u30b3\u30fc\u30c9\u306b\u3059\u308b\u3068\u3001\u3053\u306e\u3088\u3046\u306a\u611f\u3058\u3067\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"lua\" class=\"language-lua\">-- \u30c6\u30fc\u30d6\u30eb\u306e\u5b9a\u7fa9\nlocal table1 = {6, 4, 9, 8}\n\n-- \u8a08\u7b97\nlocal result = table1 + 2\n\n-- \u5370\u5237\nprint(result) --\u76ee\u6307\u3059\u51fa\u529b\uff1a{8, 6, 11, 10}<\/code><\/pre>\n\n\n\n<p>\u5148\u307b\u3069\u691c\u8a3c\u3057\u305f\u3088\u3046\u306b\u3001\u901a\u5e38\u306e\u30c6\u30fc\u30d6\u30eb\u3060\u3068\u3001\u3053\u306e\u30b3\u30fc\u30c9\u306f\u30a8\u30e9\u30fc\u304c\u51fa\u308b\u306e\u3067\u3001\u30e1\u30bf\u30c6\u30fc\u30d6\u30eb\u3092\u8a2d\u5b9a\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u30e1\u30bf\u30c6\u30fc\u30d6\u30eb\u3092\u4f7f\u3044\u3001\u300c\u76ee\u6307\u3059\u51fa\u529b\u300d\u3092\u5b9f\u73fe\u3057\u305f\u30b5\u30f3\u30d7\u30eb\u30b3\u30fc\u30c9\u304c\u3053\u3061\u3089\u3067\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"lua\" class=\"language-lua line-numbers\">--\u30c6\u30fc\u30d6\u30eb\u306e\u5b9a\u7fa9\nlocal table1 = {6, 4, 9, 8}\n\n-- \u30e1\u30bf\u30c6\u30fc\u30d6\u30eb\u306e\u5b9a\u7fa9\nlocal mt = {\n    __add = function(t, val)\n        local result = {}\n        for i, v in ipairs(t) do\n            result[i] = v + val\n        end\n        return result\n    end\n}\n\n-- table1\u306b\u30e1\u30bf\u30c6\u30fc\u30d6\u30eb\u3092\u8a2d\u5b9a\nsetmetatable(table1, mt)\n\n-- \u8a08\u7b97\nlocal result = table1 + 2\n\n-- \u5370\u5237\nprint(result)<\/code><\/pre>\n\n\n\n<p>\u30b3\u30fc\u30c9\u306e\u5185\u5bb9\u304c\u7406\u89e3\u3067\u304d\u306a\u304f\u3066\u3082\u3044\u3044\u306e\u3067\u3001<strong>\u3068\u306b\u304b\u304f\u30b3\u30d4\u30fc\u3057\u3066\u5b9f\u884c\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/strong><\/p>\n\n\n\n<p>\u51fa\u529b\u7d50\u679c\u306f\u3053\u306e\u3088\u3046\u306b\u306a\u308b\u306f\u305a\u3067\u3059\uff01<span class=\"keiko_blue\">\u5148\u307b\u3069\u306e\u300c\u671f\u5f85\u3059\u308b\u51fa\u529b\u300d\u3069\u3046\u308a\u306b\u306a\u3063\u3066\u3044\u307e\u3059\u306d\uff01<\/span><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"380\" height=\"109\" src=\"https:\/\/roblog.jp\/studio\/wp-content\/uploads\/2024\/08\/image-2.png\" alt=\"\" class=\"wp-image-3339\" srcset=\"https:\/\/roblog.jp\/studio\/wp-content\/uploads\/2024\/08\/image-2.png 380w, https:\/\/roblog.jp\/studio\/wp-content\/uploads\/2024\/08\/image-2-300x86.png 300w\" sizes=\"(max-width: 380px) 100vw, 380px\"><\/figure>\n\n\n\n<p>\u3082\u3061\u308d\u3093\u3001\u6f14\u7b97\u5b50\u306e\u5f8c\u306e\u6570\u5b57(2)\u3092\u5909\u66f4\u3059\u308b\u3053\u3068\u3082\u3067\u304d\u307e\u3059\u3002\u8a66\u3057\u306b\u3001100\u306b\u3057\u3066\u307f\u308b\u3068\u2026<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"365\" height=\"107\" src=\"https:\/\/roblog.jp\/studio\/wp-content\/uploads\/2024\/08\/image-3.png\" alt=\"\" class=\"wp-image-3340\" srcset=\"https:\/\/roblog.jp\/studio\/wp-content\/uploads\/2024\/08\/image-3.png 365w, https:\/\/roblog.jp\/studio\/wp-content\/uploads\/2024\/08\/image-3-300x88.png 300w\" sizes=\"(max-width: 365px) 100vw, 365px\"><\/figure>\n\n\n\n<p>100\u305a\u3064\u8db3\u3055\u308c\u307e\u3057\u305f\uff01<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-3\">\u30e1\u30bf\u30c6\u30fc\u30d6\u30eb\u306e\u57fa\u672c\u4e2d\u306e\u57fa\u672c\u3092\u7406\u89e3\u3059\u308b<\/h3>\n\n\n\n<p>\u5b9f\u969b\u306b\u30e1\u30bf\u30c6\u30fc\u30d6\u30eb\u3092\u4f7f\u3046\u3053\u3068\u304c\u3067\u304d\u305f\u3089\u3001\u30b3\u30fc\u30c9\u306e\u5185\u5bb9\u306b\u3064\u3044\u3066\u89e3\u8aac\u3057\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u307e\u305a\u306f\u3001\u3053\u306e\u90e8\u5206\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"lua\" class=\"language-lua\">-- table1\u306b\u30e1\u30bf\u30c6\u30fc\u30d6\u30eb\u3092\u8a2d\u5b9a\nsetmetatable(table1, mt)<\/code><\/pre>\n\n\n\n<p>\u30c6\u30fc\u30d6\u30eb\u306b\u30e1\u30bf\u30c6\u30fc\u30d6\u30eb\u3092\u8a2d\u5b9a\u3059\u308b\u306b\u306f\u3001<strong>setmetatable()<\/strong>\u3068\u3044\u3046\u7279\u5225\u306a\u95a2\u6570\u3092\u4f7f\u7528\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u95a2\u6570\u306e\u7b2c\u4e00\u5f15\u6570\u3067\u3001\u30e1\u30bf\u30c6\u30fc\u30d6\u30eb\u3092\u8a2d\u5b9a\u3059\u308b\u30c6\u30fc\u30d6\u30eb\u3092\u6307\u5b9a\u3057\u307e\u3059\u3002<br>\u305d\u3057\u3066\u3001\u7b2c\u4e8c\u5f15\u6570\u3067\u3001\u8a2d\u5b9a\u3059\u308b\u30e1\u30bf\u30c6\u30fc\u30d6\u30eb\u3092\u6307\u5b9a\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u30e1\u30bf\u30c6\u30fc\u30d6\u30eb\u304c\u5b9a\u7fa9\u3055\u308c\u3066\u3044\u308b\u306e\u306f\u3001\u3053\u306e\u90e8\u5206\u3067\u3059\u306d\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"lua\" class=\"language-lua\">-- \u30e1\u30bf\u30c6\u30fc\u30d6\u30eb\u306e\u5b9a\u7fa9\nlocal mt = {\n    __add = function(t, val)\n        local result = {}\n        for i, v in ipairs(t) do\n            result[i] = v + val\n        end\n        return result\n    end\n}<\/code><\/pre>\n\n\n<div id=\"sgb-css-id-1\" style=\"--sgb--custom--fuki: 15;\">\n<div class=\"wp-block-sgb-block-simple sgb-box-simple sgb-box-simple--title-overwrap sgb-box-simple--with-border\"><div style=\"background-color:var(--wp--preset--color--sango-main);color:#ffffff\" class=\"sgb-box-simple__title\">mt\u3068\u306f\uff1f<\/div><div class=\"sgb-box-simple__body\" style=\"border-color:var(--wp--preset--color--sango-main);background-color:#FFF\">\n<p>\u3053\u3053\u3067\u306e\u30e1\u30bf\u30c6\u30fc\u30d6\u30eb\u306e\u540d\u524d\u3067\u3042\u308b\u300cmt\u300d\u3068\u306f\u3001\u300cmetatable\u300d\u306e\u7565\u3067\u3059\u3002\u81ea\u5206\u3067\u30e1\u30bf\u30c6\u30fc\u30d6\u30eb\u3092\u5b9a\u7fa9\u3059\u308b\u3068\u304d\u306f\u3001\u5206\u304b\u308a\u3084\u3059\u3044\u540d\u524d\u306b\u3057\u307e\u3057\u3087\u3046\uff01<\/p>\n<\/div><\/div>\n<\/div>\n\n\n<p>\u3053\u306e\u30b3\u30fc\u30c9\u3067\u306f\u3001<code>mt<\/code>\u3068\u3044\u3046\u30c6\u30fc\u30d6\u30eb(\u30e1\u30bf\u30c6\u30fc\u30d6\u30eb)\u306e\u914d\u4e0b\u306b\u3001<code>__add<\/code>\u3068\u3044\u3046\u30ad\u30fc\u304c\u5165\u3063\u3066\u304a\u308a\u3001\u5024\u3068\u3057\u3066\u95a2\u6570\u304c\u683c\u7d0d\u3055\u308c\u3066\u3044\u308b\u69cb\u9020\u306b\u306a\u3063\u3066\u3044\u308b\u3053\u3068\u304c\u308f\u304b\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u3053\u306e\u3068\u304d\u3001\u30e1\u30bf\u30c6\u30fc\u30d6\u30eb\u306e\u914d\u4e0b\u306b\u3042\u308b<strong>__add<\/strong>\u306e\u3088\u3046\u306a\u30ad\u30fc\u3092\u3001<strong>\u30e1\u30bf\u30e1\u30bd\u30c3\u30c9<\/strong>\u3068\u547c\u3073\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u3053\u306e<code>__add<\/code>\u3068\u3044\u3046\u30e1\u30bf\u30e1\u30bd\u30c3\u30c9\u306f\u3001\u30c6\u30fc\u30d6\u30eb\u306b\u5bfe\u3057\u3066 <code>+<\/code> \u6f14\u7b97\u5b50\u3092\u4f7f\u7528\u3057\u305f\u969b\u306b\u3001\u30e1\u30bf\u30e1\u30bd\u30c3\u30c9\u306e\u5024\u3068\u306a\u3063\u3066\u3044\u308b\u95a2\u6570\u3092\u547c\u3073\u51fa\u3059\u3082\u306e\u3068\u306a\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n\n\n<div id=\"sgb-css-id-2\" style=\"--sgb--custom--fuki: 15;\">\n<div class=\"wp-block-sgb-block-simple sgb-box-simple sgb-box-simple--title-overwrap sgb-box-simple--with-border\"><div style=\"background-color:var(--wp--preset--color--sango-main);color:#ffffff\" class=\"sgb-box-simple__title\">\u30e1\u30bf\u30e1\u30bd\u30c3\u30c9\u306b\u3064\u3044\u3066<\/div><div class=\"sgb-box-simple__body\" style=\"border-color:var(--wp--preset--color--sango-main);background-color:#FFF\">\n<p><code>__add<\/code> \u3060\u3051\u3067\u306a\u304f\u3001<code>-<\/code>\u6f14\u7b97\u5b50\u3092\u4f7f\u7528\u3057\u305f\u969b\u306b\u547c\u3073\u51fa\u3055\u308c\u308b<code>__sub<\/code> \u3001<code>*<\/code> \u6f14\u7b97\u5b50\u3092\u4f7f\u7528\u3057\u305f\u969b\u306b\u547c\u3073\u51fa\u3055\u308c\u308b<code>__mul<\/code> \u306a\u3069\u3001\u305f\u304f\u3055\u3093\u306e\u30e1\u30bf\u30e1\u30bd\u30c3\u30c9\u304c\u3042\u308a\u307e\u3059\u3002\u307e\u305f\u3001\u6f14\u7b97\u5b50\u95a2\u9023\u4ee5\u5916\u306e\u30e1\u30bf\u30e1\u30bd\u30c3\u30c9\u3082\u3042\u308b\u306e\u3067\u3001\u5f8c\u307b\u3069\u3054\u7d39\u4ecb\u3057\u307e\u3059\u3002<\/p>\n<\/div><\/div>\n<\/div>\n\n\n<p>\u3067\u306f\u3001__add\u30e1\u30bf\u30e1\u30bd\u30c3\u30c9\u306e\u5024\u306b\u306a\u3063\u3066\u3044\u308b\u95a2\u6570\u306b\u30d5\u30a9\u30fc\u30ab\u30b9\u3092\u3042\u3066\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"lua\" class=\"language-lua\">function(t, val)\n   local result = {}\n   for i, v in ipairs(t) do\n       result[i] = v + val\n   end\n   return result\nend<\/code><\/pre>\n\n\n\n<p><code>__add<\/code>\u30e1\u30bd\u30c3\u30c9\u3067\u306f\u3001\u8a72\u5f53\u30e1\u30bf\u30c6\u30fc\u30d6\u30eb\u304c\u8a2d\u5b9a\u3055\u308c\u3066\u3044\u308b\u30c6\u30fc\u30d6\u30eb\u306b\u5bfe\u3057\u3066<code>+<\/code>\u6f14\u7b97\u5b50\u304c\u4f7f\u7528\u3055\u308c\u305f\u3068\u304d\u306b\u3001\u95a2\u6570\u3092\u5b9f\u884c\u3059\u308b\u3068\u3044\u3046\u3082\u306e\u3067\u3059\u304c\u3001\u95a2\u6570\u304c\u5b9f\u884c\u3055\u308c\u305f\u3068\u304d\u306b\u3001\u95a2\u6570\u306b2\u3064\u306e\u5f15\u6570\u304c\u6e21\u3055\u308c\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"lua\" class=\"language-lua\">function(t, val)<\/code><\/pre>\n\n\n\n<p>\u7b2c\u4e00\u5f15\u6570\u306e<code>t<\/code>\u306f\u3001\u95a2\u6570\u304c\u30c8\u30ea\u30ac\u30fc\u3055\u308c\u308b\u3053\u3068\u306b\u3064\u306a\u304c\u3063\u305f\u3001\u8a72\u5f53\u306e\u30c6\u30fc\u30d6\u30eb\u3067\u3059\u3002<br>\u5148\u307b\u3069\u306e\u300ctable1 + 2\u300d\u306e\u300ctable1\u300d\u306e\u90e8\u5206\u3067\u3059\u306d\u3002<\/p>\n\n\n\n<p>\u53cd\u5bfe\u306b\u3001\u7b2c\u4e8c\u5f15\u6570\u306e <code>val<\/code> \u306f\u3001\u6f14\u7b97\u5b50\u306e\u53f3\u306b\u3042\u305f\u308b\u5024\u306b\u306a\u308a\u307e\u3059\u3002\u300ctable1 + 2\u300d\u306e\u300c2\u300d\u306b\u3042\u305f\u308b\u90e8\u5206\u3067\u3059\u306d\u3002<\/p>\n\n\n\n<p>\u7b2c\u4e00\u5f15\u6570\u304c\u30c6\u30fc\u30d6\u30eb\u3001\u7b2c\u4e8c\u5f15\u6570\u304c\u6f14\u7b97\u5b50\u306e\u53f3\u306e\u5024\u3002<\/p>\n\n\n\n<p>\u3053\u308c\u3055\u3048\u6291\u3048\u305f\u3089\u3042\u3068\u306f\u304b\u3093\u305f\u3093\u3067\u3059\u306d\u3002\u305d\u306e\u30c6\u30fc\u30d6\u30eb\u3084\u5024\u3092\u5143\u306b\u7d50\u679c\u3092\u8a08\u7b97\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u305d\u308c\u304c\u3001\u3053\u306e\u90e8\u5206\u3067\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"lua\" class=\"language-lua\">        local result = {}\n        for i, v in ipairs(t) do\n            result[i] = v + val\n        end<\/code><\/pre>\n\n\n\n<p>for\u6587\u3092\u4f7f\u3044\u3001\u30c6\u30fc\u30d6\u30eb\u306e\u8981\u7d20\u3054\u3068\u306b\u6307\u5b9a\u306e\u6570\u5024\u3092\u8db3\u3057\u3066\u3001result\u30c6\u30fc\u30d6\u30eb\u306b\u683c\u7d0d\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u6700\u5f8c\u306b\u3001\u8a08\u7b97\u7d50\u679c\u3067\u3042\u308bresult\u30c6\u30fc\u30d6\u30eb\u3092return\u3057\u3066\u3001\u5b8c\u4e86\u3067\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"lua\" class=\"language-lua\">        return result<\/code><\/pre>\n\n\n\n<p>\u3053\u308c\u3067\u3001<code>table1 + 2<\/code> \u304c\u3001\u95a2\u6570\u5185\u3067\u8a08\u7b97\u3055\u308c\u305fresult\u30c6\u30fc\u30d6\u30eb\u306b\u306a\u308b\u308f\u3051\u3067\u3059\u306d\uff01<\/p>\n\n\n\n<p>\u3053\u308c\u3067\u3001\u30e1\u30bf\u30c6\u30fc\u30d6\u30eb\u306e\u57fa\u672c\u4e2d\u306e\u57fa\u672c\u306f\u30de\u30b9\u30bf\u30fc\u3067\u304d\u307e\u3057\u305f\u306d\uff01\u304a\u3064\u304b\u308c\u3055\u307e\u3067\u3057\u305f\uff5e\ud83c\udf89<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-4\">\u30e1\u30bf\u30c6\u30fc\u30d6\u30eb\u3067\u30e1\u30bf\u30c6\u30fc\u30d6\u30eb\u3092\u8a2d\u5b9a\u3059\u308b<\/h3>\n\n\n\n<p>\u3053\u306e\u30bb\u30af\u30b7\u30e7\u30f3\u3067\u306f\u3001\u30e1\u30bf\u30c6\u30fc\u30d6\u30eb\u3067\u30e1\u30bf\u30c6\u30fc\u30d6\u30eb\u3092\u8a2d\u5b9a\u3059\u308b\u65b9\u6cd5\u306b\u3064\u3044\u3066\u5b66\u3093\u3067\u307f\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u307e\u305a\u306f\u3001\u4ee5\u4e0b\u306e\u30b3\u30fc\u30c9\u3092\u898b\u3066\u307f\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"lua\" class=\"language-lua line-numbers\">--\u30c6\u30fc\u30d6\u30eb\u306e\u5b9a\u7fa9\nlocal table1 = {6, 4, 9, 8}\n\n-- \u30e1\u30bf\u30c6\u30fc\u30d6\u30eb\u306e\u5b9a\u7fa9\nlocal mt = {\n\t__add = function(t, val)\n\t\tlocal result = {}\n\t\tfor i, v in ipairs(t) do\n\t\t\tresult[i] = v + val\n\t\tend\n\t\treturn result\n\tend\n}\n\n-- table1\u306b\u30e1\u30bf\u30c6\u30fc\u30d6\u30eb\u3092\u8a2d\u5b9a\nsetmetatable(table1, mt)\n\n-- \u8a08\u7b97\nlocal result = table1 + 2 + 5\n\n-- \u5370\u5237\nprint(result)<\/code><\/pre>\n\n\n\n<p>\u5148\u307b\u3069\u306e\u30b3\u30fc\u30c9\u3068\u306e\u9055\u3044\u306f\u3001\u8a08\u7b97\u90e8\u5206\u306b<code>+5<\/code> \u304c\u8ffd\u52a0\u3055\u308c\u305f\u3053\u3068\u3067\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"lua\" class=\"language-lua\">-- \u8a08\u7b97\nlocal result = table1 + 2 + 5<\/code><\/pre>\n\n\n\n<p>\u305d\u308c\u3067\u306f\u3001\u3053\u306e\u30b3\u30fc\u30c9\u3092\u30b3\u30d4\u30fc\u3057\u3066\u3001\u5b9f\u884c\u3057\u3066\u307f\u307e\u3057\u3087\u3046\uff01<\/p>\n\n\n\n<p>\u2026\u3069\u3046\u306a\u308a\u307e\u3057\u305f\u304b\uff1f<\/p>\n\n\n\n<p>\u3053\u306e\u3088\u3046\u306b\u3001\u30a8\u30e9\u30fc\u304c\u767a\u751f\u3057\u305f\u306f\u305a\u3067\u3059\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"1023\" height=\"88\" src=\"https:\/\/roblog.jp\/studio\/wp-content\/uploads\/2024\/08\/image-4.png\" alt=\"\" class=\"wp-image-3342\" srcset=\"https:\/\/roblog.jp\/studio\/wp-content\/uploads\/2024\/08\/image-4.png 1023w, https:\/\/roblog.jp\/studio\/wp-content\/uploads\/2024\/08\/image-4-300x26.png 300w, https:\/\/roblog.jp\/studio\/wp-content\/uploads\/2024\/08\/image-4-768x66.png 768w, https:\/\/roblog.jp\/studio\/wp-content\/uploads\/2024\/08\/image-4-940x81.png 940w\" sizes=\"(max-width: 1023px) 100vw, 1023px\"><\/figure>\n\n\n\n<p>\u3053\u306e\u30a8\u30e9\u30fc\u306f\u3001\u30c6\u30fc\u30d6\u30eb\u306b\u30e1\u30bf\u30c6\u30fc\u30d6\u30eb\u304c\u8a2d\u5b9a\u3055\u308c\u3066\u3044\u306a\u304b\u3063\u305f\u6642\u3068\u540c\u3058\u30a8\u30e9\u30fc\u3067\u3059\u306d\u3002<\/p>\n\n\n\n<p>\u3057\u304b\u3057\u3001\u30c6\u30fc\u30d6\u30eb\u306b\u30e1\u30bf\u30c6\u30fc\u30d6\u30eb\u306f\u8a2d\u5b9a\u3055\u308c\u3066\u3044\u308b\u306f\u305a\u3067\u3059\u3002\u5909\u66f4\u70b9\u306f\u3001\u8a08\u7b97\u90e8\u5206\u306b<code>+5<\/code> \u3092\u8ffd\u52a0\u3057\u305f\u3060\u3051\u3002\u3069\u3046\u3057\u3066\u3001\u30a8\u30e9\u30fc\u304c\u767a\u751f\u3057\u3066\u3057\u307e\u3063\u305f\u306e\u3067\u3057\u3087\u3046\u304b\uff1f<\/p>\n\n\n\n<p>\u305d\u306e\u7b54\u3048\u306f\u3001<span class=\"keiko_blue\">\u65b0\u3057\u3044\u30c6\u30fc\u30d6\u30eb\u304c\u30e1\u30bf\u30c6\u30fc\u30d6\u30eb\u3067\u306f\u306a\u304f\u306a\u3063\u3066\u3057\u307e\u3063\u305f\u305f\u3081<\/span>\u3067\u3059\u3002<\/p>\n\n\n\n<p>\u3069\u3046\u3044\u3046\u3053\u3068\u306a\u306e\u304b\u89e3\u8aac\u3057\u307e\u3059\u3002<br>\u307e\u305a\u3001\u3053\u306e\u95a2\u6570\u90e8\u5206\u3067\u306f\u3001\u65b0\u3057\u3044<code>result<\/code> \u30c6\u30fc\u30d6\u30eb\u3092\u4f5c\u6210\u3057\u3001\u30c6\u30fc\u30d6\u30eb\u3068\u5024\u3092\u3082\u3068\u306b\u3001\u305d\u306e\u30c6\u30fc\u30d6\u30eb\u3092\u8fd4\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"lua\" class=\"language-lua\">\t\tlocal result = {}\n\t\tfor i, v in ipairs(t) do\n\t\t\tresult[i] = v + val\n\t\tend\n\t\treturn result<\/code><\/pre>\n\n\n\n<p>\u3088\u304f\u8003\u3048\u3066\u307f\u3066\u304f\u3060\u3055\u3044\u3002<code>result<\/code> \u30c6\u30fc\u30d6\u30eb\u306f\u3042\u304f\u307e\u3067\u3001\u5143\u306e\u30c6\u30fc\u30d6\u30eb\u306e\u30c7\u30fc\u30bf\u3092\u3082\u3068\u306b\u4f5c\u6210\u3055\u308c\u305f\u3082\u306e\u3067\u3042\u3063\u3066\u3001\u5143\u306e\u30c6\u30fc\u30d6\u30eb\u305d\u306e\u3082\u306e\u3067\u306f\u306a\u3044\u306e\u3067\u3059\u3002<\/p>\n\n\n\n<p>\u95a2\u6570\u5185\u3067\u65b0\u3057\u304f\u30c6\u30fc\u30d6\u30eb\u3092\u4f5c\u6210\u3057\u3066\u3044\u308b\u306e\u3067\u3001\u305d\u306e\u30c6\u30fc\u30d6\u30eb\u306b\u30e1\u30bf\u30c6\u30fc\u30d6\u30eb\u306f\u8a2d\u5b9a\u3055\u308c\u3066\u3044\u306a\u3044\u3068\u3044\u3046\u308f\u3051\u306a\u3093\u3067\u3059\u306d\u3002<\/p>\n\n\n\n<p>\u305d\u306e\u305f\u3081\u3001<code>\u30e1\u30bf\u30c6\u30fc\u30d6\u30eb + 2 + 5<\/code> \u2192<code>\u666e\u901a\u306e\u30c6\u30fc\u30d6\u30eb + 5<\/code> \u3068\u306a\u308a\u3001\u30a8\u30e9\u30fc\u304c\u767a\u751f\u3057\u3066\u3057\u307e\u3063\u305f\u306e\u3067\u3059\u3002<\/p>\n\n\n\n<p>\u3068\u3044\u3046\u3053\u3068\u3067\u3001\u30a8\u30e9\u30fc\u3092\u89e3\u6d88\u3059\u308b\u306b\u306f\u3001\u65b0\u3057\u3044\u30c6\u30fc\u30d6\u30eb\u306b\u3082<code>setmetatable()<\/code> \u3092\u5b9f\u884c\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<p><code>setmetatable()<\/code> \u306e\u7b2c\u4e00\u5f15\u6570\u306b\u306f\u3001<code>result<\/code> \u30c6\u30fc\u30d6\u30eb\u3092\u6307\u5b9a\u3059\u308c\u3070\u3088\u3044\u3067\u3059\u304c\u3001\u7b2c\u4e8c\u5f15\u6570\u306e\u30e1\u30bf\u30c6\u30fc\u30d6\u30eb\u306f\u3069\u3046\u6307\u5b9a\u3059\u308c\u3070\u3044\u3044\u3067\u3057\u3087\u3046\u304b\uff1f<\/p>\n\n\n\n<p>\u5143\u306e\u30c6\u30fc\u30d6\u30eb\u306b\u8a2d\u5b9a\u3055\u308c\u3066\u3044\u308b\u30e1\u30bf\u30c6\u30fc\u30d6\u30eb\u3068\u540c\u3058\u3082\u306e\u3092\u8a2d\u5b9a\u3057\u305f\u3044\u306e\u3067\u3001\u305d\u306e\u30c6\u30fc\u30d6\u30eb\u306e\u30e1\u30bf\u30c6\u30fc\u30d6\u30eb\u3092\u53d6\u5f97\u3059\u308b\u95a2\u6570\u3092\u4f7f\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u305d\u308c\u304c\u3001<code>getmetatable()<\/code> \u3067\u3059\u3002set\u304cget\u306b\u5909\u308f\u3063\u305f\u3060\u3051\u3067\u3059\u306d\u3002<\/p>\n\n\n\n<p>\u7b2c\u4e00\u5f15\u6570\u306b\u30e1\u30bf\u30c6\u30fc\u30d6\u30eb\u3092\u53d6\u5f97\u3057\u305f\u3044\u30c6\u30fc\u30d6\u30eb\u3092\u3044\u308c\u308c\u3070\u3001\u8fd4\u308a\u5024\u3068\u3057\u3066\u30e1\u30bf\u30c6\u30fc\u30d6\u30eb\u304c\u8fd4\u3048\u3063\u3066\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u3053\u308c\u3092\u8e0f\u307e\u3048\u3066\u3001\u30b3\u30fc\u30c9\u306b\u4ee5\u4e0b\u306e\u95a2\u6570\u3092\u8ffd\u52a0\u3059\u308c\u3070\u3001OK\u3067\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"lua\" class=\"language-lua\">\t\tsetmetatable(result, getmetatable(t))<\/code><\/pre>\n\n\n\n<p>\u3053\u308c\u3067\u3001\u95a2\u6570\u5168\u4f53\u306f\u3053\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"lua\" class=\"language-lua\">function(t, val)\n    local result = {}\n    for i, v in ipairs(t) do\n        result[i] = v + val\n    end\n    setmetatable(result, getmetatable(t))\n    return result\nend<\/code><\/pre>\n\n\n\n<p>\u30b3\u30fc\u30c9\u3092\u4fee\u6b63\u3067\u304d\u305f\u3089\u3001\u3082\u3046\u4e00\u5ea6\u5b9f\u884c\u3057\u3066\u307f\u307e\u3057\u3087\u3046\uff01<\/p>\n\n\n\n<p>\u30a8\u30e9\u30fc\u304c\u767a\u751f\u305b\u305a\u306b\u3001\u60f3\u5b9a\u3069\u304a\u308a\u306e\u7d50\u679c\u3092\u3060\u3059\u3053\u3068\u304c\u3067\u304d\u307e\u3057\u305f\uff01<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"414\" height=\"100\" src=\"https:\/\/roblog.jp\/studio\/wp-content\/uploads\/2024\/08\/image-5.png\" alt=\"\" class=\"wp-image-3343\" srcset=\"https:\/\/roblog.jp\/studio\/wp-content\/uploads\/2024\/08\/image-5.png 414w, https:\/\/roblog.jp\/studio\/wp-content\/uploads\/2024\/08\/image-5-300x72.png 300w\" sizes=\"(max-width: 414px) 100vw, 414px\"><\/figure>\n\n\n\n<p><code>getmetatable()<\/code> \u3082\u3001\u3088\u304f\u4f7f\u3046\u95a2\u6570\u306a\u306e\u3067\u899a\u3048\u3066\u304a\u304d\u307e\u3057\u3087\u3046\uff01<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-5\">\u305d\u306e\u4ed6\u306e\u6f14\u7b97\u5b50\u95a2\u9023\u306e\u30e1\u30bf\u30e1\u30bd\u30c3\u30c9\u3084\u88dc\u8db3\u4e8b\u9805<\/h3>\n\n\n\n<p>\u3053\u306e\u30bb\u30af\u30b7\u30e7\u30f3\u3067\u306f\u3001\u305d\u306e\u4ed6\u3001\u30e1\u30bf\u30c6\u30fc\u30d6\u30eb\u3092\u6271\u3046\u4e0a\u3067\u5fc5\u8981\u306a\u57fa\u672c\u7684\u306a\u60c5\u5831\u3092\u88dc\u8db3\u3057\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u6700\u521d\u306b\u3001\u7b97\u8853\u6f14\u7b97\u5b50\u306b\u95a2\u9023\u3059\u308b\u30e1\u30bf\u30e1\u30bd\u30c3\u30c9\u306e\u4e00\u89a7\u3092\u3054\u7d39\u4ecb\u3057\u307e\u3059\u3002<\/p>\n\n\n<div id=\"id-e408aa70-befe-4e20-b27a-76f66e02cde6\">\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>\u30e1\u30bf\u30e1\u30bd\u30c3\u30c9<\/th><th>\u5bfe\u5fdc\u3059\u308b\u7b97\u8853\u6f14\u7b97\u5b50<\/th><th>\u8aac\u660e<\/th><\/tr><\/thead><tbody><tr><td><code>__add<\/code><\/td><td><code>+<\/code><\/td><td>\u52a0\u7b97 (\u4f8b: <code>a + b<\/code>)<\/td><\/tr><tr><td><code>__sub<\/code><\/td><td><code>-<\/code><\/td><td>\u6e1b\u7b97 (\u4f8b: <code>a - b<\/code>)<\/td><\/tr><tr><td><code>__mul<\/code><\/td><td><code>*<\/code><\/td><td>\u4e57\u7b97 (\u4f8b: <code>a * b<\/code>)<\/td><\/tr><tr><td><code>__div<\/code><\/td><td><code>\/<\/code><\/td><td>\u9664\u7b97 (\u4f8b: <code>a \/ b<\/code>)<\/td><\/tr><tr><td><code>__mod<\/code><\/td><td><code>%<\/code><\/td><td>\u5270\u4f59 (\u4f8b: <code>a % b<\/code>)<\/td><\/tr><tr><td><code>__pow<\/code><\/td><td><code>^<\/code><\/td><td>\u7d2f\u4e57 (\u4f8b: <code>a ^ b<\/code>)<\/td><\/tr><tr><td><code>__unm<\/code><\/td><td><code>-<\/code> (\u5358\u9805)<\/td><td>\u8ca0\u6570\u5316 (\u4f8b: <code>-a<\/code>)<\/td><\/tr><\/tbody><\/table><\/figure>\n<\/div>\n\n\n<p>\u7b97\u8853\u6f14\u7b97\u5b50\u306b\u95a2\u9023\u3059\u308b\u30e1\u30bf\u30e1\u30bd\u30c3\u30c9\u3068\u3057\u3066\u306f\u3001\u4e0a\u8a187\u3064\u304c\u3042\u308a\u307e\u3059\uff01\u3053\u308c\u3089\u5168\u3066\u3092\u6697\u8a18\u3059\u308b\u5fc5\u8981\u306f\u306a\u3044\u3068\u601d\u3044\u307e\u3059\u3002\u30b9\u30af\u30b7\u30e7\u304b\u306a\u306b\u304b\u306b\u4fdd\u5b58\u3057\u3066\u3001\u3044\u3064\u3067\u3082\u898b\u8fd4\u305b\u308b\u3088\u3046\u306b\u3057\u3066\u304a\u3051\u3070OK\u3002\u4f7f\u3063\u3066\u3044\u304f\u3046\u3061\u306b\u81ea\u7136\u3068\u899a\u3048\u3089\u308c\u308c\u3070\u3044\u3044\u3067\u3059\u306d\uff01<\/p>\n\n\n\n<p>\u6b21\u306b\u3001\u6bd4\u8f03\u6f14\u7b97\u5b50\u306e\u30e1\u30bf\u30e1\u30bd\u30c3\u30c9\u3092\u7d39\u4ecb\u3057\u307e\u3059\u3002<\/p>\n\n\n<div id=\"id-88f6020b-e2ce-4fd5-aa73-a9c00ff8ab0b\">\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>\u30e1\u30bf\u30e1\u30bd\u30c3\u30c9<\/th><th>\u5bfe\u5fdc\u3059\u308b\u7b97\u8853\u6f14\u7b97\u5b50<\/th><th>\u8aac\u660e<\/th><\/tr><\/thead><tbody><tr><td><code>__eq<\/code><\/td><td>==<\/td><td>\u7b49\u3057\u3044\u304b\u3069\u3046\u304b (\u4f8b: <code>a == b<\/code>)<\/td><\/tr><tr><td><code>__<\/code>It<\/td><td>&lt;<\/td><td>\u5c0f\u3055\u3044\u304b\u3069\u3046\u304b (\u4f8b: <code>a &lt; b<\/code>)<\/td><\/tr><tr><td><code>__le<\/code><\/td><td>&lt;=<\/td><td>\u5c0f\u3055\u3044or\u7b49\u3057\u3044\u304b\u3069\u3046\u304b (\u4f8b: <code>a &lt;= b<\/code>)<\/td><\/tr><\/tbody><\/table><\/figure>\n<\/div>\n\n\n<p>\u6bd4\u8f03\u6f14\u7b97\u5b50\u306e\u30b3\u30fc\u30c9\u306e\u4f8b\u306f\u6b21\u306e\u3068\u304a\u308a\u3067\u3059\u3002(ChatGPT\u306b\u66f8\u3044\u3066\u3082\u3089\u3063\u305f\u3082\u306e\u3092\u5c11\u3057\u624b\u76f4\u3057\u3057\u307e\u3057\u305f\u3002\u8c61\u3068\u306d\u305a\u307f\u306e\u4f8b\u3067\u5206\u304b\u308a\u3084\u3059\u3044\u3067\u3059\u306d)<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"lua\" class=\"language-lua line-numbers\">-- \u52d5\u7269\u306e\u91cd\u3055\u3092\u7ba1\u7406\u3059\u308b\u30c6\u30fc\u30d6\u30eb\nlocal elephant = {weight = 5000}  -- \u8c61\u306e\u91cd\u3055\u306f5000kg\nlocal mouse = {weight = 0.05}     -- \u306d\u305a\u307f\u306e\u91cd\u3055\u306f0.05kg\n\n-- \u30e1\u30bf\u30c6\u30fc\u30d6\u30eb\u3092\u4f5c\u6210\u3057\u3066\u3001\u6bd4\u8f03\u6f14\u7b97\u306e\u30eb\u30fc\u30eb\u3092\u5b9a\u7fa9\nlocal meta = {}\n\n-- \u7b49\u3057\u3044\u304b\u3069\u3046\u304b\u3092\u6bd4\u8f03\u3059\u308b\u30e1\u30bf\u30e1\u30bd\u30c3\u30c9\nmeta.__eq = function(animal1, animal2)\n    return animal1.weight == animal2.weight\nend\n\n-- \u5c0f\u3055\u3044\u304b\u3069\u3046\u304b\u3092\u6bd4\u8f03\u3059\u308b\u30e1\u30bf\u30e1\u30bd\u30c3\u30c9\nmeta.__lt = function(animal1, animal2)\n    return animal1.weight &lt; animal2.weight\nend\n\n-- \u5c0f\u3055\u3044\u304b\u307e\u305f\u306f\u7b49\u3057\u3044\u304b\u3069\u3046\u304b\u3092\u6bd4\u8f03\u3059\u308b\u30e1\u30bf\u30e1\u30bd\u30c3\u30c9\nmeta.__le = function(animal1, animal2)\n    return animal1.weight &lt;= animal2.weight\nend\n\n-- \u5404\u52d5\u7269\u306e\u30c6\u30fc\u30d6\u30eb\u306b\u30e1\u30bf\u30c6\u30fc\u30d6\u30eb\u3092\u8a2d\u5b9a\nsetmetatable(elephant, meta)\nsetmetatable(mouse, meta)\n\n-- \u52d5\u7269\u306e\u91cd\u3055\u3092\u6bd4\u8f03\u3057\u3066\u307f\u308b\nprint(elephant == mouse)  -- \u8c61\u3068\u306d\u305a\u307f\u306e\u91cd\u3055\u306f\u540c\u3058\u3067\u3059\u304b\uff1f\uff08false\u3068\u8868\u793a\u3055\u308c\u308b\uff09\nprint(elephant &lt; mouse)   -- \u8c61\u306f\u306d\u305a\u307f\u3088\u308a\u8efd\u3044\u3067\u3059\u304b\uff1f\uff08false\u3068\u8868\u793a\u3055\u308c\u308b\uff09\nprint(elephant &gt; mouse)   -- &lt;\u306e\u7d50\u679c\u3092\u53cd\u8ee2\u3057\u305f\u7d50\u679c (true\u3068\u8868\u793a\u3055\u308c\u308b)\nprint(elephant &lt;= mouse)  -- \u8c61\u306f\u306d\u305a\u307f\u3088\u308a\u8efd\u3044\u304b\u3001\u307e\u305f\u306f\u540c\u3058\u91cd\u3055\u3067\u3059\u304b\uff1f\uff08false\u3068\u8868\u793a\uff09\nprint(mouse &lt;= elephant)  -- \u306d\u305a\u307f\u306f\u8c61\u3088\u308a\u8efd\u3044\u304b\u3001\u307e\u305f\u306f\u540c\u3058\u91cd\u3055\u3067\u3059\u304b\uff1f\uff08true\u3068\u8868\u793a\u3055\u308c\u308b\uff09<\/code><\/pre>\n\n\n<div id=\"sgb-css-id-3\" style=\"--sgb--custom--fuki: 15;\">\n<div class=\"wp-block-sgb-block-simple sgb-box-simple sgb-box-simple--title-overwrap sgb-box-simple--with-border\"><div style=\"background-color:var(--wp--preset--color--sango-main);color:#ffffff\" class=\"sgb-box-simple__title\">\u6bd4\u8f03\u6f14\u7b97\u5b50\u306b\u3064\u3044\u3066\u88dc\u8db3<\/div><div class=\"sgb-box-simple__body\" style=\"border-color:var(--wp--preset--color--sango-main);background-color:#FFF\">\n<p>Lua\u3067\u306f<code>&gt;<\/code>\uff08\u5927\u304d\u3044\uff09\u3084<code>&gt;=<\/code>\uff08\u5927\u304d\u3044\u304b\u7b49\u3057\u3044\uff09\u306e\u52d5\u4f5c\u3092\u30e1\u30bf\u30c6\u30fc\u30d6\u30eb\u306b\u3088\u3063\u3066\u30ab\u30b9\u30bf\u30de\u30a4\u30ba\u3057\u306a\u304f\u3066\u3082\u3001<code>__lt<\/code>\u3084<code>__le<\/code>\u304c\u5b9a\u7fa9\u3055\u308c\u3066\u3044\u308b\u3068\u81ea\u52d5\u7684\u306b\u53cd\u8ee2\u3057\u305f\u7d50\u679c\u3092\u4f7f\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u4f8b\u3048\u3070\u3001\u3053\u306e\u30b3\u30fc\u30c9\u306e\u4f8b\u306e\u5834\u5408\u3001<code>elephant &gt; mouse<\/code>\u304c<code>true<\/code>\u306e\u3068\u304d\u3001<code>elephant &lt; mouse<\/code>\u306f<code>false<\/code>\u3068\u3057\u3066\u52d5\u4f5c\u3057\u307e\u3059\u3002<\/p>\n<\/div><\/div>\n<\/div>\n\n\n<p>\u4ee5\u4e0a\u304c\u6bd4\u8f03\u6f14\u7b97\u5b50\u306b\u3064\u3044\u3066\u306e\u7d39\u4ecb\u3067\u3057\u305f\u3002<\/p>\n\n\n\n<p>\u307e\u305f\u3001\u30e1\u30bf\u30c6\u30fc\u30d6\u30eb\u5168\u4f53\u306b\u304a\u3044\u3066\u30012\u3064\u3001\u88dc\u8db3\u4e8b\u9805\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n\n\n<div id=\"sgb-css-id-4\" style=\"--sgb--custom--fuki: 15;\">\n<div class=\"wp-block-sgb-block-simple sgb-box-simple sgb-box-simple--title-overwrap sgb-box-simple--with-border\"><div style=\"background-color:var(--wp--preset--color--sango-main);color:#ffffff\" class=\"sgb-box-simple__title\">\u30e1\u30bf\u30c6\u30fc\u30d6\u30eb\u306b\u3064\u3044\u3066\u88dc\u8db3<\/div><div class=\"sgb-box-simple__body\" style=\"border-color:var(--wp--preset--color--sango-main);background-color:#FFF\"><div style=\"--sgb-list-icon-color: var(--sgb-main-color);\">\n<ul class=\"wp-block-list is-style-sango-list-check\">\n<li>\u30e1\u30bf\u30c6\u30fc\u30d6\u30eb\u306f\u30c6\u30fc\u30d6\u30eb\u3067\u5b9a\u7fa9\u3059\u308b\u306e\u3067\u3001\u67d4\u8edf\u3002\u4f8b\u3048\u3070\u30011\u3064\u306e\u30e1\u30bf\u30c6\u30fc\u30d6\u30eb\u306b\u8907\u6570\u306e\u30e1\u30bf\u30e1\u30bd\u30c3\u30c9\u3092\u8a2d\u5b9a\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u308b\u3057\u3001\u30b9\u30af\u30ea\u30d7\u30c8\u306e\u9014\u4e2d\u3067\u52d5\u7684\u306b\u30e1\u30bf\u30e1\u30bd\u30c3\u30c9\u3084\u305d\u306e\u95a2\u6570\u3092\u5909\u3048\u308b\u3053\u3068\u3082\u3067\u304d\u308b\u3002<\/li>\n\n\n\n<li>1\u3064\u306e\u30c6\u30fc\u30d6\u30eb\u306b\u306f1\u3064\u306e\u30e1\u30bf\u30c6\u30fc\u30d6\u30eb\u3057\u304b\u8a2d\u5b9a\u3067\u304d\u306a\u3044\u3002\uff08\u4e0a\u66f8\u304d\u3055\u308c\u308b\uff09<\/li>\n<\/ul>\n<\/div><\/div><\/div>\n<\/div>\n\n\n<p>\u4ee5\u4e0a\u3067\u3001\u30e1\u30bf\u30c6\u30fc\u30d6\u30eb\u306e\u57fa\u790e\u7684\u306a\u90e8\u5206\u306f\u7406\u89e3\u3067\u304d\u305f\u306f\u305a\u3067\u3059\u3002<\/p>\n\n\n\n<p>\u307e\u3060\u7406\u89e3\u3067\u304d\u306a\u3044\u65b9\u306f\u3001\u4f55\u5ea6\u3067\u3082\u8aad\u307f\u8fd4\u3057\u3066\u304f\u3060\u3055\u3044\u306d\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"i-6\">\u7279\u6b8a\u306a\u30e1\u30bf\u30e1\u30bd\u30c3\u30c9<\/h2>\n\n\n\n<p>\u3053\u3053\u307e\u3067\u306f\u3001\u30e1\u30bf\u30c6\u30fc\u30d6\u30eb\u306e\u57fa\u672c\u7684\u306a\u6982\u5ff5\u3068\u3001\u7b97\u8853\u6f14\u7b97\u5b50\u30fb\u6bd4\u8f03\u6f14\u7b97\u5b50\u306e\u30e1\u30bf\u30e1\u30bd\u30c3\u30c9\u3092\u7d39\u4ecb\u3057\u307e\u3057\u305f\u3002<\/p>\n\n\n\n<p>\u3053\u3053\u304b\u3089\u306f\u3001\u4e3b\u8981\u306a\u305d\u306e\u4ed6\u306e\u7279\u6b8a\u306a\u6a5f\u80fd\u3092\u6301\u3063\u305f\u30e1\u30bf\u30e1\u30bd\u30c3\u30c9\u306b\u3064\u3044\u3066\u7d39\u4ecb\u3057\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u3053\u308c\u3089\u306e\u30e1\u30bf\u30e1\u30bd\u30c3\u30c9\u3092\u6271\u3048\u308b\u3088\u3046\u306b\u306a\u3063\u3066\u3001\u521d\u3081\u3066\u30e1\u30bf\u30c6\u30fc\u30d6\u30eb\u306e\u771f\u4fa1\u3092\u767a\u63ee\u3067\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-7\">__index \u30e1\u30bf\u30e1\u30bd\u30c3\u30c9<\/h3>\n\n\n\n<p><code>__index<\/code> \u306f\u3001\u6700\u3082\u4f7f\u7528\u983b\u5ea6\u304c\u9ad8\u3044\u3068\u3055\u308c\u3066\u3044\u308b\u30e1\u30bf\u30e1\u30bd\u30c3\u30c9\u3067\u3059\u3002<\/p>\n\n\n\n<p>\u3053\u306e\u30e1\u30bf\u30e1\u30bd\u30c3\u30c9\u306f\u3001\u30c6\u30fc\u30d6\u30eb\u3067\u30a2\u30af\u30bb\u30b9\u3057\u3088\u3046\u3068\u3057\u3066\u3044\u308b\u30ad\u30fc\u304c\u5b58\u5728\u3057\u306a\u3044\u5834\u5408\u306b\u547c\u3073\u51fa\u3055\u308c\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u4f8b\u3048\u3070\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u3001\u30c6\u30fc\u30d6\u30eb\u306b\u5b58\u5728\u3057\u306a\u3044\u30ad\u30fc\u306b\u30a2\u30af\u30bb\u30b9\u3057\u3088\u3046\u3068\u3059\u308b\u3053\u3068\u3067\u3001<code>\"default-value\"<\/code> \u3068\u3044\u3046\u30c7\u30d5\u30a9\u30eb\u30c8\u5024\u3092\u8a2d\u5b9a\u3059\u308b\u3053\u3068\u304c\u53ef\u80fd\u3067\u3059\u3002\uff08\u3053\u306e\u30e1\u30bf\u30e1\u30bd\u30c3\u30c9\u3092\u8a2d\u5b9a\u3057\u3066\u3044\u306a\u3044\u5834\u5408\u3001\u51fa\u529b\u7d50\u679c\u306f<code>nil<\/code>\u306b\u306a\u308a\u307e\u3059\u3002\uff09<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"lua\" class=\"language-lua\">local myTable = {}\nlocal mt = {\n    __index = function(table, key)\n        return \"default-value\"\n    end\n}\nsetmetatable(myTable, mt)\n\nprint(myTable.someKey)  -- \u51fa\u529b\u7d50\u679c: \"default-value\"<\/code><\/pre>\n\n\n\n<p>\u30c6\u30fc\u30d6\u30eb\u306b\u30c7\u30d5\u30a9\u30eb\u30c8\u5024\u3092\u8a2d\u5b9a\u3067\u304d\u308b\u306e\u306f\u3001\u304b\u306a\u308a\u4fbf\u5229\u306a\u306e\u3067\u306f\u306a\u3044\u3067\u3057\u3087\u3046\u304b\u3002<\/p>\n\n\n\n<p>\u307e\u305f\u3001<code>__index<\/code> \u306f\u3001\u5225\u306e\u30c6\u30fc\u30d6\u30eb\u304b\u3089\u30c7\u30fc\u30bf\u3092\u53d6\u5f97\u3059\u308b\u7528\u9014\u3068\u3057\u3066\u3082\u5229\u7528\u3067\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"lua\" class=\"language-lua\">local defaultValues = {x = 10, y = 20}\nlocal myTable = {}\nlocal mt = {\n    __index = defaultValues  -- \u5225\u306e\u30c6\u30fc\u30d6\u30eb\u3092\u53c2\u7167\u3059\u308b\n}\nsetmetatable(myTable, mt)\n\n-- \u30ad\u30fc \"x\" \u3084 \"y\" \u306f myTable \u306b\u306f\u5b58\u5728\u3057\u306a\u3044\u304c\u3001defaultValues \u304b\u3089\u53d6\u5f97\u3055\u308c\u308b\nprint(myTable.x)  -- \u51fa\u529b\u7d50\u679c: 10\nprint(myTable.y)  -- \u51fa\u529b\u7d50\u679c: 20<\/code><\/pre>\n\n\n\n<p>\u3053\u308c\u3092\u4e0a\u624b\u304f\u6d3b\u7528\u3059\u308c\u3070\u3001\u30b3\u30fc\u30c9\u306e\u518d\u5229\u7528\u6027\u3084\u67d4\u8edf\u6027\u3092\u9ad8\u3081\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u306d\u3002<\/p>\n\n\n\n<p>\u4ee5\u4e0a\u304c\u3001\u5168\u30e1\u30bf\u30e1\u30bd\u30c3\u30c9\u306e\u4e2d\u3067\u6700\u3082\u4f7f\u7528\u983b\u5ea6\u304c\u591a\u3044\u3067\u3042\u308d\u3046\u30e1\u30bf\u30e1\u30bd\u30c3\u30c9\u3001<code>__index<\/code> \u306e\u7d39\u4ecb\u3067\u3057\u305f\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-8\">__newindex \u30e1\u30bf\u30e1\u30bd\u30c3\u30c9<\/h3>\n\n\n\n<p><code>__newindex<\/code> \u306f\u3001<code>__index<\/code> \u306e\u6b21\u306b\u4f7f\u7528\u983b\u5ea6\u304c\u591a\u3044\u3068\u3055\u308c\u3066\u3044\u308b\u30e1\u30bf\u30e1\u30bd\u30c3\u30c9\u3067\u3059\u3002<\/p>\n\n\n\n<p><code>__newindex<\/code>\u3092\u4f7f\u3048\u3070\u3001\u65b0\u3057\u3044\u30ad\u30fc\u3092\u8ffd\u52a0\u3057\u3088\u3046\u3068\u3057\u305f\u3068\u304d\u306b\u3001\u305d\u306e\u52d5\u4f5c\u3092\u30ab\u30b9\u30bf\u30de\u30a4\u30ba\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u3053\u306e\u30e1\u30bf\u30e1\u30bd\u30c3\u30c9\u306e\u4f7f\u7528\u65b9\u6cd5\u306f\u5c11\u3057\u7279\u6b8a\u3067\u3059\u3002\u4ee5\u4e0b\u306b\u4f8b\u3092\u793a\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"lua\" class=\"language-lua\">local myTable = {}\nlocal mt = {\n    __newindex = function(table, key, value)\n        print(\"Attempting to assign:\", key, \"=\", value)\n        rawset(table, key, value)  -- \u901a\u5e38\u306e\u30c6\u30fc\u30d6\u30eb\u306b\u66f8\u304d\u8fbc\u3080\u52d5\u4f5c\u3092\u5b9f\u884c\n    end\n}\nsetmetatable(myTable, mt)\n\nmyTable.newKey = \"Hello\"  -- \"Attempting to assign: newKey = Hello\" \u3068\u8868\u793a\u3055\u308c\u308b<\/code><\/pre>\n\n\n\n<p><code>__newindex<\/code> \u3067\u306f\u30013\u3064\u306e\u5f15\u6570\u304c\u6e21\u3055\u308c\u307e\u3059\u3002\u305d\u308c\u305e\u308c\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u306a\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n\n\n<div style=\"--sgb-list-icon-color: var(--sgb-main-color);--sgb-list-border-color: var(--sgb-main-color);\">\n<ul class=\"wp-block-list is-style-sango-list-check\">\n<li>\u66f8\u304d\u8fbc\u307f\u5bfe\u8c61\u306e\u30c6\u30fc\u30d6\u30eb (<code>table<\/code>)<\/li>\n\n\n\n<li>\u66f8\u304d\u8fbc\u307f\u5bfe\u8c61\u306e\u30ad\u30fc (<code>key<\/code>)<\/li>\n\n\n\n<li>\u305d\u306e\u30ad\u30fc\u306b\u5272\u308a\u5f53\u3066\u308b\u5024 (<code>value<\/code>)<\/li>\n<\/ul>\n<\/div>\n\n\n<p>\u4ed6\u306e\u30e1\u30bf\u30e1\u30bd\u30c3\u30c9\u3068\u7570\u306a\u308b\u6ce8\u610f\u70b9\u3068\u3057\u3066\u3001<code>return<\/code> \u306f\u4f7f\u7528\u305b\u305a\u306b\u3001<code>rawset()<\/code> \u3092\u4f7f\u7528\u3057\u3066\u30c6\u30fc\u30d6\u30eb\u306e\u64cd\u4f5c\u3092\u884c\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<p><code>rawset()<\/code> \u306f\u3001<code>__newindex<\/code> \u3092\u542b\u3080\u30e1\u30bf\u30e1\u30bd\u30c3\u30c9\u306e\u5f71\u97ff\u3092\u53d7\u3051\u305a\u306b\u3001\u6307\u5b9a\u3057\u305f\u30c6\u30fc\u30d6\u30eb\u306b\u6307\u5b9a\u3057\u305f\u30ad\u30fc\u3068\u5024\u306e\u30da\u30a2\u3092\u8ffd\u52a0\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u308b\u95a2\u6570\u3067\u3059\u3002<\/p>\n\n\n\n<p>\u3053\u308c\u306b\u3088\u308a\u3001<code>__newindex<\/code> \u306e\u7121\u9650\u30eb\u30fc\u30d7\u3092\u9632\u3050\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<code>rawset()<\/code> \u306f\u4ed6\u306e\u5834\u6240\u3067\u3082\u4f7f\u3046\u3053\u3068\u304c\u3042\u308b\u306e\u3067\u3001\u899a\u3048\u3066\u304a\u304d\u307e\u3057\u3087\u3046\u3002<\/p>\n\n\n\n<p><code>__newindex<\/code> \u3092\u6d3b\u7528\u3059\u308c\u3070\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u3053\u3068\u304c\u53ef\u80fd\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n\n\n<div style=\"--sgb-list-icon-color: var(--sgb-main-color);--sgb-list-border-color: var(--sgb-main-color);\">\n<ul class=\"wp-block-list is-style-sango-list-check\">\n<li>\u30c6\u30fc\u30d6\u30eb\u306b\u5bfe\u3057\u3066\u30ad\u30fc\u306e\u8ffd\u52a0\u3092\u9632\u3052\u308b<\/li>\n\n\n\n<li>\u5024\u3092\u30c1\u30a7\u30c3\u30af\u3057\u3066\u3001\u4e0d\u6b63\u306a\u5024\u3092\u6301\u3063\u305f\u30ad\u30fc\u306e\u8ffd\u52a0\u3092\u62d2\u5426\u3067\u304d\u308b<\/li>\n\n\n\n<li>\u305d\u306e\u4ed6\u3001\u5024\u306b\u5bfe\u3057\u3066\u6f14\u7b97\u3092\u9069\u7528\u3057\u3066\u304b\u3089\u30c6\u30fc\u30d6\u30eb\u306b\u633f\u5165\u3055\u305b\u305f\u308a\u3059\u308b\u3053\u3068\u304c\u53ef\u80fd\u306b<\/li>\n<\/ul>\n<\/div>\n\n\n<p>\u4f8b\u3048\u3070\u3001\u6570\u5024\u4ee5\u5916\u306e\u578b\u306e\u30c7\u30fc\u30bf\u3092\u30c6\u30fc\u30d6\u30eb\u306b\u633f\u5165\u3067\u304d\u306a\u304f\u3059\u308b\u3053\u3068\u304c\u53ef\u80fd\u3067\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"lua\" class=\"language-lua\">local myTable = {}\nlocal mt = {\n    __newindex = function(table, key, value)\n        if typeof(value) ~= \"number\" then\n            error(\"\u3053\u306e\u30c6\u30fc\u30d6\u30eb\u306b\u633f\u5165\u3067\u304d\u308b\u306e\u306f\u6570\u5024\u306e\u307f\u3067\u3059\u3002\")\n        end\n        rawset(table, key, value) -- \u5b9f\u969b\u306e\u30c6\u30fc\u30d6\u30eb\u306b\u5024\u3092\u8a2d\u5b9a\n    end\n}\n\nsetmetatable(myTable, mt)\n\nmyTable.a = 10 -- \u3053\u308c\u306f\u6210\u529f\u3059\u308b\nmyTable.b = \"string\" -- \u3053\u308c\u306f\u30a8\u30e9\u30fc\u306b\u306a\u308b<\/code><\/pre>\n\n\n\n<p><code>__newindex<\/code> \u306f\u5c11\u3057\u6271\u3044\u65b9\u304c\u7279\u6b8a\u3067\u3059\u304c\u3001\u3068\u3066\u3082\u4fbf\u5229\u306a\u30e1\u30bf\u30e1\u30bd\u30c3\u30c9\u306e1\u3064\u306a\u306e\u3067\u3001\u81ea\u8eab\u306e\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u306b\u5408\u308f\u305b\u3066\u4e0a\u624b\u304f\u6d3b\u7528\u3057\u3066\u307f\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-9\">__call \u30e1\u30bf\u30e1\u30bd\u30c3\u30c9<\/h3>\n\n\n\n<p><code>__call<\/code> \u30e1\u30bf\u30e1\u30bd\u30c3\u30c9\u3092\u4f7f\u3048\u3070\u3001\u30c6\u30fc\u30d6\u30eb\u3092\u95a2\u6570\u306e\u3088\u3046\u306b\u632f\u308b\u821e\u308f\u305b\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u30b3\u30fc\u30c9\u306e\u4f8b\u3092\u4ee5\u4e0b\u306b\u793a\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"lua\" class=\"language-lua\">local myTable = {}\nlocal mt = {\n    __call = function(table, arg1, arg2)\n        print(\"\u30c6\u30fc\u30d6\u30eb\u304c\u547c\u3073\u51fa\u3055\u308c\u307e\u3057\u305f\u3002\u5f15\u6570:\", arg1, arg2)\n    end\n}\nsetmetatable(myTable, mt)\n\nmyTable(10, 20)  -- \u51fa\u529b\u7d50\u679c: \"\u30c6\u30fc\u30d6\u30eb\u304c\u547c\u3073\u51fa\u3055\u308c\u307e\u3057\u305f\u3002\u5f15\u6570: 10 20\"<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-10\">__tostring \u30e1\u30bf\u30e1\u30bd\u30c3\u30c9<\/h3>\n\n\n\n<p><code>__tostring<\/code> \u30e1\u30bf\u30e1\u30bd\u30c3\u30c9\u306f\u3001\u30c6\u30fc\u30d6\u30eb\u304c\u6587\u5b57\u5217\u306b\u5909\u63db\u3055\u308c\u308b\u3068\u304d\u306b\u547c\u3073\u51fa\u3055\u308c\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u3064\u307e\u308a\u306f\u3001\u30c6\u30fc\u30d6\u30eb\u306b\u5bfe\u3057\u3066\u3001<code>tostring()<\/code> \u3084<code>print()<\/code> \u306a\u3069\u3092\u9069\u7528\u3057\u305f\u3068\u304d\u306e\u52d5\u4f5c\u3092\u30ab\u30b9\u30bf\u30de\u30a4\u30ba\u3067\u304d\u307e\u3059\u3002\u30c6\u30fc\u30d6\u30eb\u306e\u8868\u793a\u65b9\u6cd5\u3092\u30ab\u30b9\u30bf\u30de\u30a4\u30ba\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u4ee5\u4e0b\u306b\u30b3\u30fc\u30c9\u4f8b\u3092\u793a\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"lua\" class=\"language-lua\">local person = {\n    name = \"Alice\",\n    age = 30\n}\n\nlocal mt = {\n    __tostring = function(table)\n        return \"Name: \" .. table.name .. \", Age: \" .. table.age\n    end\n}\nsetmetatable(person, mt)\n\nprint(person)  -- \u51fa\u529b\u7d50\u679c: \"Name: Alice, Age: 30\"<\/code><\/pre>\n\n\n\n<p>\u6ce8\u610f\u70b9\u3068\u3057\u3066\u3001<code>__tostring<\/code> \u30e1\u30bf\u30e1\u30bd\u30c3\u30c9\u3067\u306f\u3001\u5fc5\u305a\u6587\u5b57\u5217\u3092\u8fd4\u3059\u3088\u3046\u306b\u3057\u3066\u304f\u3060\u3055\u3044\u3002\u3082\u3057\u4ed6\u306e\u30c7\u30fc\u30bf\u578b\u3092\u8fd4\u3059\u3068\u3001\u30a8\u30e9\u30fc\u304c\u767a\u751f\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<p><code>__tostring<\/code> \u3092\u4f7f\u3048\u3070\u3001\u3053\u306e\u3088\u3046\u306b\u3057\u3066\u30c6\u30fc\u30d6\u30eb\u306e\u51fa\u529b\u306a\u3069\u3092\u30ab\u30b9\u30bf\u30de\u30a4\u30ba\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u3053\u308c\u3067\u3001\u3088\u304f\u4f7f\u308f\u308c\u308b\u7279\u6b8a\u306a\u30e1\u30bf\u30e1\u30bd\u30c3\u30c9\u306e\u7d39\u4ecb\u306f\u4ee5\u4e0a\u3067\u3059\u3002\u4e0a\u624b\u304f\u4f7f\u3044\u3053\u306a\u3057\u3066\u30e1\u30bf\u30c6\u30fc\u30d6\u30eb\u3092\u30de\u30b9\u30bf\u30fc\u3057\u307e\u3057\u3087\u3046\uff01<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"i-11\">\u6700\u5f8c\u306b<\/h2>\n\n\n\n<p>\u3053\u306e\u8a18\u4e8b\u3067\u306f\u3001\u30e1\u30bf\u30c6\u30fc\u30d6\u30eb\u306e\u6271\u3044\u65b9\u306b\u3064\u3044\u3066\u7d39\u4ecb\u3057\u307e\u3057\u305f\u3002<\/p>\n\n\n\n<p>\u3053\u306e\u8a18\u4e8b\u306e\u5185\u5bb9\u3092\u7406\u89e3\u3059\u308c\u3070\u3001\u30c6\u30fc\u30d6\u30eb\u3092\u3088\u308a\u67d4\u8edf\u306b\u6d3b\u7528\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u308b\u306f\u305a\u3067\u3059\u3002<\/p>\n\n\n\n<p>\u6b21\u306e\u8a18\u4e8b\u3067\u306f\u3001\u3053\u306e\u30e1\u30bf\u30c6\u30fc\u30d6\u30eb\u3092\u4f7f\u3063\u3066\u3001\u72ec\u81ea\u306e\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u3092\u3064\u304f\u308b\u3053\u3068\u304c\u3067\u304d\u308bOOP\u624b\u6cd5\u306b\u3064\u3044\u3066\u7d39\u4ecb\u3057\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002\u5c11\u3057\u96e3\u3057\u3044\u3067\u3059\u304c\u3001\u305d\u308c\u3082\u304d\u3063\u3068\u5f79\u306b\u7acb\u3064\u306f\u305a\u3067\u3059\u3002\u305c\u3072\u304a\u697d\u3057\u307f\u306b\uff01<\/p>\n\n\n\n<p>\u305d\u308c\u3067\u306f\u3001\u4eca\u56de\u306f\u3053\u3053\u307e\u3067\u3002\u6700\u5f8c\u307e\u3067\u3054\u89a7\u3044\u305f\u3060\u304d\u3042\u308a\u304c\u3068\u3046\u3054\u3056\u3044\u307e\u3057\u305f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3053\u3093\u306b\u3061\u306f\uff01 \u3042\u306a\u305f\u306f\u3001\u300c\u30e1\u30bf\u30c6\u30fc\u30d6\u30eb\u300d\u3068\u3044\u3046\u8a00\u8449\u3092\u805e\u3044\u305f\u3053\u3068\u306f\u3042\u308a\u307e\u3059\u304b\uff1f \u300c\u30e1\u30bf\u30c6\u30fc\u30d6\u30eb\u3001\u805e\u3044\u305f\u3053\u3068\u306f\u3042\u308b\u3057\u3001\u4fbf\u5229\u3060\u3051\u3069\u3001\u306a\u3093\u3060\u304b\u96e3\u3057\u305d\u3046\u2026\u3002\u300d \u300c\u6d77\u5916\u306e\u89e3\u8aac\u52d5\u753b\u3092\u898b\u305f\u3051\u3069\u3001\u96e3\u3057\u304f\u3066\u632b\u6298\u3057\u305f\u2026\u3002\u300d \u305d\u3093\u306a\u65b9\u304c\u3053\u306e\u8a18\u4e8b &#8230; <\/p>\n","protected":false},"author":1,"featured_media":3836,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,58],"tags":[87,88,111],"class_list":{"0":"post-3333","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-tutorial","8":"category-script","9":"tag-robloxstudio","10":"tag-88","11":"tag-111","12":"entry"},"_links":{"self":[{"href":"https:\/\/roblog.jp\/studio\/wp-json\/wp\/v2\/posts\/3333","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/roblog.jp\/studio\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/roblog.jp\/studio\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/roblog.jp\/studio\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/roblog.jp\/studio\/wp-json\/wp\/v2\/comments?post=3333"}],"version-history":[{"count":14,"href":"https:\/\/roblog.jp\/studio\/wp-json\/wp\/v2\/posts\/3333\/revisions"}],"predecessor-version":[{"id":3840,"href":"https:\/\/roblog.jp\/studio\/wp-json\/wp\/v2\/posts\/3333\/revisions\/3840"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/roblog.jp\/studio\/wp-json\/wp\/v2\/media\/3836"}],"wp:attachment":[{"href":"https:\/\/roblog.jp\/studio\/wp-json\/wp\/v2\/media?parent=3333"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/roblog.jp\/studio\/wp-json\/wp\/v2\/categories?post=3333"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/roblog.jp\/studio\/wp-json\/wp\/v2\/tags?post=3333"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}