Skip to content

Commit 8709af2

Browse files
committed
update "Dependencies" and "Libraries" pages
1 parent 6aa9bff commit 8709af2

File tree

2 files changed

+53
-15
lines changed

2 files changed

+53
-15
lines changed

dependencies.md

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,38 @@ order: 97
44
---
55

66
# Dependencies
7-
TO-DO
7+
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.
8+
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+
14+
<br />
15+
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+
20+
```lua /plugins/LuaLink/scripts/example_script/init.lua
21+
depends {
22+
"PlaceholderAPI"
23+
}
24+
```
25+
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.
31+
32+
Assuming the plugin is **installed** and **enabled** on the server, we should be able to call its API like any other function.
33+
```lua /plugins/LuaLink/scripts/example_script/main.lua
34+
local PlaceholderAPI = import("me.clip.placeholderapi.PlaceholderAPI")
35+
36+
script.logger:info(PlaceholderAPI:setPlaceholders(nil, "Server is running %server_variant% %server_version_full%"))
37+
```
38+
```log Console Output
39+
[00:00:00 INFO]: [LuaLink/example_script] Server is running Paper 1.21.4-224
40+
```
41+
That's it. As mentioned earlier, current implementation is really simple and should just work.

libraries.md

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,21 @@ order: 96
44
---
55

66
# Libraries
7-
LuaLink provides a way to load external **Java** libraries for use in your scripts, as well as to define and/or use external **Lua** libraries.
7+
LuaLink provides a way to load external **Java** libraries for use in your scripts, as well as to define and use external **Lua** libraries.
88

99
<br />
1010

11+
<!--
1112
## Lua Libraries
1213
External Lua libraries can be added by creating or copying files to the `/plugins/LuaLink/libs/` folder.
1314
1415
==- Example Lua Library
1516
```lua **/plugins/LuaLink/libs/example_library/main.lua**
16-
local Counter = {}
17-
Counter.__index = Counter
17+
Counter = {}
1818
1919
-- Creates a new Counter instance.
2020
function Counter.new()
21-
local self = setmetatable({}, Counter)
21+
local self = setmetatable({}, {__index = Counter})
2222
self.count = 0
2323
return self
2424
end
@@ -37,8 +37,6 @@ end
3737
function Counter:get()
3838
return self.count
3939
end
40-
41-
return Counter
4240
```
4341
==-
4442
@@ -51,7 +49,7 @@ local Counter = require("example_library")
5149
5250
script:onLoad(function()
5351
-- Creating a new instance of the Counter class.
54-
local counter = Counter()
52+
local counter = Counter:new()
5553
-- Incrementing the counter three times.
5654
counter:increment()
5755
counter:increment()
@@ -63,6 +61,8 @@ end)
6361
6462
<br />
6563
64+
-->
65+
6666
## Java Libraries
6767
External Java/Kotlin libraries can be added by configuring the `/plugins/LuaLink/libraries.json` file. Dependencies will be downloaded and exposed to the scripting runtime after server restart.
6868

@@ -72,7 +72,7 @@ External Java/Kotlin libraries can be added by configuring the `/plugins/LuaLink
7272
// Repositories to be used for dependency resolution.
7373
"repositories": {
7474
// Repository definition using simple format.
75-
"MavenCentral": "https://repo.maven.apache.org/maven2/",
75+
"PaperMC": "https://repo.papermc.io/repository/maven-public/",
7676
// Repository definition with credentials authentication.
7777
"SomePrivateRepository": {
7878
"url": "https://repo.example.com/private",
@@ -83,17 +83,21 @@ External Java/Kotlin libraries can be added by configuring the `/plugins/LuaLink
8383
// Dependencies to be downloaded and exposed to the scripting runtime.
8484
// Entries must be specified using Maven coordinate format: groupId:artifactId:version
8585
"dependencies": [
86-
"com.github.stefvanschie.inventoryframework:IF:0.10.11"
86+
"io.papermc:paperlib:1.0.7"
8787
]
8888
}
8989
```
9090

91-
In this example, we are adding stefvanschie's [IF](https://github.com/stefvanschie/IF) library of version `0.10.11` from [Maven Central](https://repo.maven.apache.org/maven2/) repository. You can also see how and authenticate with a private repository using credentials, which might be essential when working with closed-source projects or [GitHub Packages](https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-apache-maven-registry).
91+
In this example, we are adding **[PaperLib](https://github.com/PaperMC/PaperLub)** library of version **1.0.7** from **[PaperMC](https://repo.papermc.io/repository/maven-public/)** repository. You can also see how and authenticate with a private repository using credentials, which might be essential when working with closed-source projects or **[GitHub Packages](https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-apache-maven-registry)**.
9292

9393
After restarting the server, we should be able to import and access any class that belongs to specified library(-ies).
9494

95-
```lua /plugins/LuaLink/scripts/example_script/init.lua
96-
-- TO-DO
97-
```
95+
```lua /plugins/LuaLink/scripts/example_script/main.lua
96+
local PaperLib = import("io.papermc.lib.PaperLib")
9897

99-
<br />
98+
script.logger:info("Is the server running Paper? " .. (PaperLib:isPaper() and "YES" or "NO") .. "!")
99+
```
100+
```log Console Output
101+
[00:00:00 INFO]: [LuaLink/example_script] Is the server running Paper? YES!
102+
```
103+
While this example may not be the best use of **PaperLib** - especially because **LuaLink** requires you to run the plugin on **Paper** - it is still a good example of how to use external libraries in your scripts.

0 commit comments

Comments
 (0)