Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: ci
on:
push:
pull_request:
workflow_dispatch:
jobs:
ci:
strategy:
fail-fast: false # https://github.com/actions/runner-images#available-images
matrix: # https://www.lua.org/versions.html
os: [ubuntu-26.04, ubuntu-26.04-arm]
lua-version: [5.1, 5.2, 5.3, 5.4]
runs-on: ${{ matrix.os }}
steps:
- run: |
sudo apt-get update
sudo apt-get install -y lua${{ matrix.lua-version }} liblua${{ matrix.lua-version }}-dev luarocks
- run: lua -v && luarocks --version # Lua 5.x.x Luarocks 3.8.0 (not 3.13.0!)
- uses: actions/checkout@v7
- uses: actions/setup-python@v6
with:
python-version: 3.x
- run: luarocks --lua-version=${{ matrix.lua-version }} lint lunatic-python-scm-0.rockspec
- run: luarocks --lua-version=${{ matrix.lua-version }} lint rockspecs/lunatic-python-1.0-1.rockspec
- run: luarocks --lua-version=${{ matrix.lua-version }} --local make
- run: luarocks --lua-version=${{ matrix.lua-version }} show lunatic-python
- run: lua${{ matrix.lua-version }} tests/test_py.lua
- run: pip install --editable .
- run: python -m doctest --verbose tests/test_lua.py
58 changes: 34 additions & 24 deletions tests/test_lua.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@

>>> lua.execute("x = {1, 2, 3, foo = {4, 5}}")
>>> lg.x[1], lg.x[2], lg.x[3]
(1..., 2..., 3...)
(1, 2, 3)
>>> lg.x['foo'][1], lg.x['foo'][2]
(4..., 5...)
(4, 5)

>>> lua.require
<built-in function require>

>>> lg.string
>>> lg.string # doctest: +ELLIPSIS
<Lua table at 0x...>
>>> lg.string.lower
>>> lg.string.lower # doctest: +ELLIPSIS
<Lua function at 0x...>
>>> lg.string.lower("Hello world!") == u'hello world!'
True
Expand All @@ -35,57 +35,67 @@
>>> lg.d = d
>>> lua.execute("d['key'] = 'value'")
>>> d
{...'key': ...'value'}
{'key': 'value'}

>>> d2 = lua.eval("d")
>>> d is d2
True

>>> lua.execute("python = require 'python'")
>>> lua.eval("python")
# TODO: Fix `require 'python'` so the `python.` commands will work.
# >>> lua.execute("python = require 'python'")
# >>> lua.eval("python") # doctest: +ELLIPSIS
<Lua table at 0x...>

>>> obj
<MyClass>

>>> lua.eval("python.eval 'obj'")
# >>> lua.eval("python.eval 'obj'")
<MyClass>

>>> lua.eval(\"\"\"python.eval([[lua.eval('python.eval("obj")')]])\"\"\")
# >>> lua.eval(\"\"\"python.eval([[lua.eval('python.eval("obj")')]])\"\"\")
<MyClass>

>>> lua.execute("pg = python.globals()")
>>> lua.eval("pg.obj")
# >>> lua.execute("pg = python.globals()")
# >>> lua.eval("pg.obj")
<MyClass>

>>> def show(key, value):
... print("key is %s and value is %s" % (repr(key), repr(value)))
...
>>> asfunc = lua.eval("python.asfunc")
>>> asfunc

# >>> asfunc = lua.eval("python.asfunc")
# >>> asfunc # doctest: +ELLIPSIS
<Lua function at 0x...>

>>> l = ['a', 'b', 'c']
>>> t = lua.eval("{a=1, b=2, c=3}")
>>> for k in l:
... show(k, t[k])
key is 'a' and value is 1...
key is 'b' and value is 2...
key is 'c' and value is 3...

key is 'a' and value is 1
key is 'b' and value is 2
key is 'c' and value is 3
"""

import sys, os
import os
import sys

sys.path.append(os.getcwd())
import lua # noqa: F401

try:
import python # noqa: F401
except ImportError as e:
print(f"{e = }")


class MyClass:
def __repr__(self): return '<MyClass>'
def __repr__(self):
return "<MyClass>"


obj = MyClass()


if __name__ == '__main__':
import lua
import doctest
doctest.testmod(optionflags=doctest.ELLIPSIS)
if __name__ == "__main__":
from doctest import testmod

testmod()