polyplug-loaders-lua 0.1.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- polyplug_loaders_lua-0.1.1/PKG-INFO +7 -0
- polyplug_loaders_lua-0.1.1/polyplug_loaders_lua/__init__.py +82 -0
- polyplug_loaders_lua-0.1.1/polyplug_loaders_lua/_native/linux-x64/libpolyplug_lua.so +0 -0
- polyplug_loaders_lua-0.1.1/polyplug_loaders_lua/_native/macos-arm64/libpolyplug_lua.dylib +0 -0
- polyplug_loaders_lua-0.1.1/polyplug_loaders_lua/_native/windows-x64/polyplug_lua.dll +0 -0
- polyplug_loaders_lua-0.1.1/polyplug_loaders_lua.egg-info/PKG-INFO +7 -0
- polyplug_loaders_lua-0.1.1/polyplug_loaders_lua.egg-info/SOURCES.txt +10 -0
- polyplug_loaders_lua-0.1.1/polyplug_loaders_lua.egg-info/dependency_links.txt +1 -0
- polyplug_loaders_lua-0.1.1/polyplug_loaders_lua.egg-info/requires.txt +1 -0
- polyplug_loaders_lua-0.1.1/polyplug_loaders_lua.egg-info/top_level.txt +1 -0
- polyplug_loaders_lua-0.1.1/pyproject.toml +20 -0
- polyplug_loaders_lua-0.1.1/setup.cfg +4 -0
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"""Lua loader registration for polyplug."""
|
|
2
|
+
|
|
3
|
+
import ctypes
|
|
4
|
+
import os
|
|
5
|
+
import sys
|
|
6
|
+
import platform
|
|
7
|
+
from polyplug.runtime import Runtime
|
|
8
|
+
|
|
9
|
+
_lib = None
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def _platform_id() -> str:
|
|
13
|
+
machine: str = platform.machine().lower()
|
|
14
|
+
if sys.platform == "linux":
|
|
15
|
+
if machine in ("x86_64", "amd64"):
|
|
16
|
+
return "linux-x64"
|
|
17
|
+
if machine == "aarch64":
|
|
18
|
+
return "linux-arm64"
|
|
19
|
+
elif sys.platform == "darwin":
|
|
20
|
+
if machine == "arm64":
|
|
21
|
+
return "macos-arm64"
|
|
22
|
+
if machine in ("x86_64", "amd64"):
|
|
23
|
+
return "macos-x64"
|
|
24
|
+
elif sys.platform == "win32":
|
|
25
|
+
if machine in ("x86_64", "amd64"):
|
|
26
|
+
return "windows-x64"
|
|
27
|
+
raise RuntimeError(f"polyplug: unsupported platform {sys.platform}/{machine}")
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def _lib_filename(base: str) -> str:
|
|
31
|
+
if sys.platform == "darwin":
|
|
32
|
+
return f"lib{base}.dylib"
|
|
33
|
+
if sys.platform == "win32":
|
|
34
|
+
return f"{base}.dll"
|
|
35
|
+
return f"lib{base}.so"
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def _resolve_lib_path(env_var: str, base: str) -> str:
|
|
39
|
+
# An explicit env override (set by the test/CI harness) always wins so the
|
|
40
|
+
# loader cdylib matches the freshly built tree.
|
|
41
|
+
override: str = os.environ.get(env_var, "")
|
|
42
|
+
if override and os.path.exists(override):
|
|
43
|
+
return override
|
|
44
|
+
# Native staged into the wheel under <package>/_native/<platform>/.
|
|
45
|
+
embedded: str = os.path.join(
|
|
46
|
+
os.path.dirname(__file__), "_native", _platform_id(), _lib_filename(base)
|
|
47
|
+
)
|
|
48
|
+
if os.path.exists(embedded):
|
|
49
|
+
return embedded
|
|
50
|
+
# Fall back to the bare soname on the system library path.
|
|
51
|
+
return _lib_filename(base)
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def _get_lib() -> ctypes.CDLL:
|
|
55
|
+
global _lib
|
|
56
|
+
if _lib is None:
|
|
57
|
+
lib_path: str = _resolve_lib_path("POLYPLUG_LUA_LIB", "polyplug_lua")
|
|
58
|
+
_lib = ctypes.CDLL(lib_path)
|
|
59
|
+
_lib.polyplug_lua_loader_create.restype = ctypes.c_void_p
|
|
60
|
+
_lib.polyplug_lua_loader_create.argtypes = [ctypes.c_void_p]
|
|
61
|
+
return _lib
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
class _LuaConfig(ctypes.Structure):
|
|
65
|
+
_fields_ = [("_reserved", ctypes.c_uint8)]
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
_RUNTIME_NAME: str = "lua"
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def register_lua_loader(runtime: Runtime) -> None:
|
|
72
|
+
"""Register the Lua loader with the runtime via HostApi.register_loader."""
|
|
73
|
+
lib: ctypes.CDLL = _get_lib()
|
|
74
|
+
cfg = _LuaConfig(0)
|
|
75
|
+
loader_ptr: int = lib.polyplug_lua_loader_create(ctypes.byref(cfg))
|
|
76
|
+
if not loader_ptr:
|
|
77
|
+
raise RuntimeError("polyplug: lua loader create failed")
|
|
78
|
+
|
|
79
|
+
runtime.register_loader(loader_ptr)
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
__all__ = ["register_lua_loader"]
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
pyproject.toml
|
|
2
|
+
polyplug_loaders_lua/__init__.py
|
|
3
|
+
polyplug_loaders_lua.egg-info/PKG-INFO
|
|
4
|
+
polyplug_loaders_lua.egg-info/SOURCES.txt
|
|
5
|
+
polyplug_loaders_lua.egg-info/dependency_links.txt
|
|
6
|
+
polyplug_loaders_lua.egg-info/requires.txt
|
|
7
|
+
polyplug_loaders_lua.egg-info/top_level.txt
|
|
8
|
+
polyplug_loaders_lua/_native/linux-x64/libpolyplug_lua.so
|
|
9
|
+
polyplug_loaders_lua/_native/macos-arm64/libpolyplug_lua.dylib
|
|
10
|
+
polyplug_loaders_lua/_native/windows-x64/polyplug_lua.dll
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
polyplug
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
polyplug_loaders_lua
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "polyplug-loaders-lua"
|
|
7
|
+
version = "0.1.1"
|
|
8
|
+
description = "Lua loader for polyplug - loads LuaJIT plugins"
|
|
9
|
+
requires-python = ">=3.10"
|
|
10
|
+
license = { text = "MIT" }
|
|
11
|
+
dependencies = [
|
|
12
|
+
"polyplug",
|
|
13
|
+
]
|
|
14
|
+
|
|
15
|
+
[tool.setuptools.packages.find]
|
|
16
|
+
where = ["."]
|
|
17
|
+
include = ["polyplug_loaders_lua*"]
|
|
18
|
+
|
|
19
|
+
[tool.setuptools.package-data]
|
|
20
|
+
polyplug_loaders_lua = ["_native/**/*"]
|