aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/tests
diff options
context:
space:
mode:
author简律纯 <i@jyunko.cn>2023-11-20 09:15:53 +0800
committer简律纯 <i@jyunko.cn>2023-11-20 09:15:53 +0800
commit7894ed73f929c6676242da3a1c3bd11d78d8e711 (patch)
treea4890b78f8e8abcbfb2ec53422eea63604424a65 /tests
parent4c08ec908bfaba35c6055ee273a0768ba6749089 (diff)
downloadHydroRoll-7894ed73f929c6676242da3a1c3bd11d78d8e711.tar.gz
HydroRoll-7894ed73f929c6676242da3a1c3bd11d78d8e711.zip
feat: 实现在 lua 脚本中调用被注册的 Python 同步函数与类
Diffstat (limited to 'tests')
-rw-r--r--tests/lua_in_python.py25
1 files changed, 24 insertions, 1 deletions
diff --git a/tests/lua_in_python.py b/tests/lua_in_python.py
index 34deaab..eec2042 100644
--- a/tests/lua_in_python.py
+++ b/tests/lua_in_python.py
@@ -9,4 +9,27 @@ except ImportError:
except ImportError:
import lupa
-print(f"Using {lupa.LuaRuntime().lua_implementation} (compiled with {lupa.LUA_VERSION})") \ No newline at end of file
+print(
+ f"Using {lupa.LuaRuntime().lua_implementation} (compiled with {lupa.LUA_VERSION})"
+)
+
+from lupa import LuaRuntime
+
+lua = LuaRuntime(unpack_returned_tuples=True)
+import asyncio
+
+async def get_Dice_Dir():
+ import os
+ await asyncio.sleep(1)
+ return os.path.dirname(os.path.abspath(__file__))
+
+
+lua.globals().getDiceDir = get_Dice_Dir
+
+print(
+ lua.eval(
+ """\
+ getDiceDir()
+ """
+ )
+)