|
| 1 | +--- |
| 2 | +description: Learn how to write plugins for Lite XL. |
| 3 | +--- |
| 4 | + |
| 5 | +# Writing Plugins |
| 6 | + |
| 7 | +Lite XL allows users to load Lua files to add or modify functionalities of the editor. |
| 8 | +In general, a plugin is a Lua file or a directory that contains an `init.lua` file |
| 9 | +serving as the entrypoint. |
| 10 | +Plugins can load other Lua files or native libraries that can be used to call system functions, |
| 11 | +but are responsible for managing their own dependencies. |
| 12 | + |
| 13 | +!!! tip |
| 14 | + [Plugin managers] provide dependency resolution capabilities for plugins, |
| 15 | + and automates the installation of native libraries on different platforms. |
| 16 | + If you aren't using a plugin manager, you should definitely consider using one. |
| 17 | + |
| 18 | +## Overriding existing functionality |
| 19 | + |
| 20 | +Lite XL heavily uses the idiom of overriding existing function that does a certain task. |
| 21 | +For instance, to run something when the user saves a file, you can override `Doc:save()` |
| 22 | +to add your own functionality before or after calling the original `Doc:save()` function. |
| 23 | +This design makes plugin code generally easier to tinker with, but gets complex when the user |
| 24 | +installs a bunch of plugins that doesn't interact with each other well. |
| 25 | +This is a trade-off [lite] and Lite XL made for the sake of simplicity. |
| 26 | + |
| 27 | +## Native libraries |
| 28 | + |
| 29 | +Lite XL, since v2.1.0, supports loading shared libraries |
| 30 | +(also known as dynamically-linked libraries on Windows) to provide functionalities |
| 31 | +that are not available with Lite XL's own native bindings. |
| 32 | +Lite XL uses [Lua's convention] for these libraries, but extends the convention to support |
| 33 | +statically-linked Lua in Lite XL. |
| 34 | + |
| 35 | +!!! warning |
| 36 | + Using native libraries in v2.1.0 is **not recommended**, as the native plugin API |
| 37 | + was missing several Lua symbols that will cause a crash when called. |
| 38 | + This behavior is fixed in v2.1.1. |
| 39 | + |
| 40 | +## In this section |
| 41 | + |
| 42 | +| Topic | Description |
| 43 | +| ----- | ----------- |
| 44 | +| [Classes and Objects] | Learn how Lite XL implements OOP in Lua. |
| 45 | +| [Documents] | Learn about how to operate on files opened in the editor. |
| 46 | +| [Views] | Learn about Views, one of the core concepts for building UIs. |
| 47 | +| [Background Tasks] | Learn how to use background tasks to perform long-running operations. |
| 48 | +| [Debugging] | Learn how to debug Lite XL with the debugger plugin, and other related tips. |
| 49 | + |
| 50 | + |
| 51 | +[Plugin managers]: ../../user-guide/managing-plugins.md#plugin-managers |
| 52 | +[lite]: https://github.com/rxi/lite |
| 53 | +[Lua's convention]: https://www.lua.org/manual/5.4/manual.html#pdf-package.searchers |
| 54 | +[Classes and Objects]: ./classes-and-objects.md |
| 55 | +[Documents]: ./documents.md |
| 56 | +[Views]: ./views.md |
| 57 | +[Background Tasks]: ./background-tasks.md |
| 58 | +[Debugging]: ./debugging.md |
0 commit comments