From 686ba42466ca46f9e49f13d45ae9a225aa2dbe51 Mon Sep 17 00:00:00 2001 From: Miodrag Milanovic Date: Sun, 14 Feb 2016 19:48:44 +0100 Subject: [PATCH] Added plugin info json files and made system automatically load available plugins and start them if flagged so (nw) --- plugins/boot.lua | 38 ++++++++++++++--------------- plugins/coro-channel/plugin.json | 8 ++++++ plugins/coro-fs/plugin.json | 8 ++++++ plugins/coro-http/plugin.json | 8 ++++++ plugins/coro-net/plugin.json | 8 ++++++ plugins/coro-tls/plugin.json | 8 ++++++ plugins/coro-wrapper/plugin.json | 8 ++++++ plugins/dummy/init.lua | 20 +++++++++++++++ plugins/dummy/plugin.json | 9 +++++++ plugins/http-codec/plugin.json | 8 ++++++ plugins/json/plugin.json | 8 ++++++ plugins/mime/plugin.json | 8 ++++++ plugins/path/plugin.json | 8 ++++++ plugins/pretty-print/plugin.json | 8 ++++++ plugins/querystring/plugin.json | 8 ++++++ plugins/weblit/plugin.json | 8 ++++++ plugins/webserver/init.lua | 34 ++++++++++++++++++++++++++ plugins/webserver/plugin.json | 9 +++++++ plugins/websocket-codec/plugin.json | 8 ++++++ 19 files changed, 202 insertions(+), 20 deletions(-) create mode 100644 plugins/coro-channel/plugin.json create mode 100644 plugins/coro-fs/plugin.json create mode 100644 plugins/coro-http/plugin.json create mode 100644 plugins/coro-net/plugin.json create mode 100644 plugins/coro-tls/plugin.json create mode 100644 plugins/coro-wrapper/plugin.json create mode 100644 plugins/dummy/init.lua create mode 100644 plugins/dummy/plugin.json create mode 100644 plugins/http-codec/plugin.json create mode 100644 plugins/json/plugin.json create mode 100644 plugins/mime/plugin.json create mode 100644 plugins/path/plugin.json create mode 100644 plugins/pretty-print/plugin.json create mode 100644 plugins/querystring/plugin.json create mode 100644 plugins/weblit/plugin.json create mode 100644 plugins/webserver/init.lua create mode 100644 plugins/webserver/plugin.json create mode 100644 plugins/websocket-codec/plugin.json 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 diff --git a/plugins/coro-channel/plugin.json b/plugins/coro-channel/plugin.json new file mode 100644 index 00000000000..5a3f5af8813 --- /dev/null +++ b/plugins/coro-channel/plugin.json @@ -0,0 +1,8 @@ +{ + "plugin": { + "name": "coro-channel", + "version": "1.2.0", + "author": "Tim Caswell", + "type": "library", + } +} \ No newline at end of file diff --git a/plugins/coro-fs/plugin.json b/plugins/coro-fs/plugin.json new file mode 100644 index 00000000000..c35d9e27315 --- /dev/null +++ b/plugins/coro-fs/plugin.json @@ -0,0 +1,8 @@ +{ + "plugin": { + "name": "coro-fs", + "version": "1.3.0", + "author": "Tim Caswell", + "type": "library", + } +} \ No newline at end of file diff --git a/plugins/coro-http/plugin.json b/plugins/coro-http/plugin.json new file mode 100644 index 00000000000..0c8047c9ebe --- /dev/null +++ b/plugins/coro-http/plugin.json @@ -0,0 +1,8 @@ +{ + "plugin": { + "name": "coro-http", + "version": "1.2.1-1", + "author": "Tim Caswell", + "type": "library", + } +} \ No newline at end of file diff --git a/plugins/coro-net/plugin.json b/plugins/coro-net/plugin.json new file mode 100644 index 00000000000..cf839aad881 --- /dev/null +++ b/plugins/coro-net/plugin.json @@ -0,0 +1,8 @@ +{ + "plugin": { + "name": "coro-net", + "version": "1.1.1-1", + "author": "Tim Caswell", + "type": "library", + } +} \ No newline at end of file diff --git a/plugins/coro-tls/plugin.json b/plugins/coro-tls/plugin.json new file mode 100644 index 00000000000..257224e2ea3 --- /dev/null +++ b/plugins/coro-tls/plugin.json @@ -0,0 +1,8 @@ +{ + "plugin": { + "name": "coro-tls", + "version": "1.2.1", + "author": "Tim Caswell", + "type": "library", + } +} \ No newline at end of file diff --git a/plugins/coro-wrapper/plugin.json b/plugins/coro-wrapper/plugin.json new file mode 100644 index 00000000000..6075edba1fa --- /dev/null +++ b/plugins/coro-wrapper/plugin.json @@ -0,0 +1,8 @@ +{ + "plugin": { + "name": "coro-wrapper", + "version": "1.0.0-1", + "author": "Tim Caswell", + "type": "library", + } +} \ No newline at end of file diff --git a/plugins/dummy/init.lua b/plugins/dummy/init.lua new file mode 100644 index 00000000000..8c4fbe6a0f5 --- /dev/null +++ b/plugins/dummy/init.lua @@ -0,0 +1,20 @@ +local exports = {} +exports.name = "dummy" +exports.version = "0.0.1" +exports.description = "A dummy example" +exports.license = "MIT" +exports.author = { name = "Miodrag Milanovic" } + +local dummy = exports + +function dummy.startplugin() + emu.register_start(function() + print("Starting " .. emu.gamename()) + end) + + emu.register_stop(function() + print("Exiting " .. emu.gamename()) + end) +end + +return exports diff --git a/plugins/dummy/plugin.json b/plugins/dummy/plugin.json new file mode 100644 index 00000000000..4d877fa4dfa --- /dev/null +++ b/plugins/dummy/plugin.json @@ -0,0 +1,9 @@ +{ + "plugin": { + "name": "dummy", + "version": "0.0.1", + "author": "Miodrag Milanovic", + "type": "plugin", + "start": "false", + } +} \ No newline at end of file diff --git a/plugins/http-codec/plugin.json b/plugins/http-codec/plugin.json new file mode 100644 index 00000000000..ce511afa785 --- /dev/null +++ b/plugins/http-codec/plugin.json @@ -0,0 +1,8 @@ +{ + "plugin": { + "name": "http-codec", + "version": "1.0.0-1", + "author": "Tim Caswell", + "type": "library", + } +} \ No newline at end of file diff --git a/plugins/json/plugin.json b/plugins/json/plugin.json new file mode 100644 index 00000000000..c5a0c77355d --- /dev/null +++ b/plugins/json/plugin.json @@ -0,0 +1,8 @@ +{ + "plugin": { + "name": "json", + "version": "2.5.0", + "author": "David Kolf", + "type": "library", + } +} \ No newline at end of file diff --git a/plugins/mime/plugin.json b/plugins/mime/plugin.json new file mode 100644 index 00000000000..ee55fd559b3 --- /dev/null +++ b/plugins/mime/plugin.json @@ -0,0 +1,8 @@ +{ + "plugin": { + "name": "mime", + "version": "0.1.2-1", + "author": "Tim Caswell", + "type": "library", + } +} \ No newline at end of file diff --git a/plugins/path/plugin.json b/plugins/path/plugin.json new file mode 100644 index 00000000000..c88de67d77c --- /dev/null +++ b/plugins/path/plugin.json @@ -0,0 +1,8 @@ +{ + "plugin": { + "name": "path", + "version": "1.0.0", + "author": "Tim Caswell", + "type": "library", + } +} \ No newline at end of file diff --git a/plugins/pretty-print/plugin.json b/plugins/pretty-print/plugin.json new file mode 100644 index 00000000000..556608c8dd6 --- /dev/null +++ b/plugins/pretty-print/plugin.json @@ -0,0 +1,8 @@ +{ + "plugin": { + "name": "pretty-print", + "version": "1.0.3", + "author": "Tim Caswell", + "type": "library", + } +} \ No newline at end of file diff --git a/plugins/querystring/plugin.json b/plugins/querystring/plugin.json new file mode 100644 index 00000000000..ddd3cc4291e --- /dev/null +++ b/plugins/querystring/plugin.json @@ -0,0 +1,8 @@ +{ + "plugin": { + "name": "querystring", + "version": "1.0.2", + "author": "Tim Caswell", + "type": "library", + } +} \ No newline at end of file diff --git a/plugins/weblit/plugin.json b/plugins/weblit/plugin.json new file mode 100644 index 00000000000..69dd45ccc0e --- /dev/null +++ b/plugins/weblit/plugin.json @@ -0,0 +1,8 @@ +{ + "plugin": { + "name": "weblit", + "version": "1.0.0", + "author": "Tim Caswell", + "type": "library", + } +} \ No newline at end of file diff --git a/plugins/webserver/init.lua b/plugins/webserver/init.lua new file mode 100644 index 00000000000..3d68b01e6d5 --- /dev/null +++ b/plugins/webserver/init.lua @@ -0,0 +1,34 @@ +local exports = {} +exports.name = "webserver" +exports.version = "1.0.0" +exports.description = "A simple web server" +exports.license = "MIT" +exports.author = { name = "Miodrag Milanovic" } + +local ws = exports + +local app = require('weblit/app') + +function ws.startplugin() + app.bind({ + host = "0.0.0.0", + port = 8080 + }) + + app.use(require('weblit/logger')) + app.use(require('weblit/auto-headers')) + app.use(require('weblit/etag-cache')) + + app.route({ + method = "GET", + path = "/", + }, function (req, res, go) + res.code = 200 + res.headers["Content-Type"] = "text/html" + res.body = "

Hello!

\n" + end) + + app.start() +end + +return exports diff --git a/plugins/webserver/plugin.json b/plugins/webserver/plugin.json new file mode 100644 index 00000000000..e420a5d5485 --- /dev/null +++ b/plugins/webserver/plugin.json @@ -0,0 +1,9 @@ +{ + "plugin": { + "name": "webserver", + "version": "1.0.0", + "author": "Miodrag Milanovic", + "type": "plugin", + "start": "false", + } +} \ No newline at end of file diff --git a/plugins/websocket-codec/plugin.json b/plugins/websocket-codec/plugin.json new file mode 100644 index 00000000000..00a49dbcba3 --- /dev/null +++ b/plugins/websocket-codec/plugin.json @@ -0,0 +1,8 @@ +{ + "plugin": { + "name": "websocket-codec", + "version": "1.0.7", + "author": "Tim Caswell", + "type": "library", + } +} \ No newline at end of file