-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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.