Skip to main content

一个基于 lupa 模块的轻量级扩展库,提供了便捷的 Lua 模块加载与管理功能。

Project description

MLua 使用指南

概述

MLua 是一个基于 Pythonlupa模块的轻量级扩展库,提供了便捷的 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")
# 挂载模块到环境
mlua_obj = module.mount(lua_env: MLuaEnvironment)

# 加载多个 Lua 模块
installer = MLuaInstaller("path/to/module1.lua", "path/to/module2.lua")
mlua_objects = installer.mount_all(lua_env: MLuaEnvironment)

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, ...)

高级用法

日志

from mlua import MLuaLogsPrinter

# 打印信息日志
MLuaLogsPrinter.info("Hello, world!")

# 打印警告日志
MLuaLogsPrinter.warn("Something might be wrong!")

# 打印错误日志
MLuaLogsPrinter.error("Something went wrong!")

安全模式

# 安全模式挂载(推荐)
mlua_obj = module.mount(lua_env: MLuaEnvironment, security = True)
# 非安全模式挂载(更快但可能不安全)
mlua_obj = module.mount(lua_env: MLuaEnvironment, security = False)

深度加载模块

# 深度加载模块及其所有依赖
mlua_objects = module.mount_deeply(lua_env: MLuaEnvironment)

校验状态

from mlua import status

status()

注意事项

  1. 建议始终使用安全模式挂载模块
  2. 模块依赖关系应避免循环依赖
  3. 模块文件路径应为绝对路径或相对于工作目录的有效路径
  4. 禁止循环依赖

Project details


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.0.tar.gz (10.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mlua-1.0.0-py3-none-any.whl (11.2 kB view details)

Uploaded Python 3

File details

Details for the file mlua-1.0.0.tar.gz.

File metadata

  • Download URL: mlua-1.0.0.tar.gz
  • Upload date:
  • Size: 10.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.2

File hashes

Hashes for mlua-1.0.0.tar.gz
Algorithm Hash digest
SHA256 1a1a2d9bb3871740883f0a27eb980bf78e59eca5a358be7fae0079963e02f2ee
MD5 04f6558ee87ee311b5e8472d6aee7db5
BLAKE2b-256 975ee4882ace1fe60ff1e6934e9bd6344f2a23c9c9f2ab0173f3f92c013f85a6

See more details on using hashes here.

File details

Details for the file mlua-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: mlua-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 11.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.2

File hashes

Hashes for mlua-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2be4682b3a5241d753ea517247fffe7f6dcd1ae0e566095e6e5312a2b15672c5
MD5 0c30451a33a1391f58b61b062a3e7f03
BLAKE2b-256 827d5669e3ac61ff3314a97023c1d54add77357ff428c3339aa5945c53cbde22

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page