一个基于 lupa 模块的轻量级扩展库,提供了便捷的 Lua 模块加载与管理功能。
Reason this release was yanked:
未在__init__.py文件中暴露MLuaPackager模块,导致其无法被调用
Project description
from mlua.mlua import MLuaManagerfrom mlua.mlua.envs import MLuaPackager
MLua 使用指南
概述
一个基于 lupa 模块的轻量级扩展库,提供了便捷的 Lua 环境管理和模块加载功能。
快速开始
1. 创建 Lua 环境
from mlua import MLuaEnvironment
# 创建 Lua 运行时环境
lua_env = MLuaEnvironment()
2. 加载 Lua 模块
from mlua import MLuaModule, MLuaInstaller
# 加载单个 Lua 模块
module = MLuaModule("path/to/module.lua")
# 挂载模块到环境,指定secure=True以选择安全模式,默认选择
mlua_obj = module.mount(lua_env: MLuaEnvironment, [secure=True])
# 加载模块及其依赖
mlua_objects = module.mount_deeply(lua_env: MLuaEnvironment, [secure=True])
# 加载多个 Lua 模块,返回一个mlua_objects列表
installer = MLuaInstaller(mlua_module1: MLuaModule, mlua_module2: MLuaModule, ...)
mlua_objects = installer.mount_all(lua_env: MLuaEnvironment, [secure=True])
3. 使用模块功能
# 调用模块函数
results = mlua_obj.functions.some_function()
# 访问模块值
value = mlua_obj.values.some_variable
4. 处理模块依赖
from mlua import MLuaResolver
# 创建依赖管理器
resolver = MLuaResolver()
# 解析模块依赖(解析对象式)
modules_to_load = resolver.requirements(module: MLuaModule)
# 解析模块依赖(解析全局式)
modules_to_load = MLuaResolver.requirements_directly(module: MLuaModule)
# 打印依赖关系
MLuaResolver.relationship(modules_to_load1, modules_to_load2, modules_to_load3, ...)
5.日志
from mlua import MLuaLogsPrinter
# 打印信息日志
MLuaLogsPrinter.info("Hello, world!")
# 打印警告日志
MLuaLogsPrinter.warn("Something might be wrong!")
# 打印错误日志
MLuaLogsPrinter.error("Something went wrong!")
6.打包
# 打包模块,返回字节串
results_bytes = MLuaPackager.pack(module1: MLuaModule, module2: MLuaModule, ...)
# 解包模块,返回模块列表
results_modules = MLuaPackager.unpack(data_bytes: bytes)
7.保存至文件
# 保存模块至文件,默认仓库目录为./mlua_modules
MLuaManager.save(module1: MLuaModule, module2: MLuaModule, ..., [directory="./mlua_modules"])
# 加载模块文件,返回模块列表
results_modules = MLuaManager.load([directory="./mlua_modules"])
# 直接使用指定模块
results_modules = MLuaManager.use("module1", "module2", ..., [directory="./mlua_modules"])
校验状态
from mlua import status
status()
注意事项
- 建议始终使用安全模式挂载模块
- 模块依赖关系应避免循环依赖
- 模块文件路径应为绝对路径或相对于工作目录的有效路径
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
mlua-1.0.1.tar.gz
(11.1 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
mlua-1.0.1-py3-none-any.whl
(11.3 kB
view details)
File details
Details for the file mlua-1.0.1.tar.gz.
File metadata
- Download URL: mlua-1.0.1.tar.gz
- Upload date:
- Size: 11.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9e1b00d3a22651e74a282b47a405bc4ff6c86e2c6e9b05587b9e1606d0c0b4a0
|
|
| MD5 |
5c8a7aacae65a647847f74f666b9ece1
|
|
| BLAKE2b-256 |
92dfb7a1db9bb22961a3d7b5787b9e538d92a2738159eb9b499bff8c4872173c
|
File details
Details for the file mlua-1.0.1-py3-none-any.whl.
File metadata
- Download URL: mlua-1.0.1-py3-none-any.whl
- Upload date:
- Size: 11.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
480c6e9f00bed79c8eaa4a15d7fac5900a34b9577f946ec55683a883716ffd15
|
|
| MD5 |
a6fe8a0d5e8d4ebf52bba2ef243616ce
|
|
| BLAKE2b-256 |
3d1369c4328be1ad61a9957323ac51ca6287c7817835b461471e3eba197b97d3
|