aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/tests/lua_in_python.py
blob: 0f929df3b80eabfe1bb7011fff9aa076e063c17d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
try:
    import lupa.luajit2 as lupa
except ImportError:
    try:
        import lupa.lua54 as lupa
    except ImportError:
        try:
            import lupa.lua53 as lupa
        except ImportError:
            import lupa

print(
    f"Using {lupa.LuaRuntime().lua_implementation} (compiled with {lupa.LUA_VERSION})"
)

from lupa import LuaRuntime

lua = LuaRuntime(unpack_returned_tuples=True)
import os


def get_Dice_Dir():
    return os.path.dirname(os.path.abspath("__file__"))


lua.globals().getDiceDir = get_Dice_Dir
lua.globals().package.path = (
    lua.globals().package.path
    + ";"
    + os.path.join(get_Dice_Dir(), "?.lua")
    + ";"
    + os.path.join(get_Dice_Dir(), "?.dll")
    + ";"
    + os.path.join(os.path.dirname(os.path.abspath(__file__)), "?.lua")
    + ";"
    + os.path.join(os.path.dirname(os.path.abspath(__file__)), "?.dll")
)

try:
    lua.execute(
        """\
    print()
    print(getDiceDir())
    print()
    print(package.path)
    js = require('json')
    print()
    print(js)
            """
    )
except Exception as e:
    print(f"{e!r}")