summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnthony Zhang <azhang9@gmail.com>2013-03-20 17:31:00 -0400
committerAnthony Zhang <azhang9@gmail.com>2013-03-20 17:31:00 -0400
commit65c218c3e2b6fbac804af6b04b633574a64e5d9c (patch)
treeeae5aabdda35bd330972c6fa8d1ba7e4494a693c
parentd1828affffb332dceb0665753a4b6c1cb151df5b (diff)
Dynamic module loading - you can now delete any file in the worldedit mod except init.lua, and the relevant functionality will simply not be included.
-rw-r--r--WorldEdit API.md2
-rw-r--r--worldedit/compatibility.lua2
-rw-r--r--worldedit/init.lua19
3 files changed, 17 insertions, 6 deletions
diff --git a/WorldEdit API.md b/WorldEdit API.md
index 464a719..a69062f 100644
--- a/WorldEdit API.md
+++ b/WorldEdit API.md
@@ -2,6 +2,8 @@ WorldEdit API
=============
The WorldEdit API is composed of multiple modules, each of which is independent and can be used without the other. Each module is contained within a single file.
+If needed, individual modules such as visualization.lua can be removed without affecting the rest of the program. The only file that cannot be removed is init.lua, which is necessary for the mod to run.
+
For more information, see the [README](README.md).
Manipulations
diff --git a/worldedit/compatibility.lua b/worldedit/compatibility.lua
index 3b9c889..0ea2333 100644
--- a/worldedit/compatibility.lua
+++ b/worldedit/compatibility.lua
@@ -1,3 +1,5 @@
+worldedit = worldedit or {}
+
worldedit.allocate_old = worldedit.allocate
worldedit.deserialize_old = worldedit.deserialize
worldedit.metasave = function(pos1, pos2, filename)
diff --git a/worldedit/init.lua b/worldedit/init.lua
index aaf70ae..f3eb9bb 100644
--- a/worldedit/init.lua
+++ b/worldedit/init.lua
@@ -1,7 +1,14 @@
local path = minetest.get_modpath("worldedit")
-dofile(path .. "/manipulations.lua")
-dofile(path .. "/primitives.lua")
-dofile(path .. "/visualization.lua")
-dofile(path .. "/serialization.lua")
-dofile(path .. "/code.lua")
-dofile(path .. "/compatibility.lua") \ No newline at end of file
+
+local loadmodule = function(path)
+ return pcall(function()
+ dofile(path)
+ end)
+end
+
+loadmodule(path .. "/manipulations.lua")
+loadmodule(path .. "/primitives.lua")
+loadmodule(path .. "/visualization.lua")
+loadmodule(path .. "/serialization.lua")
+loadmodule(path .. "/code.lua")
+loadmodule(path .. "/compatibility.lua") \ No newline at end of file