summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Pointner <equinox@spreadspace.org>2010-12-26 15:07:45 +0000
committerChristian Pointner <equinox@spreadspace.org>2010-12-26 15:07:45 +0000
commita021cac4bd1000ecce951c576c31535f672773a5 (patch)
tree59edd18643ebb2d924f7fae74bebf90db02a26a2
parentupdated TODO (diff)
removed crapy require from module loader
git-svn-id: https://svn.spreadspace.org/gcsd/trunk@72 ac14a137-c7f1-4531-abe0-07747231d213
-rw-r--r--TODO2
-rw-r--r--src/module_list.lua12
2 files changed, 8 insertions, 6 deletions
diff --git a/TODO b/TODO
index 04ef741..67387a1 100644
--- a/TODO
+++ b/TODO
@@ -2,7 +2,7 @@
* out-of-order responses
* finish API for command & response dispatch tables
* add listener tables (for requests, responses and other messages)
- * module loader cleanup (no require)
+ * improve module loader (configurable path)
* module API etc. clean-up, finalize, freeze
* config-parser
* check max instances at modules (instance counter)
diff --git a/src/module_list.lua b/src/module_list.lua
index eb12b1f..5ddb845 100644
--- a/src/module_list.lua
+++ b/src/module_list.lua
@@ -35,6 +35,7 @@ local defines = require("defines")
module_list = {}
module_list.classes = {}
+module_list.classes.__path = "./modules"
local mt = {}
function mt.__index(table, key)
local value = rawget(table, key)
@@ -42,11 +43,12 @@ function mt.__index(table, key)
log.printf(log.DEBUG, "load module class: %s", key)
- local old_path = package.path
- package.path = package.path .. ";./modules/?.lua"
- value = require(key)
- package.path = old_path
-
+ local filename = table.__path .. "/" .. key .. ".lua"
+ local chunk, err = loadfile(filename)
+ if (not chunk) then
+ error("failed to load module: " .. err)
+ end
+ value = chunk()
rawset(table, key, value)
return value
end