From 686ba42466ca46f9e49f13d45ae9a225aa2dbe51 Mon Sep 17 00:00:00 2001 From: Miodrag Milanovic Date: Sun, 14 Feb 2016 19:48:44 +0100 Subject: Added plugin info json files and made system automatically load available plugins and start them if flagged so (nw) --- plugins/boot.lua | 38 ++++++++++++++++++-------------------- 1 file changed, 18 insertions(+), 20 deletions(-) (limited to 'plugins/boot.lua') diff --git a/plugins/boot.lua b/plugins/boot.lua index e6cdde58004..4f8c6a0ee96 100644 --- a/plugins/boot.lua +++ b/plugins/boot.lua @@ -1,26 +1,24 @@ +require('lfs') local uv = require('luv') local cwd = uv.cwd() package.path = cwd .. "/plugins/?.lua;" .. cwd .. "/plugins/?/init.lua" -require('weblit/app') +local json = require('json') +function readAll(file) + local f = io.open(file, "rb") + local content = f:read("*all") + f:close() + return content +end - .bind({ - host = "0.0.0.0", - port = 8080 - }) - - .use(require('weblit/logger')) - .use(require('weblit/auto-headers')) - .use(require('weblit/etag-cache')) - - .route({ - method = "GET", - path = "/", - }, function (req, res, go) - res.code = 200 - res.headers["Content-Type"] = "text/html" - res.body = "

Hello!

\n" - end) - - .start() +for file in lfs.dir("plugins") do + if (file~="." and file~=".." and lfs.attributes("plugins/" .. file,"mode")=="directory") then + local filename = "plugins/" .. file .. "/plugin.json" + local meta = json.parse(readAll(filename)) + if (meta["plugin"]["type"]=="plugin") and (meta["plugin"]["start"]=="true") then + server = require(meta["plugin"]["name"]) + server.startplugin(); + end + end +end -- cgit v1.2.3-70-g09d2