You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In this section you can find community-made libraries that were written specifically for use with LuaLink. Want to see your project here? **[Submit a PR](https://github.com/LuaLink/docs/pulls)** and we'll consider adding it to the list.
Copy file name to clipboardExpand all lines: examples.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,7 +3,7 @@ icon: play
3
3
order: 94
4
4
---
5
5
# Examples
6
-
In this section you can find some example scripts written with LuaLink. Want to see your script here? **[Submit a PR](https://github.com/LuaLink/docs/pulls)** and we'll add it to the list.
6
+
In this section you can find some example scripts written with LuaLink. Want to see your script here? **[Submit a PR](https://github.com/LuaLink/docs/pulls)** and we'll consider adding it to the list.
Copy file name to clipboardExpand all lines: libraries.md
+60-40Lines changed: 60 additions & 40 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,69 +4,86 @@ order: 96
4
4
---
5
5
6
6
# 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.
7
+
LuaLink provides a way to load external **Java** libraries for use in your scripts, as well as to define and use embedded**Lua** libraries.
8
8
9
9
<br />
10
10
11
-
<!--
12
11
## Lua Libraries
13
-
External Lua libraries can be added by creating or copying files to the `/plugins/LuaLink/libs/` folder.
12
+
Lua libraries are almost identical to scripts, but there are a few differences.
13
+
- Each Lua library should be placed in a separate folder in the `/plugins/LuaLink/libs` directory.
14
+
<sup>For example `/plugins/LuaLink/libs/example/main.lua` will be available as `example` or `example.main`.</sup>
15
+
- Entry point of a Lua library should be always be a `main.lua` file.
16
+
<sup>Different entry points are still possible however, and can be imported using a `.` denoted path, for example: `require("my_lib.my_entry_point")`</sup>
17
+
- Lua Libraries are loaded on demand, using the `require` keyword.
18
+
<sup>For example, if we want to use the `example` library in our script, we can import it using the `require("example")`.</sup>
-- Printing current value of the counter to the console.
58
-
script.logger:info(counter:get() .. " is the current value of the counter.")
59
-
end)
60
+
localCounter=require("counter")
61
+
62
+
-- Creating a new instance of the Counter class.
63
+
localcounter=Counter:new()
64
+
-- Incrementing the counter three times.
65
+
counter:increment()
66
+
counter:increment()
67
+
counter:increment()
68
+
-- Decrementing the counter once.
69
+
counter:decrement()
70
+
-- Printing current value of the counter to the console.
71
+
print(counter:get() .." is the current value.")
72
+
```
73
+
```log Console Output
74
+
[00:00:00 INFO]: [LuaLink/example_script] 2 is the current value.
60
75
```
61
76
62
77
<br />
63
-
64
-
-->
78
+
<hr>
79
+
<br />
65
80
66
81
## Java Libraries
67
82
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.
68
83
69
-
### Configuration Example
84
+
<br />
85
+
86
+
### Configuration
70
87
```json5 /plugins/LuaLink/libraries.json
71
88
{
72
89
// Repositories to be used for dependency resolution.
@@ -90,6 +107,9 @@ External Java/Kotlin libraries can be added by configuring the `/plugins/LuaLink
90
107
91
108
In this example, we are adding **[PaperLib](https://github.com/PaperMC/PaperLib)** 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)**.
92
109
110
+
<br />
111
+
112
+
### Usage
93
113
After restarting the server, we should be able to import and access any class that belongs to specified library(-ies).
0 commit comments