Skip to content

Commit 87d1a5c

Browse files
committed
document dependency declaration
1 parent 2777488 commit 87d1a5c

File tree

1 file changed

+11
-18
lines changed

1 file changed

+11
-18
lines changed

dependencies.md

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,36 +6,29 @@ order: 97
66
# Dependencies
77
LuaLink provides a way to access and use plugins' APIs in your scripts. This feature is very powerful and makes it easy to integrate scripts with other plugins. It must be noted this has not been thoroughly tested yet and some issues may arise. Please be cautious when using this feature.
88

9-
!!! warning EXPERIMENTAL
10-
Current implementation, despite being relatively simple and fully functional, is still marked as experimental.
11-
We may introuduce breaking changes to the way dependencies are declared and exposed to scripts.
12-
!!!
13-
149
<br />
1510

16-
<!--
17-
## Declaring Dependencies
18-
To declare a dependency, you must create an `init.lua` file in your script's folder. In this example we will use **[PlaceholderAPI](https://www.spigotmc.org/resources/placeholderapi.19978/)**.
19-
11+
### Declaring Dependencies
12+
Before we can start using any external API, we must declare a dependency. This ensures that script will **not be loaded** if dependency plugin is missing. To declare dependencies, you must create `init.lua` file in your script's folder.
2013
```lua /plugins/LuaLink/scripts/example_script/init.lua
21-
depends {
22-
"PlaceholderAPI"
14+
return {
15+
dependencies = {
16+
"PlaceholderAPI"
17+
}
2318
}
2419
```
20+
In this example we will use **[PlaceholderAPI](https://www.spigotmc.org/resources/placeholderapi.19978/)** - a plugin you should already be familiar with.
2521

26-
**Why is that important?** Declaring dependency will ensure that script will not be loaded if **PlaceholderAPI** plugin is missing.
27-
-->
28-
29-
## Using Dependencies
30-
Importing any class that belongs to an installed plugin should work out of the box. In this example we will use **[PlaceholderAPI](https://www.spigotmc.org/resources/placeholderapi.19978/)**, a plugin you should be already familiar with.
22+
<br />
3123

32-
Assuming the plugin is **installed** and **enabled** on the server, we should be able to call its API like any other function.
24+
### Accessing Dependencies
25+
Next, assuming the plugin is **installed** and **enabled** on the server, any import and call to its API should work as expected.
3326
```lua /plugins/LuaLink/scripts/example_script/main.lua
3427
local PlaceholderAPI = import("me.clip.placeholderapi.PlaceholderAPI")
3528

29+
-- NOTE: Placeholders in this example come from the Server expansion which is not installed by default.
3630
script.logger:info(PlaceholderAPI:setPlaceholders(nil, "Server is running %server_variant% %server_version_full%"))
3731
```
3832
```log Console Output
3933
[00:00:00 INFO]: [LuaLink/example_script] Server is running Paper 1.21.4-224
4034
```
41-
That's it. As mentioned earlier, current implementation is really simple and should just work.

0 commit comments

Comments
 (0)