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
60 changes: 60 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
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, 5.5]
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
- if: runner.os == 'Linux'
run: luarocks --lua-version=${{ matrix.lua-version }} config | grep INC || echo " *INC* is not set!!!"
- if: runner.os == 'Linux' && matrix.lua-version == '5.5'
# env:
# PCDIR: "$(pkgconf lua5.5 --variable=pcfiledir)"
run: |
sudo apt-get install -y lua5.4 liblua5.4-dev
sudo cp /etc/luarocks/config-5.4.lua /etc/luarocks/config-5.5.lua
cat /etc/luarocks/config-5.5.lua
echo "---"
cat /etc/luarocks/config-5.1.lua || true
PCDIR="$(pkgconf lua5.5 --variable=pcfiledir)"
echo "--PCDIR: $PCDIR"
echo "--See the ERROR IN THE VERSION"
head -n 4 $PCDIR/lua5.5.pc # See the ERROR IN THE VERSION
echo "--Fix the ERROR IN THE VERSION"
luarocks --lua-version=5.5 path
sudo sed -i '/^version=5\.5\.\#define /c\version=5.5.0' $PCDIR/lua5.5.pc
head -n 4 $PCDIR/lua5.5.pc # Error fixed
# ---
echo "-- Set the LUA_INCDIR variable and check again"
mkdir -p $HOME/.luarocks # So we can set luarocks variables
luarocks --lua-version=5.5 config variables.LUA_INCDIR /usr/include/lua5.5
luarocks --lua-version=5.5 config | grep INC
sudo apt-get purge --yes lua5.5 liblua5.5-dev luarocks
sudo apt-get install --yes lua5.5 liblua5.5-dev luarocks
luarocks --lua-version=5.5 config | grep INC
- 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@v7
with:
python-version: 3.x
# - run: luarocks --lua-version=${{ matrix.lua-version }} install --local luacheck
# - run: $HOME/.luarocks/bin/luacheck
- 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 || sudo LUA_INCDIR=/usr/include/lua${{ matrix.lua-version }} luarocks --lua-version=${{ matrix.lua-version }} --local make
- run: luarocks --lua-version=${{ matrix.lua-version }} show lunatic-python
- run: luarocks --lua-version=${{ matrix.lua-version }} doc lunatic-python
- run: luarocks --lua-version=${{ matrix.lua-version }} test lunatic-python || true
- 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()
Loading