Skip to content

Some lua code doesnt work or work improperly #3

Open

Description

@inceptorprogrammer

Some lua code doesnt work or work improperly

so far all tests i've tried with the lua 5.1 testsuite have failed either because it didnt work or worked improperly

How to replicate:
Download the lua 5.1 testsuite
Download cli-python-lua
Make sure to enable all the features or the features you need in python-lua with cli-python-lua
Run one of the lua tests using cli-python-lua

Activity

  1. inceptorprogrammer commented on May 31, 2025

    @inceptorprogrammer
    Author

    You can also do os.execute and io.popen and they wont work

  2. wijnen commented on Jun 7, 2025

    @wijnen
    Owner

    Hi,

    Thanks for your interest in the project. I have recently been making quite a few changes to the project. I may have fixed some of the things you encountered. However, I didn't check everything you wrote yet.

    What I can say is this:

    • The C code that was in there, was the start of my work to port the entire project to C. I have just made that work properly, and it is now the way it should be used.
    • The code no longer supports choosing your own Lua version (and perhaps it didn't when you tested it; that may have been the issue). It now only supports Lua 5.4.
    • Porting to other Lua versions (and probably also other variants such as Luau) is likely pretty easy (just link to the other Lua library), but possibly it requires some changes to the code. I didn't check.
    • Your cli-python-lua code contains some bugs, which may be the cause of (some of) the test failures. I may report them there if I have time.

    The new code has a test script included, which tests most of the possible interactions between Lua and Python. You can use it as an example for how things should work.

    Please let me know if things work properly for you, and also if they don't.

  3. inceptorprogrammer commented on Jun 7, 2025

    @inceptorprogrammer
    Author

    let me see if the lua 5.4 testsuite works

  4. inceptorprogrammer commented on Jun 7, 2025

    @inceptorprogrammer
    Author

    the main.lua test fails in the lua 5.4 test suite using cli-python-lua with ValueError: [string "# testing special comment on first line..."]:1: unexpected symbol near '#'

  5. inceptorprogrammer commented on Jun 7, 2025

    @inceptorprogrammer
    Author

    also the sort.lua test in the lua 5.4 testsuite fails because of File "", line 322, in decode
    UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe1 in position 7892: invalid continuation byte
    if i'm correct

  6. inceptorprogrammer commented on Jun 7, 2025

    @inceptorprogrammer
    Author

    You can replicate these by downloading the lua 5.4.0 test suite and running it using cli-python-lua

  7. inceptorprogrammer commented on Jun 7, 2025

    @inceptorprogrammer
    Author

    however this is all being done with a old version of python-lua and cli-python-lua so let me try it on a newer version

  8. inceptorprogrammer commented on Jun 7, 2025

    @inceptorprogrammer
    Author

    python-lua still fails on main.lua and sort.lua on the lua 5.4.0 testsuite with the same errors

  9. wijnen commented on Jun 8, 2025

    @wijnen
    Owner

    the main.lua test fails in the lua 5.4 test suite using cli-python-lua with ValueError: [string "# testing special comment on first line..."]:1: unexpected symbol near '#'

    This is a problem with your script. When you say that you are running a file, you are really reading the file into a string and running that.

    Lua only support a first line starting with # when running a file, not when running a string. So because you are running it as a string, the error is expected and correct.

    The solution is to use the Lua.run_file() function instead of the Lua.run() function.

  10. wijnen commented on Jun 8, 2025

    @wijnen
    Owner

    also the sort.lua test in the lua 5.4 testsuite fails because of File "", line 322, in decode UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe1 in position 7892: invalid continuation byte if i'm correct

    This is also a problem with your code. You are reading the contents of the file as text, which means Python will parse the contents of the file as UTF-8. If the file isn't valid UTF-8 (as is the case with sort.lua), it will result in an error. Note that this error happens before calling Lua.run(), so it is obviously not in my code.

    There are two possible solutions for this. The first is to use Lua.run_file(), because that will correctly parse the non-UTF-8 file. The other is to send a bytes object instead of a str. However, that second option is currently not supported. I think I will add support for it in the future, because it seems like a nice feature to support.

  11. wijnen commented on Jun 8, 2025

    @wijnen
    Owner

    I have implemented it right away. :-) The current code supports running bytes objects as well.

  12. inceptorprogrammer commented on Jun 8, 2025

    @inceptorprogrammer
    Author

    I didn't know Lua.run_file() existed thanks for telling me I'll rewrite my code and try the lua 5.4 testsuite again

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions