{"id":340,"date":"2018-06-14T17:29:51","date_gmt":"2018-06-14T14:29:51","guid":{"rendered":"http:\/\/www.scozturk.com\/?p=340"},"modified":"2025-08-29T10:44:58","modified_gmt":"2025-08-29T10:44:58","slug":"c-programlarinda-lua-scriptleri-kullanmak-2","status":"publish","type":"post","link":"http:\/\/18.193.70.38\/?p=340&lang=tr","title":{"rendered":"C# Programlar\u0131nda Lua Scriptleri Kullanmak \u2013 2"},"content":{"rendered":"<p><em><strong>1- Giri\u015f<\/strong><\/em><br \/>\nBir \u00f6nceki yaz\u0131mda <em>&#8220;C# Programlar\u0131nda Lua Scriptleri Kullanmak \u2013 1&#8221;<\/em> \u00e7ok temel bi\u00e7imde Lua&#8217;n\u0131n C#&#8217;dan kullan\u0131m\u0131, C#&#8217;dan Lua beti\u011fine parametreler g\u00f6nderme ve Lua beti\u011finden C# koduna eri\u015fimle ilgili \u00f6rnekler g\u00f6sterdim. Bu yaz\u0131mda ise \u00e7ok daha i\u015fe yarar bi\u00e7imde bir <em>C# Windows Form<\/em> yaz\u0131l\u0131m\u0131n\u0131n Lua betikleri ile entegre edilip nas\u0131l parametrik\/dinamik hale getirilebilece\u011fini g\u00f6sterece\u011fim.<\/p>\n<p><em><strong>2- C# Kodlar\u0131<\/strong><\/em><br \/>\nC# kodumuz a\u015fa\u011f\u0131daki gibidir:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n\/\/ Lua scriptleme nesnesi olu\u015ftur\nLua script = new Lua();\n \n\/\/ CLR'i Y\u00fckleyelim\nscript.LoadCLRPackage();\n\n\/\/ Formu Lua'ya belirtelim\nscript&#x5B;&quot;formNesnesi&quot;] = this;\n\n\/\/ Buton bas\u0131l\u0131nca \u00e7a\u011f\u0131r\u0131lacak metodumuzu tan\u0131mlayal\u0131m\nMethodInfo testMetodu = this.GetType().GetMethod(&quot;_testMetodu&quot;, BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.DeclaredOnly | BindingFlags.Instance, null, new Type&#x5B;] {typeof(int),typeof(int)}, null);\n\n\/\/ Metodu Lua'ya kaydedelim\nscript.RegisterFunction(&quot;testMetodu&quot;, this, testMetodu);\n\n\/\/ Dosyadan Lua scriptini \u00e7al\u0131\u015ft\u0131r\nscript.DoFile(&quot;test5.lua&quot;);\n<\/pre>\n<p><em>&#8220;LoadCLRPackage()&#8221;<\/em> ile CLR paketini script alt yap\u0131s\u0131na y\u00fckl\u00fcyoruz, bu paket .Net framework&#8217;\u00fcne Lua&#8217;n\u0131n eri\u015fmesi i\u00e7in gerekmektedir.<\/p>\n<p><em>&#8220;MethodInfo&#8221;<\/em> ile ba\u015flayan sat\u0131rda temel olarak C# metodumuzu Lua&#8217;ya ba\u011flayabilmek i\u00e7in gereken \u00f6n \u00e7al\u0131\u015fma olan metod g\u00f6stergecini alma i\u015flemini yap\u0131yoruz. Temel olarak burada <em>&#8220;_testMetodu&#8221;<\/em> ad\u0131nda ve 2 adet int tipinde parametresi olan bir metodun g\u00f6stergeci\/pointer\u0131 al\u0131yoruz. <\/p>\n<p>Akabinde alt\u0131ndaki sat\u0131rdaki <em>&#8220;RegisterFunction&#8221;<\/em> metoduyla metodumuzu Lua scriptimize ekliyoruz. Bundan sonra asl\u0131nda bu metodu Lua&#8217;dan do\u011frudan \u00e7a\u011f\u0131rabilece\u011fiz.<\/p>\n<p>Di\u011fer kodlar bir \u00f6nceki yaz\u0131da g\u00f6rd\u00fc\u011f\u00fcm\u00fcz kodlar. Methodumuzu da bir yerde tan\u0131mlamay\u0131 unutmayal\u0131m:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nprivate void _testMetodu(int a, int b)\n{\n            MessageBox.Show(&quot;Merhaba! Toplam=&quot;+(a+b).ToString());\n}\n<\/pre>\n<p>Bu C# metodu ile verilen 2 <em>integer<\/em> de\u011feri toplay\u0131p <em>MessageBox<\/em> i\u00e7erisinde g\u00f6steriyoruz.<\/p>\n<p><em><strong>3- Lua Beti\u011fi<\/strong><\/em><br \/>\nLua beti\u011fimiz a\u015fa\u011f\u0131daki \u015fekildedir, <em>&#8220;test5.lua&#8221;<\/em> olarak kaydedelim.<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n-- Gerekli bile\u015fenleri y\u00fckle\nimport(&quot;System.Windows.Forms&quot;)\nimport(&quot;System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a&quot;)\nimport(&quot;System.Drawing&quot;)\nForms = CLRPackage(&quot;System.Windows.Forms&quot;, &quot;System.Windows.Forms&quot;)\nDrawing = CLRPackage(&quot;System.Drawing&quot;, &quot;System.Drawing&quot;)\n\n-- .Net Nesne Tan\u0131mlar\u0131n\u0131 LUA'ya \u00c7ekelim\nForm=Forms.Form\nButton=Forms.Button\nTextBox=Forms.TextBox\nLabel=Forms.Label\nPoint=Drawing.Point\nSize=Drawing.Size\n\n-- Button Bas\u0131ld\u0131\u011f\u0131nda \u00c7a\u011f\u0131r\u0131lacak Fonksiyon\nfunction yeniButton_Click(sender,data)\n\t-- C# s\u0131n\u0131f\u0131m\u0131zdaki metodu \u00e7a\u011f\u0131ral\u0131m\n\ttestMetodu(3,5)\nend\n\n-- Button olu\u015ftural\u0131m\nyeniButton=Button()\nyeniButton.Text = &quot;Button \u00d6rne\u011fi&quot;\nyeniButton.Location = Point(220, 0)\nyeniButton.Name = &quot;yeniButton&quot;\nyeniButton.Size = Size(100, 20)\nhandler=yeniButton.MouseUp:Add(yeniButton_Click)\n\n-- Textbox olu\u015ftural\u0131m\nyeniTextBox=TextBox()\nyeniTextBox.Text = &quot;TextBox \u00d6rne\u011fi&quot;\nyeniTextBox.Location = Point(110, 0)\nyeniTextBox.Name = &quot;yeniTextBox&quot;\nyeniTextBox.Size = Size(100, 20)\n\n-- Label olu\u015ftural\u0131m\nyeniLabel=Label()\nyeniLabel.Text = &quot;Label \u00d6rne\u011fi&quot;\nyeniLabel.Location = Point(0, 0)\nyeniLabel.Name = &quot;yeniLabel&quot;\nyeniLabel.Size = Size(100, 20)\n\n-- Nesneleri formumuza ekleyelim\nformNesnesi.Controls:Add(yeniButton) \nformNesnesi.Controls:Add(yeniTextBox) \nformNesnesi.Controls:Add(yeniLabel)\n<\/pre>\n<p>Lua beti\u011finde \u00e7ok \u00f6zel bir kod yok, genel olarak standart Lua kodlar\u0131ndan olu\u015fuyor. <em>&#8220;formNesnesi&#8221;<\/em> bizim C# kodumuzdan Lua scriptine bildirdi\u011fimiz <em>Form<\/em> nesnemiz. Lua i\u00e7erisinden <em>Button\/Label\/TextBox<\/em> olu\u015fturup Form nesnemize ekliyoruz. <em>Button<\/em> nesnemizi olu\u015ftururken ek olarak <em>&#8220;yeniButton_Click&#8221;<\/em> Lua metodunu fareye t\u0131klama olay\u0131na ba\u011fl\u0131yoruz. C# kodumuzdan ba\u011flad\u0131\u011f\u0131m\u0131z <em>&#8220;testMetodu&#8221;<\/em> metodunu da Lua beti\u011fimizden normal bir bi\u00e7imde \u00e7a\u011f\u0131r\u0131yoruz.<\/p>\n<p><em><strong>4- Sonu\u00e7<\/strong><\/em><br \/>\nBu yaz\u0131da C# ve Lua&#8217;y\u0131 olduk\u00e7a yak\u0131ndan entegre etmenin y\u00f6ntemlerini g\u00f6rd\u00fck. Umar\u0131m i\u015finize yarar, iyi kodlamalar. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>1- Giri\u015f Bir \u00f6nceki yaz\u0131mda &#8220;C# Programlar\u0131nda Lua Scriptleri Kullanmak \u2013 1&#8221; \u00e7ok temel bi\u00e7imde Lua&#8217;n\u0131n C#&#8217;dan kullan\u0131m\u0131, C#&#8217;dan Lua beti\u011fine parametreler g\u00f6nderme ve Lua beti\u011finden C# koduna&#8230;<\/p>\n","protected":false},"author":1,"featured_media":341,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[265,267],"tags":[269,271,273,275,277,279,281,283,285],"class_list":["post-340","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-c-tr-tr","category-lua-tr","tag-betik-tr","tag-betikleme-tr","tag-c-tr","tag-fonksiyon-tr","tag-lua-tr","tag-metod-tr","tag-nlua-tr","tag-scripting-tr","tag-scriptleme-tr"],"_links":{"self":[{"href":"http:\/\/18.193.70.38\/index.php?rest_route=\/wp\/v2\/posts\/340","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/18.193.70.38\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/18.193.70.38\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/18.193.70.38\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/18.193.70.38\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=340"}],"version-history":[{"count":1,"href":"http:\/\/18.193.70.38\/index.php?rest_route=\/wp\/v2\/posts\/340\/revisions"}],"predecessor-version":[{"id":1207,"href":"http:\/\/18.193.70.38\/index.php?rest_route=\/wp\/v2\/posts\/340\/revisions\/1207"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/18.193.70.38\/index.php?rest_route=\/wp\/v2\/media\/341"}],"wp:attachment":[{"href":"http:\/\/18.193.70.38\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=340"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/18.193.70.38\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=340"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/18.193.70.38\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=340"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}