micro-editor / micro-editor/micro
package.path is missing the path of the plugins directory
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 29.6k
- Forks
- 1.4k
- Avg merge
- 2d 18h
- Merged PRs (30d)
- 10
Description
When developing a plugin, it is currently a challenge to write multi-lua file plugin.
Since lua5.1, the recommended way to build a module is the following (in file mod.lua):
local mod = {}
function mod.Foo()
end
function mod.Bar()
end
...
return mod
And in your main script you do:
local m = require("mod")
m.Foo()
m.Bar()
Previously (lua5.0 and early lua5.1), the language provided a mechanism to define a module using a specific statement module("mod", package.seeall) and defining methods in a different way.
But this method has been deprecated and it is recommended to use new module style. (see http://lua-users.org/wiki/LuaModuleFunctionCritiqued).
So using the new module style, we can not use PluginAddFile() to load an extra lua file (because it doesn't return a reference to the table from the module). Using the new module style, we are forced to use the require() method to load extra modules. The require method does a search for module along a predefined set of path (package.path). Unfortunately, the plugin folder is not in the package.path, so we can not do m = require(pluginname/module.lua)
If would be great if micro could expose the path of the plugin directory somewhere (in config?) so that we could modify the package.path as necessary, or better if micro could add the plugin path to the package.path before running any of the plugin.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing plugin loading and PluginAddFile(), then inspect how Lua's package.path is initialized before plugins run. Compare exposing the plugin directory with adding it automatically; done when a multi-file plugin can require a sibling module using Lua's newer module style.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go, lua
- Domain
- cli, devtools
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100