summaryrefslogtreecommitdiff
path: root/apps/plugins/lua/include_lua/temploader.lua
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/lua/include_lua/temploader.lua')
-rw-r--r--apps/plugins/lua/include_lua/temploader.lua30
1 files changed, 30 insertions, 0 deletions
diff --git a/apps/plugins/lua/include_lua/temploader.lua b/apps/plugins/lua/include_lua/temploader.lua
new file mode 100644
index 0000000000..69eae468a8
--- /dev/null
+++ b/apps/plugins/lua/include_lua/temploader.lua
@@ -0,0 +1,30 @@
1--[[
2temp loader allows some lua requires to be loaded and later garbage collected
3unfortunately the module needs to be formatted in such a way to pass back a
4call table in order to keep the functions within from being garbage collected
5too early
6
7BE AWARE this bypasses the module loader which would allow code reuse
8so if you aren't careful this memory saving tool could spell disaster
9for free RAM if you load the same code multiple times
10--]]
11
12
13local function tempload(modulename)
14 --http://lua-users.org/wiki/LuaModulesLoader
15 local errmsg = ""
16 -- Find source
17 local modulepath = string.gsub(modulename, "%.", "/")
18 for path in string.gmatch(package.path, "([^;]+)") do
19 local filename = string.gsub(path, "%?", modulepath)
20 local file = io.open(filename, "r")
21 if file then
22 -- Compile and return the module
23 return assert(loadstring(assert(file:read("*a")), filename))()
24 end
25 errmsg = errmsg.."\n\tno file '"..filename.."' (temp loader)"
26 end
27 return errmsg
28end
29
30return tempload