aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
author简律纯 <i@jyunko.cn>2023-11-20 09:30:14 +0800
committer简律纯 <i@jyunko.cn>2023-11-20 09:30:14 +0800
commitf5926cd9277a76e3779958d2b387ce0229697d51 (patch)
tree803f3d1a283a5a038fb6967a57e6e60618e2d109
parent7894ed73f929c6676242da3a1c3bd11d78d8e711 (diff)
downloadHydroRoll-f5926cd9277a76e3779958d2b387ce0229697d51.tar.gz
HydroRoll-f5926cd9277a76e3779958d2b387ce0229697d51.zip
feat: 支持lua内调用lua库
-rw-r--r--tests/json.lua0
-rw-r--r--tests/lua_in_python.py22
2 files changed, 12 insertions, 10 deletions
diff --git a/tests/json.lua b/tests/json.lua
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/tests/json.lua
diff --git a/tests/lua_in_python.py b/tests/lua_in_python.py
index eec2042..7692e2f 100644
--- a/tests/lua_in_python.py
+++ b/tests/lua_in_python.py
@@ -16,20 +16,22 @@ print(
from lupa import LuaRuntime
lua = LuaRuntime(unpack_returned_tuples=True)
-import asyncio
+import os
-async def get_Dice_Dir():
- import os
- await asyncio.sleep(1)
+def get_Dice_Dir():
return os.path.dirname(os.path.abspath(__file__))
lua.globals().getDiceDir = get_Dice_Dir
-
-print(
- lua.eval(
+lua.globals().package.path = lua.globals().package.path + ';' + os.path.join(get_Dice_Dir(), '?.lua')
+try:
+ lua.execute(
"""\
- getDiceDir()
- """
+ print(getDiceDir())
+ print(package.path)
+ js = require('json')
+ print(js)
+ """
)
-)
+except Exception as e:
+ print(f'{e!r}') \ No newline at end of file