From f5926cd9277a76e3779958d2b387ce0229697d51 Mon Sep 17 00:00:00 2001 From: 简律纯 Date: Mon, 20 Nov 2023 09:30:14 +0800 Subject: feat: 支持lua内调用lua库 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/json.lua | 0 tests/lua_in_python.py | 22 ++++++++++++---------- 2 files changed, 12 insertions(+), 10 deletions(-) create mode 100644 tests/json.lua diff --git a/tests/json.lua b/tests/json.lua new file mode 100644 index 0000000..e69de29 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 -- cgit v1.2.3-70-g09d2