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
205 changes: 205 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,205 @@
name: ci
on:
push:
pull_request:
workflow_dispatch:
jobs:
lua5_5_pc_typo:
# liblua5.5-dev installs a pkgconfig/lua5.5.pc file that contains a typo
# in the version that prevents `lib_name_include=lua5.5` from being set.
#
# Typo fix would be:
# ```diff
# - version=5.5.#define LUA_VERSION_RELEASE LUAI_TOSTR(LUA_VERSION_RELEASE_N)
# - lib_name_include=lua5.5
# + version=5.5.0
# + lib_name_include=lua5.5
# ```
#
# This causes the luarocks LUA_INCDIR variable to be undefined, which
# results in failures when calling `luarocks --lua-version=5.5 make`.
#
# `apt-get install luarocks` delivers v3.8.0, which should be updated
# to luarocks >= v3.13 to support lua5.5.
runs-on: ubuntu-26.04
env:
PCDIR: "/usr/lib/x86_64-linux-gnu/pkgconfig"
steps:
- run: |
echo "${{ runner.os }} on ${{ runner.arch }}"
sudo apt-get update
- run: sudo apt-get install --yes lua5.4 liblua5.4-dev lua5.5 liblua5.5-dev luarocks
- name: liblua5.5-dev installs pkgconfig/lua5.5.pc with a TYPO IN THE VERSION
run: |
echo "-- head lua5.4.pc looks good:"
head -n 4 $PCDIR/lua5.4.pc || true # No typo so LUA_INCDIR is set correctly
echo "-- head lua5.5.pc contains a typo in the version:"
head -n 4 $PCDIR/lua5.5.pc # Version typo prevents LUA_INCDIR from being set
echo "-- Above '#define LUA_VERSION_RELEASE LUAI_TOSTR(LUA_VERSION_RELEASE_N)' should be '0'!!!"

echo "-- pkgconfig gets the correct 'includedir' and 'lib_name_include' values"
echo "$(pkgconf lua5.4 --variable=includedir)$(pkgconf lua5.4 --variable=lib_name_include)"
echo "$(pkgconf lua5.5 --variable=includedir)$(pkgconf lua5.5 --variable=lib_name_include)"
# pkgconf lua5.4 --variable=includedir --variable=lib_name_include || echo "/usr/include/ and lua5.4"
# pkgconf lua5.5 --variable=includedir --variable=lib_name_include || echo "/usr/include/ and lua5.5"

echo "-- But `luarocks --lua-version=5.5 config` does not have a LUA_INCDIR variable..."
echo "-- Check the luarocks LUA_INCDIR and INCFILE variables for Lua 5.4 and Lua 5.5"
luarocks --lua-version=5.4 config | grep LUA || echo " LUA_INC* is not set for Lua 5.4"
echo "-----"
luarocks --lua-version=5.4 config | grep LUA_INC || echo " LUA_INC* is not set for Lua 5.4"
luarocks --lua-version=5.5 config | grep LUA_INC || echo " LUA_INCDIR is not set for Lua 5.5!!!"
echo "-- DONE???"

echo "-- pkgconfig/lua5.5.pc has TYPO IN THE VERSION that prevents the definition of include*"
pkgconf lua5.5 --variable=includedir --variable=lib_name_include || echo "/usr/include/ and lua5.5"

pkgconf lua5.4 --variable=includedir || echo "lua5.4 is not installed -- lua5.4.0"
pkgconf lua5.4 --variable=lib_name_include || echo "lua5.5 is not installed -- lua5.5.0"
pkgconf lua5.5 --variable=includedir || echo "lua5.4 is not installed -- lua5.4.0"
pkgconf lua5.5 --variable=lib_name_include || echo "lua5.5 is not installed -- lua5.5.0"

echo "-- The typo seems to cause `luarocks --lua-version=5.5 config` to not have a LUA_INCDIR"
echo "-- See the value before and after setting it"
pkgconf lua5.4 --print-variables | grep include || echo "lua5.4 is not installed -- /usr/include/lua5.4"
pkgconf lua5.5 --print-variables | grep include || echo "lua5.5 is not installed -- /usr/include/lua5.5"

echo "-- There is a comment in the version line that comments out the next line"
pkgconf lua5.5 --variable=version
head -n 4 $PCDIR/lua5.5.pc # See the TYPO IN THE VERSION
pkgconf lua5.5 --variable=includedir # Nothing!

echo "--Fix the typo"
sudo sed -i '/^version=5\.5\.\#define /c\version=5.5.0' $PCDIR/lua5.5.pc
head -n 4 $PCDIR/lua5.5.pc # Typo fixed

echo "-- See the pkgconf value includedir before and after setting it"
pkgconf lua5.4 --variable=includedir
pkgconf lua5.5 --variable=includedir
pkgconf lua5.5 --define-variable=includedir="/usr/include/lua5.5"
pkgconf lua5.4 --variable=includedir
pkgconf lua5.5 --variable=includedir

echo "-- Now we can install luarocks and set LUA_INCDIR for Lua 5.5"
sudo apt-get install --yes luarocks

echo "-- Check the luarocks LUA_INCDIR and INCFILE variables for Lua 5.4 and Lua 5.5"
luarocks --lua-version=5.4 config | grep LUA_INC || echo "LUA_INC* is not set for Lua 5.4"
luarocks --lua-version=5.5 config | grep LUA_INC || echo "LUA_INC* is not set for Lua 5.5"

echo "-- Set the 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 LUA_INCDIR

- name: Use sed to fix the typo in pkgconfig/lua5.5.pc
run: |
sudo sed -i '/^version=5\.5\.\#define /c\version=5.5.0' $PCDIR/lua5.5.pc
head -n 4 $PCDIR/lua5.5.pc # Typo is fixed
- name: Use luarocks to check LUA_INCDIR for Lua 5.4 and Lua 5.5
run: |
echo "-- luarocks setting for Lua 5.4:"
luarocks --lua-version=5.4 config | grep LUA # LUA_INCDIR is set for Lua 5.4
echo "-- luarocks setting for Lua 5.5 do not have a LUA_INCDIR:"
luarocks --lua-version=5.5 config | grep LUA # LUA_INCDIR is NOT set for Lua 5.5
- name: Use luarocks to set LUA_INCDIR for 5.5
run: |
mkdir -p $HOME/.luarocks
luarocks --lua-version=5.5 config variables.LUA_INCDIR /usr/include/lua5.5
luarocks --lua-version=5.5 config | grep LUA # LUA_INCDIR is now set for Lua 5.5
- run: |
echo "`luarocks --lua-version=5.5 make` may still fail with:"
echo "# Error: Lua header mismatches configured version. You may need to install them or configure LUA_INCDIR."

lua5_5_pc_typo_fix:
# liblua5.5-dev installs a pkgconfig/lua5.5.pc file that contains a typo in the
# version that prevents `lib_name_include=lua5.5` from being set.
#
# ```diff
# - version=5.5.#define LUA_VERSION_RELEASE LUAI_TOSTR(LUA_VERSION_RELEASE_N)
# - lib_name_include=lua5.5
# + version=5.5.0
# + lib_name_include=lua5.5
# ```
#
# This causes the luarocks LUA_INCDIR variable to be undefined, which results
# in failures when calling `luarocks --lua-version=5.5 make`.
#
# luarocks is also v3.8.0, which should be updated to >= v3.13 to support lua5.5.
runs-on: ubuntu-26.04
env:
PCDIR: "/usr/lib/x86_64-linux-gnu/pkgconfig"
steps:
- run: echo "${{ runner.os }} on ${{ runner.arch }}"
- run: |
sudo apt-get update
sudo apt-get install --yes lua5.4 liblua5.4-dev lua5.5 liblua5.5-dev # NOT YET: luarocks
- run: |
echo "-- pkgconfig/lua5.5.pc has TYPO IN THE VERSION"
pkgconf lua5.4 --variable=version || echo "lua5.4 is not installed -- lua5.4.8"
pkgconf lua5.5 --variable=version || echo "lua5.5 is not installed -- lua5.5.0"

echo "-- pkgconfig/lua5.5.pc has TYPO IN THE VERSION that prevents the definition of include*"
pkgconf lua5.4 --variable=includedir || echo "lua5.4 is not installed -- lua5.4.0"
pkgconf lua5.4 --variable=lib_name_include || echo "lua5.5 is not installed -- lua5.5.0"
pkgconf lua5.5 --variable=includedir || echo "lua5.4 is not installed -- lua5.4.0"
pkgconf lua5.5 --variable=lib_name_include || echo "lua5.5 is not installed -- lua5.5.0"

echo "-- This also means that `luarocks --lua-version=5.5 config` does not have a LUA_INCDIR"
echo "-- See the value before and after setting it"
pkgconf lua5.4 --print-variables | grep include || echo "lua5.4 is not installed -- /usr/include/lua5.4"
pkgconf lua5.5 --print-variables | grep include || echo "lua5.5 is not installed -- /usr/include/lua5.5"

echo "-- There is a comment in the version line that comments out the next line"
pkgconf lua5.5 --variable=version
head -n 4 $PCDIR/lua5.5.pc # See the TYPO IN THE VERSION
pkgconf lua5.5 --variable=includedir # Nothing!

echo "--Fix the typo"
sudo sed -i '/^version=5\.5\.\#define /c\version=5.5.0' $PCDIR/lua5.5.pc
head -n 4 $PCDIR/lua5.5.pc # Typo fixed

echo "-- See the pkgconf value includedir before and after setting it"
pkgconf lua5.4 --variable=includedir
pkgconf lua5.5 --variable=includedir
pkgconf lua5.5 --define-variable=includedir="/usr/include/lua5.5"
pkgconf lua5.4 --variable=includedir
pkgconf lua5.5 --variable=includedir

echo "-- Now we can install luarocks and set LUA_INCDIR for Lua 5.5"
sudo apt-get install --yes luarocks

echo "-- Check the luarocks LUA_INCDIR and INCFILE variables for Lua 5.4 and Lua 5.5"
luarocks --lua-version=5.4 config | grep LUA_INC || echo "LUA_INC* is not set for Lua 5.4"
luarocks --lua-version=5.5 config | grep LUA_INC || echo "LUA_INC* is not set for Lua 5.5"

echo "-- Set the 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 LUA_INCDIR

- name: liblua5.5-dev installs pkgconfig/lua5.5.pc with a TYPO IN THE VERSION
run: |
echo "-- head lua5.4.pc looks good:"
head -n 4 $PCDIR/lua5.4.pc || true # No typo so LUA_INCDIR is set correctly
echo "-- head lua5.5.pc contains a typo in the version:"
head -n 4 $PCDIR/lua5.5.pc # Version typo prevents LUA_INCDIR from being set
- name: Use sed to fix the typo in pkgconfig/lua5.5.pc
run: |
sudo sed -i '/^version=5\.5\.\#define /c\version=5.5.0' $PCDIR/lua5.5.pc
head -n 4 $PCDIR/lua5.5.pc # Typo is fixed
- name: Use luarocks to check LUA_INCDIR for Lua 5.4 and Lua 5.5
run: |
echo "-- luarocks setting for Lua 5.4:"
luarocks --lua-version=5.4 config | grep LUA # LUA_INCDIR is set for Lua 5.4
echo "-- luarocks setting for Lua 5.5 do not have a LUA_INCDIR:"
luarocks --lua-version=5.5 config | grep LUA # LUA_INCDIR is NOT set for Lua 5.5
- name: Use luarocks to set LUA_INCDIR for 5.5
run: |
mkdir -p $HOME/.luarocks
luarocks --lua-version=5.5 config variables.LUA_INCDIR /usr/include/lua5.5
luarocks --lua-version=5.5 config | grep LUA # LUA_INCDIR is now set for Lua 5.5
- run: |
echo "`luarocks --lua-version=5.5 make` may still fail with:"
echo "# Error: Lua header mismatches configured version. You may need to install them or configure LUA_INCDIR."

59 changes: 35 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,68 @@
>>> 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'")
# >>> python = lua.eval("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