-
Notifications
You must be signed in to change notification settings - Fork 0
Plugins
⚠️ Like smake files, plugins are not sandboxed. Please be careful when installing plugins.
✅ Plugins have access to the smake api, so you can use any libraries or globals you would use in a smake file.
Find the Lua script(s) for your plugin and move them into your plugins directory.
To execute a plugin simply type smake -p <name> replacing with the name of the plugin. You can add any flags after that for the plugin to use.
Creating a plugin is easy. Simply create a Lua file with the name of your plugin inside of your plugins directory and start writing code.
⚠️ It is recommended to always usePlugin.Commandfor CLI plugins so things don't error when imported in a Smake file. Fields available in the Plugin API for CLI execution will not exist when being imported.
✅ Plugin.Commands is a variadic function that takes command line arguments.
Start by making a Plugin.Command function that is invoked through the Smake CLI. Look below for examples.
Parses flags based on the optstring. This function uses getopt internally, look at the specification to see how to create optstring.
Serializes all the flags passed to the plugin. For example, smake -p test -a -b -c arg would return -a -b -c arg.
⚠️ Keep globals to a minimum to prevent polluting the main Smake environment. The global environment is shared between all plugins and the main Smake file.
To allow your plugin to be imported in a Smake file, simply make a Plugin.Import function and return anything necessary. To import a plugin, simply call import with the plugin's name. If you give import true as a second argument, all tables returned from the plugin will be made global.
Here is a super simple echo plugin. The code is stored inside of echo.lua in the plugins directory.
function Plugin.Command(...)
print(...)
end
function Plugin.Import()
return print
endThis plugin can be invoked through the CLI
smake -p echo Hello World!
or imported in a Smake file
local echo = import('echo')
echo('Hello World!')