User plugin foundations for 0.6.0 (#257)

Starts work on #55.

This is similar to the previous work in #125. It's gated behind a new Cargo
feature, `user-plugins`. This time, the config gate is much smaller. The
`plugins` member of projects is still accessible when plugins aren't enabled,
but is always empty. Additionally, user plugins are only enabled if there's a
Lua state present in the snapshot context when the `SnapshotUserPlugins`
snapshot middleware runs. This not ever the case currently.

This code has very little possibility of rotting while we focus on other work,
since it'll be guaranteed to still compile and can be tested in isolation
without the feature being turned on.
This commit is contained in:
Lucien Greathouse
2019-10-11 15:45:02 -07:00
committed by GitHub
parent f3dc78b7cd
commit b093626a21
17 changed files with 306 additions and 22 deletions

View File

@@ -0,0 +1,9 @@
{
"name": "plugins",
"tree": {
"$path": "src"
},
"plugins": [
"test-plugin.lua"
]
}

View File

@@ -0,0 +1 @@
print 'Hello, world!'

View File

@@ -0,0 +1,20 @@
print("test-plugin initializing...")
return function(nextDispatch, entry)
if entry:isDirectory() then
return nextDispatch(entry)
end
local name = entry:fileName()
local instanceName = name:match("(.-)%.moon$")
if instanceName == nil then
return nextDispatch(entry)
end
return rojo.instance({
Name = instanceName,
ClassName = "ModuleScript",
Source = compileMoonScript(entry:contents()),
})
end