{"id":246,"date":"2024-10-01T13:32:35","date_gmt":"2024-10-01T12:32:35","guid":{"rendered":"http:\/\/monkey.ploogie.co.uk\/?page_id=246"},"modified":"2024-10-02T04:22:10","modified_gmt":"2024-10-02T03:22:10","slug":"mwnci-includes","status":"publish","type":"page","link":"https:\/\/monkey.ploogie.co.uk\/index.php\/mwnci-includes\/","title":{"rendered":"Mwnci Includes"},"content":{"rendered":"<h2>What is an include?<\/h2>\n<p>It&#8217;s quite simply a file containing <em>Mwnci <\/em>code with functions and\/or variable definitions that may be useful in other scripts<\/p>\n<h2>Creating an include<\/h2>\n<p>To create an include just save the code you want in a file with the file extension\u00a0<em>.mwnci<\/em><\/p>\n<p>Save the below code as <strong><em>greeting.mwnci<\/em><\/strong><\/p>\n<pre>function hello(Name) {\r\n    println(\"Hello \", Name)\r\n}<\/pre>\n<h2>Using the include<\/h2>\n<p>Now we can use the include we just created, by using the <em>include<\/em> command:<\/p>\n<pre>include(\"greeting\")\r\nhello(\"Nobby\")\r\n\r\n\r\nHello Nobby\r\n\r\n<\/pre>\n<h2>Contents of an include<\/h2>\n<p>Includes can contain functions, as already described, but also variables of all types (arrays, hashes) etc.<\/p>\n<p>If we add this to the file <em>greeting.mwnci<\/em><\/p>\n<pre>MyHash={\r\n    \"Age\": 45,\r\n    \"Toes\": 10\r\n}<\/pre>\n<p>And if we run:<\/p>\n<pre>include(\"greeting\")\r\nhello(\"Nobby\")\r\nprintln(\"You have \", MyHash[\"Toes\"], \" toes\"\r\n\r\n\r\nHello Nobby\r\nYou have 10 toes\r\n\r\n<\/pre>\n<p>There are several built-in includes, which can be used at any time.<\/p>\n<p>The files are searched via a &#8216;SearchPath&#8217; which is controlled by the environment variable <b>INCLUDEPATH<\/b>. The default path is configured prior to compiling mwnci, such as \/usr\/local\/include\/mwnci. The current directory is searched after \/usr\/local\/include\/mwnci.<\/p>\n<p>INCLUDEPATH is a colon (:) separated path that is searched prior to the default path.<\/p>\n<p>if INCLUDEPATH is defined as &#8220;\/home\/detritus\/include&#8221;, then at run time for the mwnci script it is set to:<\/p>\n<pre>\/home\/detritus\/include:\/usr\/local\/include\/mwnci:.<\/pre>\n<p>You can also import multiple files:<\/p>\n<pre>include(\r\n     \"foo\",\r\n     \"bar\",\r\n     \"wibble\"\r\n)\r\n<\/pre>\n<p>Or if you prefer:<\/p>\n<pre>include(\"foo\")\r\ninclude(\"bar\")\r\ninclude(\"wibble\")<\/pre>\n<p>For &#8216;foo&#8217; to be included, the file foo.mwnci must reside in \/home\/detritus\/include, or \/usr\/local\/include\/mwnci or your current directory.<\/p>\n<p>If you have files of the same name in more than one directory, then only the first found will be used. The file <em>main.mwnci<\/em> is auto included at script run time.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>What is an include? It&#8217;s quite simply a file containing Mwnci code with functions and\/or variable definitions that may be useful in other scripts Creating an include To create an include just save the code you want in a file with the file extension\u00a0.mwnci Save the below code as greeting.mwnci function hello(Name) { println(&#8220;Hello &#8220;, &hellip; <a href=\"https:\/\/monkey.ploogie.co.uk\/index.php\/mwnci-includes\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Mwnci Includes&#8221;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-246","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/monkey.ploogie.co.uk\/index.php\/wp-json\/wp\/v2\/pages\/246","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/monkey.ploogie.co.uk\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/monkey.ploogie.co.uk\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/monkey.ploogie.co.uk\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/monkey.ploogie.co.uk\/index.php\/wp-json\/wp\/v2\/comments?post=246"}],"version-history":[{"count":7,"href":"https:\/\/monkey.ploogie.co.uk\/index.php\/wp-json\/wp\/v2\/pages\/246\/revisions"}],"predecessor-version":[{"id":258,"href":"https:\/\/monkey.ploogie.co.uk\/index.php\/wp-json\/wp\/v2\/pages\/246\/revisions\/258"}],"wp:attachment":[{"href":"https:\/\/monkey.ploogie.co.uk\/index.php\/wp-json\/wp\/v2\/media?parent=246"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}