Skip to content

Commit dd965eb

Browse files
committed
docs: add some useful stuff
1 parent 3011f18 commit dd965eb

File tree

8 files changed

+179
-91
lines changed

8 files changed

+179
-91
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ lip install --upgrade gitea.litebds.com/LiteLDev/legacy-script-engine-python
3737

3838
For more information, please refer to [the documentation](https://legacy-script-engine.levimc.org)
3939

40+
## Some helpful project for plugin development
41+
42+
- [HelperLib](https://github.com/LiteLDev/HelperLib)
43+
- [LiteLoaderSE-Aids](https://github.com/LiteLDev/LiteLoaderSE-Aids)
44+
4045
## Contributing
4146

4247
If you have any questions, please open an issue to discuss it

README.zh.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ lip install --upgrade gitea.litebds.com/LiteLDev/legacy-script-engine-python
3636

3737
更多信息请参见[文档](https://legacy-script-engine.levimc.org)
3838

39+
## 一些对插件开发有帮助的项目
40+
41+
- [HelperLib](https://github.com/LiteLDev/HelperLib)
42+
- [LiteLoaderSE-Aids](https://github.com/LiteLDev/LiteLoaderSE-Aids)
43+
3944
## 贡献
4045

4146
如果您有任何问题,请开启一个 issue 来讨论

docs/apis/LanguageSupport.md

Lines changed: 86 additions & 46 deletions
Large diffs are not rendered by default.

docs/apis/LanguageSupport.zh.md

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@
77

88
目前,脚本引擎支持使用如下语言编写插件:
99

10-
| 语言后端 | 备注 |
11-
| ------------ | ---------------------------------------------- |
10+
| 语言后端 | 备注 |
11+
|--------------|-----------------------------------|
1212
| `JavaScript` | 使用 QuickJS 引擎运行插件,支持 ES Module 机制 |
13-
| `Lua` | 使用 CLua 引擎运行插件 |
14-
| `Node.js` | 改造 Node.js 使其适合嵌入工作,支持 npm 包管理 |
15-
| `Python` | 使用 CPython 引擎运行插件,支持 pip 包管理 |
13+
| `Lua` | 使用 CLua 引擎运行插件 |
14+
| `Node.js` | 改造 Node.js 使其适合嵌入工作,支持 npm 包管理 |
15+
| `Python` | 使用 CPython 引擎运行插件,支持 pip 包管理 |
1616

1717
!!! tip
18-
如果需要使用 C++、Go、Rust 等原生语言编写插件,请移步 [主页](https://levilamina.liteldev.com) 查看其他语言文档
18+
如果需要使用 C++、Go、Rust 等原生语言编写插件,请移步 [主页](https://levilamina.liteldev.com) 查看其他语言文档
1919

2020
## JavaScript 语言支持说明
2121

@@ -24,16 +24,13 @@
2424
- 暂不支持包管理机制,如果需要请使用 Node.js 进行插件开发,使用 npm 包管理
2525
- 在BDS控制台中使用`jsdebug`命令进入和退出 QuickJs 交互式命令行环境。此功能便于编写插件时进行一些简单的测试
2626

27-
28-
2927
## Lua 语言支持说明
3028

3129
- 使用 CLua 引擎,支持使用 require 进行简单的项目管理
32-
- 由于 Rocks 包管理机制需要引入编译器,因此暂不提供相关实现。如果需要依赖扩展可以手动编译后引入项目进行使用(如 SQLite 等常用库)
30+
- 由于 Rocks 包管理机制需要引入编译器,因此暂不提供相关实现。如果需要依赖扩展可以手动编译后引入项目进行使用(如 SQLite
31+
等常用库)
3332
- 在BDS控制台中使用`luadebug`命令进入和退出 Lua 交互式命令行环境。此功能便于编写插件时进行一些简单的测试
3433

35-
36-
3734
## Node.js 支持说明
3835

3936
- LSE 通过自行实现 Node.js 启动代码,使其可以在嵌入式模式下工作,并实现了不同插件的执行环境隔离
@@ -51,13 +48,13 @@
5148
- 在插件编写完成之后,请将 `package.json` 以及所有插件源码打包为一个zip压缩包,并**将文件名后缀修改为 .llplugin**
5249
- `node_modules` 目录请勿打包在压缩包之中
5350
-**.llplugin** 文件作为插件分发,安装插件时直接将此文件放置到 plugins 目录即可
54-
- 在开服时,脚本引擎会自动识别 **.llplugin** 文件,将其解压到`plugins/nodejs/插件名`目录,并在目录中自动执行 `npm install`安装依赖包,整个过程无需人工干预
55-
56-
51+
- 在开服时,脚本引擎会自动识别 **.llplugin** 文件,将其解压到`plugins/nodejs/插件名`目录,并在目录中自动执行 `npm install`
52+
安装依赖包,整个过程无需人工干预
5753

5854
## Python 语言支持说明
5955

60-
- 使用 CPython 引擎,Python版本为3.10.9。支持使用 pip 包管理机制为插件安装第三方扩展依赖包,支持多文件插件开发和 import,支持现代项目管理机制
56+
- 使用 CPython 引擎,Python版本为3.12.8。支持使用 pip 包管理机制为插件安装第三方扩展依赖包,支持多文件插件开发和
57+
import,支持现代项目管理机制
6158
- 在BDS控制台中使用`pydebug`命令进入和退出 Python 交互式命令行环境。此功能便于编写插件时进行一些简单的测试
6259

6360
#### **Python 单文件插件开发方法**
@@ -69,21 +66,23 @@
6966
#### **Python 多文件插件开发方法**
7067

7168
- 对于大型、正式的Python插件,强烈建议使用此方法进行开发。多文件插件支持所有完整的Python特性。
72-
- LSE 使用`pyproject.toml` 项目文件进行元数据储存(类似 Node.Js 的`package.json`)。此项目文件推荐使用支持现代项目特性的 PDM 包管理器([pdm-project/pdm](https://github.com/pdm-project/pdm))自动生成,以便于进行插件项目的创建和维护。
69+
- LSE 使用`pyproject.toml` 项目文件进行元数据储存(类似 Node.Js 的`package.json`)。此项目文件推荐使用支持现代项目特性的
70+
PDM 包管理器([pdm-project/pdm](https://github.com/pdm-project/pdm))自动生成,以便于进行插件项目的创建和维护。
7371

7472
##### **下面是具体的插件开发流程:**
7573

76-
1. 首先,安装Python 3.10.9
74+
1. 首先,安装Python 3.12.8
7775

7876
2. 在终端中执行`pip install --user pdm`命令安装 pdm 包管理工具
7977

8078
3. 创建一个新的目录进行插件开发。在此目录启动终端执行`pdm init`命令。根据pdm工具的提示创建新项目,填写项目的相关信息。
8179

82-
- 如果需要安装依赖包,在项目目录执行`pdm add <依赖包名>`即可
80+
- 如果需要安装依赖包,在项目目录执行`pdm add <依赖包名>`即可
8381

84-
- 所有的项目元数据和依赖数据都会被自动储存在`pyproject.toml` 中,无需手动编写。你也可以打开此文件修改版本号、描述等元数据信息
82+
- 所有的项目元数据和依赖数据都会被自动储存在`pyproject.toml` 中,无需手动编写。你也可以打开此文件修改版本号、描述等元数据信息
8583

86-
- 除了使用`pdm add`命令之外,你也可以直接把项目依赖手动写在`requirements.txt`当中。在安装插件时,`pyproject.toml``requirements.txt`中描述的依赖都将被处理并自动安装。
84+
- 除了使用`pdm add`命令之外,你也可以直接把项目依赖手动写在`requirements.txt`当中。在安装插件时,`pyproject.toml`
85+
`requirements.txt`中描述的依赖都将被处理并自动安装。
8786

8887
4. 接下来创建`__init__.py`文件,并在其中编写插件代码。加载插件时,Python解释器会首先读取并执行这个文件。
8988

@@ -94,17 +93,19 @@
9493
- 在插件编写完成之后,请将 `pyproject.toml`以及所有插件源码打包为一个zip压缩包,并**将文件名后缀修改为 .llplugin**
9594
- `__pycache__``__pypackages__` 等目录请勿打包在压缩包之中
9695
-**.llplugin** 文件作为插件分发,安装插件时直接将此文件放置到 plugins 目录即可
97-
- 在开服时,脚本引擎会自动识别 **.llplugin** 文件,将其解压到`plugins/python/插件名`目录,并在目录中自动执行 `pip install`安装依赖包,整个过程无需人工干预
96+
- 在开服时,脚本引擎会自动识别 **.llplugin** 文件,将其解压到`plugins/python/插件名`目录,并在目录中自动执行 `pip install`
97+
安装依赖包,整个过程无需人工干预
9898

9999
#### **Python插件开发的已知问题**
100100

101101
平心而论,CPython的代码质量和维护状况有些堪忧。下面给出了一些开发Python插件时需要注意的地方,其中有不少都是由CPython本身的Bug引起的:
102102

103103
1. 暂时不要使用`threading` `asyncio`等特性
104-
- LSE使用CPython的子解释器作为引擎调度的核心单位,然而CPython自身长期以来对子解释器机制的支持并不完善,存在众多Bug,令人一言难尽。目前上面这些机制所需要使用到的GIL api内部并没有考虑到子解释器的存在,因此一旦使用会发生死锁、崩溃等问题。
105-
- 如果有并行计算需求的开发者可以暂时使用`multiprocess`进行多进程并行
106-
- Python3.12 按计划将对子解释器和GIL相关bug做出针对性的修复,届时LSE将对CPython3.12进行适配,解决此问题。Py3.12预计在2023年10月份左右推出,请耐心等待
104+
- LSE使用CPython的子解释器作为引擎调度的核心单位,然而CPython自身长期以来对子解释器机制的支持并不完善,存在众多Bug,令人一言难尽。目前上面这些机制所需要使用到的GIL
105+
api内部并没有考虑到子解释器的存在,因此一旦使用会发生死锁、崩溃等问题。
106+
- 如果有并行计算需求的开发者可以暂时使用`multiprocess`进行多进程并行
107+
- Python3.12 按计划将对子解释器和GIL相关bug做出针对性的修复,届时LSE将对CPython3.12进行适配,解决此问题。Py3.12预计在2023年10月份左右推出,请耐心等待
107108
2. 所有Python引擎的`sys.stdin`被禁用
108-
- 这是另外一个CPython的bug,具体详见:https://github.com/python/cpython/issues/83526
109-
- 另外,即使不是上述情况下加载的CPython引擎,也会出现抢夺stdin的问题,导致部分使用了输入重定向机制的工具失效
110-
- 因此我们打patch禁用了所有Python引擎的`sys.stdin`,等待后续版本CPython将此系列bug彻底解决之后,再视情况恢复
109+
- 这是另外一个CPython的bug,具体详见:https://github.com/python/cpython/issues/83526
110+
- 另外,即使不是上述情况下加载的CPython引擎,也会出现抢夺stdin的问题,导致部分使用了输入重定向机制的工具失效
111+
- 因此我们打patch禁用了所有Python引擎的`sys.stdin`,等待后续版本CPython将此系列bug彻底解决之后,再视情况恢复

docs/index.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ lip install --upgrade gitea.litebds.com/LiteLDev/legacy-script-engine-python
4141

4242
For more information, please refer to [the documentation](https://legacy-script-engine.levimc.org)
4343

44+
## Some helpful project for plugin development
45+
46+
- [HelperLib](https://github.com/LiteLDev/HelperLib)
47+
- [LiteLoaderSE-Aids](https://github.com/LiteLDev/LiteLoaderSE-Aids)
48+
4449
## Contributing
4550

4651
If you have any questions, please open an issue to discuss it

docs/index.zh.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ lip install --upgrade gitea.litebds.com/LiteLDev/legacy-script-engine-python
4040

4141
更多信息请参见[文档](https://legacy-script-engine.levimc.org)
4242

43+
## 一些对插件开发有帮助的项目
44+
45+
- [HelperLib](https://github.com/LiteLDev/HelperLib)
46+
- [LiteLoaderSE-Aids](https://github.com/LiteLDev/LiteLoaderSE-Aids)
47+
4348
## 贡献
4449

4550
如果您有任何问题,请开启一个 issue 来讨论

docs/tutorials/create_your_first_plugin.md

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,51 @@
11
# Create Your First Plugin
22

3-
> This guide serves to demonstrate the very simple and straight forward process to creating your first plugin - as well as some best practices when thinking about what to make and how to do it. Experience using JavaScript previously is recommended, but not required. JavaScript is a very beginner friendly language, so don't get overwhelmed!
3+
> This guide serves to demonstrate the very simple and straight forward process to creating your first plugin - as well
4+
> as some best practices when thinking about what to make and how to do it. Experience using JavaScript previously is
5+
> recommended, but not required. JavaScript is a very beginner friendly language, so don't get overwhelmed!
46
57
## Prerequisites
68

7-
Before developing your first plugin, we will need to set up your developer environment (IDE). The choice of software you use to program is yours, but trusted and reliable software is recommended. [Atom](https://atom.io/) is lightweight editor that works well for this tutorial, otherwise [VSCode](https://code.visualstudio.com/) is also a widely used editor with a lot of powerful features.
9+
Before developing your first plugin, we will need to set up your developer environment (IDE). The choice of software you
10+
use to program is yours, but trusted and reliable software is recommended. [Atom](https://atom.io/) is lightweight
11+
editor that works well for this tutorial, otherwise [VSCode](https://code.visualstudio.com/) is also a widely used
12+
editor with a lot of powerful features.
813

9-
You will also need to set up a clean LeviLamina installation, details on how to install LeviLamina can be found [here](https://levilamina.liteldev.com/install/). This server will be used to test your plugin.
14+
You will also need to set up a clean LeviLamina installation, details on how to install LeviLamina can be
15+
found [here](https://levilamina.liteldev.com/install/). This server will be used to test your plugin.
1016

1117
With your IDE in hand, and the server installation complete, you are ready to begin!
1218

1319
## What Do I Do Now?
1420

15-
Developing a LLSE Plugin begins with creating your plugin's file. This file should be named "LLMyPlugin.js", replacing "MyPlugin" with what you would like to call your plugin. It should be placed in the plugins folder of your server installation. Some IDEs will allow you to create a new file and choose a location, while others will allow you to choose only after hitting "Save As".
21+
Developing a LLSE Plugin begins with creating your plugin's file. This file should be named "LLMyPlugin.js", replacing "
22+
MyPlugin" with what you would like to call your plugin. It should be placed in the plugins folder of your server
23+
installation. Some IDEs will allow you to create a new file and choose a location, while others will allow you to choose
24+
only after hitting "Save As".
1625

17-
This might confuse some developers, as `ll` should be undefined. However, this file is going to be utilized by the LeviLamina ScriptX Engine. `ll` will be automatically included during the script's runtime. This is the same with any other variables/classes you see referenced without a definition.
18-
19-
Now that we have created our .js file, and registered the plugin, all we have to do from here is create an event listener. We do that by utilizing `mc`.
26+
This might confuse some developers, as `ll` should be undefined. However, this file is going to be utilized by the
27+
LeviLamina ScriptX Engine. `ll` will be automatically included during the script's runtime. This is the same with any
28+
other variables/classes you see referenced without a definition.
2029

30+
Now that we have created our .js file, and registered the plugin, all we have to do from here is create an event
31+
listener. We do that by utilizing `mc`.
2132

2233
```js
2334
mc.listen("onJoin", (player) => {
2435
log(`${player.name} has joined the server.`);
2536
});
2637
```
38+
2739
> Reference: [Event Listening Documentation](../apis/EventAPI/Listen.md)
2840
29-
In order to test your plugin, simply start the server and the server should be able to identify your plugin and successfully load it. LeviLamina console will log any logs you create, as well as any errors if your plugin, or the API fails. Iteration while developing is important. Test frequently and each step of the way to ensure that when an issue does pop up, you know exactly what you changed and can come up with a solution to fix it.
41+
In order to test your plugin, simply start the server and the server should be able to identify your plugin and
42+
successfully load it. LeviLamina console will log any logs you create, as well as any errors if your plugin, or the API
43+
fails. Iteration while developing is important. Test frequently and each step of the way to ensure that when an issue
44+
does pop up, you know exactly what you changed and can come up with a solution to fix it.
3045

31-
You can reference the `mc` class as well as other special classes and constructors. The `mc` class is the bread and butter of your plugin and will allow you to do a lot of cool things. The Game Content interface has all the methods and properties available to you.
46+
You can reference the `mc` class as well as other special classes and constructors. The `mc` class is the bread and
47+
butter of your plugin and will allow you to do a lot of cool things. The Game Content interface has all the methods and
48+
properties available to you.
3249
> Reference: [Game Element Interface Documentation](../apis/GameAPI/Basic.md)
3350
3451
For example, we can use the player object and directly act on it to send information/manipulate a Player.
@@ -51,6 +68,12 @@ mc.listen("onJoin", (player) => {
5168
});
5269
```
5370

54-
This brings us to the final considerations. When making plugins, try to think of something simple and self-enclosing. Every developer wants to build a massive plugin with a ton of features, but such projects are prone to abandonment as they never truly get finished. Make a series of small plugins that have specific purpose. Add features to those plugins to enable configuration and customization. Find features or things you wish the game had and use the methods available in LeviLamina to make them happen. There are truly unlimited possibilities with LeviLamina's API.
71+
This brings us to the final considerations. When making plugins, try to think of something simple and self-enclosing.
72+
Every developer wants to build a massive plugin with a ton of features, but such projects are prone to abandonment as
73+
they never truly get finished. Make a series of small plugins that have specific purpose. Add features to those plugins
74+
to enable configuration and customization. Find features or things you wish the game had and use the methods available
75+
in LeviLamina to make them happen. There are truly unlimited possibilities with LeviLamina's API.
5576

56-
If you run into any issues while developing, questions, comments or concerns can be answered by joining the [Telegram](https://t.me/LiteLoader)/[Discord](https://discord.gg/5HU3cJsVZ5) - or by opening an issue on the LeviLamina Github Repo.
77+
If you run into any issues while developing, questions, comments or concerns can be answered by
78+
joining [LeviLamina](https://github.com/LiteLDev/LeviLamina)‘s Groups or by opening an issue on the LegacyScriptEngine
79+
Github Repo.

0 commit comments

Comments
 (0)