Added plugin info json files and made system automatically load available plugins and start them if flagged so (nw)

This commit is contained in:
Miodrag Milanovic 2016-02-14 19:48:44 +01:00
parent 5a31d8513b
commit 686ba42466
19 changed files with 202 additions and 20 deletions

View file

@ -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 = "<h1>Hello!</h1>\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

View file

@ -0,0 +1,8 @@
{
"plugin": {
"name": "coro-channel",
"version": "1.2.0",
"author": "Tim Caswell",
"type": "library",
}
}

View file

@ -0,0 +1,8 @@
{
"plugin": {
"name": "coro-fs",
"version": "1.3.0",
"author": "Tim Caswell",
"type": "library",
}
}

View file

@ -0,0 +1,8 @@
{
"plugin": {
"name": "coro-http",
"version": "1.2.1-1",
"author": "Tim Caswell",
"type": "library",
}
}

View file

@ -0,0 +1,8 @@
{
"plugin": {
"name": "coro-net",
"version": "1.1.1-1",
"author": "Tim Caswell",
"type": "library",
}
}

View file

@ -0,0 +1,8 @@
{
"plugin": {
"name": "coro-tls",
"version": "1.2.1",
"author": "Tim Caswell",
"type": "library",
}
}

View file

@ -0,0 +1,8 @@
{
"plugin": {
"name": "coro-wrapper",
"version": "1.0.0-1",
"author": "Tim Caswell",
"type": "library",
}
}

20
plugins/dummy/init.lua Normal file
View file

@ -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

View file

@ -0,0 +1,9 @@
{
"plugin": {
"name": "dummy",
"version": "0.0.1",
"author": "Miodrag Milanovic",
"type": "plugin",
"start": "false",
}
}

View file

@ -0,0 +1,8 @@
{
"plugin": {
"name": "http-codec",
"version": "1.0.0-1",
"author": "Tim Caswell",
"type": "library",
}
}

8
plugins/json/plugin.json Normal file
View file

@ -0,0 +1,8 @@
{
"plugin": {
"name": "json",
"version": "2.5.0",
"author": "David Kolf",
"type": "library",
}
}

8
plugins/mime/plugin.json Normal file
View file

@ -0,0 +1,8 @@
{
"plugin": {
"name": "mime",
"version": "0.1.2-1",
"author": "Tim Caswell",
"type": "library",
}
}

8
plugins/path/plugin.json Normal file
View file

@ -0,0 +1,8 @@
{
"plugin": {
"name": "path",
"version": "1.0.0",
"author": "Tim Caswell",
"type": "library",
}
}

View file

@ -0,0 +1,8 @@
{
"plugin": {
"name": "pretty-print",
"version": "1.0.3",
"author": "Tim Caswell",
"type": "library",
}
}

View file

@ -0,0 +1,8 @@
{
"plugin": {
"name": "querystring",
"version": "1.0.2",
"author": "Tim Caswell",
"type": "library",
}
}

View file

@ -0,0 +1,8 @@
{
"plugin": {
"name": "weblit",
"version": "1.0.0",
"author": "Tim Caswell",
"type": "library",
}
}

View file

@ -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 = "<h1>Hello!</h1>\n"
end)
app.start()
end
return exports

View file

@ -0,0 +1,9 @@
{
"plugin": {
"name": "webserver",
"version": "1.0.0",
"author": "Miodrag Milanovic",
"type": "plugin",
"start": "false",
}
}

View file

@ -0,0 +1,8 @@
{
"plugin": {
"name": "websocket-codec",
"version": "1.0.7",
"author": "Tim Caswell",
"type": "library",
}
}