From 7894ed73f929c6676242da3a1c3bd11d78d8e711 Mon Sep 17 00:00:00 2001 From: 简律纯 Date: Mon, 20 Nov 2023 09:15:53 +0800 Subject: feat: 实现在 lua 脚本中调用被注册的 Python 同步函数与类 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/lua_in_python.py | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) 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() + """ + ) +) -- cgit v1.2.3-70-g09d2