{"id":838,"date":"2017-08-22T13:17:07","date_gmt":"2017-08-22T12:17:07","guid":{"rendered":"https:\/\/solidt.eu\/site\/?p=838"},"modified":"2023-05-12T10:19:55","modified_gmt":"2023-05-12T09:19:55","slug":"lua-load-module-from-file","status":"publish","type":"post","link":"https:\/\/solidt.eu\/site\/lua-load-module-from-file\/","title":{"rendered":"Lua load module from file"},"content":{"rendered":"\n<div style=\"height: 250px; position:relative; margin-bottom: 50px;\" class=\"wp-block-simple-code-block-ace\"><pre class=\"wp-block-simple-code-block-ace\" style=\"position:absolute;top:0;right:0;bottom:0;left:0\" data-mode=\"lua\" data-theme=\"monokai\" data-fontsize=\"14\" data-lines=\"Infinity\" data-showlines=\"true\" data-copy=\"false\">local loadedModules = {}\nlocal function loadModule(name, unload)\n\tif (unload) then\n\t\tloadedModules[name] = nil\n\tend\n\n\tif loadedModules[name] then \n\t\treturn loadedModules[name] \n\tend\n\n\tlocal fileName = name .. '.lua'\n\tlocal moduleContent, err = loadfile(fileName)\n\tif (err) then\n\t\terror(string.format(\"error loading module: %s\\r\\n%s\", name, err), 2);\n\tend\n\tloadedModules[name] = moduleContent() or true\t\n\treturn loadedModules[name]\nend\n\nreturn loadModule<\/pre><\/div>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[9],"tags":[],"class_list":["post-838","post","type-post","status-publish","format-standard","hentry","category-lua"],"_links":{"self":[{"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/posts\/838","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/comments?post=838"}],"version-history":[{"count":2,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/posts\/838\/revisions"}],"predecessor-version":[{"id":7771,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/posts\/838\/revisions\/7771"}],"wp:attachment":[{"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/media?parent=838"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/categories?post=838"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/tags?post=838"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}