Bug 461135

Summary: Lua backend locks up on evaluate
Product: [Applications] cantor Reporter: hugeblank <hugeblank>
Component: lua-backendAssignee: Alexander Semke <alexander.semke>
Status: RESOLVED FIXED    
Severity: normal CC: alexander.semke
Priority: NOR    
Version First Reported In: 22.08.2   
Target Milestone: ---   
Platform: Arch Linux   
OS: Linux   
Latest Commit: Version Fixed In: 23.03
Sentry Crash Report:

Description hugeblank 2022-10-28 22:56:56 UTC
SUMMARY
When attempting to evaluate a command entry using the Lua backend, it locks up and doesn't evaluate. 

This potentially is a lack of documentation issue. I have no information on how the lua backend works besides it uses luajit. I don't know if there's any extra API extension to properly output or exit a command entry. The documentation panel is blank, all user input besides the search bar in the panel is greyed out. Further there's no example worksheets for the Lua backend available.

STEPS TO REPRODUCE
1. put any valid or invalid lua code into a command entry box
2. press "Evaluate Worksheet" button

OBSERVED RESULT
the ">>>" blinks green indefinitely

EXPECTED RESULT
some kind of output, either an error, or the printed output

SOFTWARE/OS VERSIONS
Operating System: Arch Linux
KDE Plasma Version: 5.26.2
KDE Frameworks Version: 5.99.0
Qt Version: 5.15.6
Kernel Version: 6.0.2-arch1-1 (64-bit)
Graphics Platform: Wayland
Processors: 16 × AMD Ryzen 7 2700X Eight-Core Processor
Memory: 31.3 GiB of RAM
Graphics Processor: AMD Radeon RX 6600 XT
Manufacturer: Micro-Star International Co., Ltd.
Product Name: MS-7C37
System Version: 1.0
Comment 1 Alexander Semke 2023-03-25 11:14:24 UTC
Git commit 3aa4202cfcd52cb6c335c4fda9957164c104d3e8 by Alexander Semke.
Committed on 25/03/2023 at 11:13.
Pushed by asemke into branch 'master'.

[lua] refactored and fixed the parsing of LuaJIT's output.

The current implementation doesn't work at all, the output of LuaJIT doesn't fit to the parsing logic (anymore) that was implemented initially.
The refactored code works and handles also multi-line commands where the tests were deactivated earlier for.
More testing and more investment is still probably required to cover more code syntax in Lua/LuaJIT.
This commit makes the lua backend in Cantor working now first, more improvements will come later.
FIXED-IN: 23.03

M  +1    -1    src/backends/lua/luabackend.cpp
M  +17   -4    src/backends/lua/luaexpression.cpp
M  +31   -107  src/backends/lua/luasession.cpp
M  +10   -16   src/backends/lua/luasession.h
M  +54   -19   src/backends/lua/testlua.cpp
M  +2    -6    src/backends/lua/testlua.h

https://invent.kde.org/education/cantor/commit/3aa4202cfcd52cb6c335c4fda9957164c104d3e8
Comment 2 Alexander Semke 2023-03-25 11:23:50 UTC
(In reply to hugeblank from comment #0)
> SUMMARY
> When attempting to evaluate a command entry using the Lua backend, it locks
> up and doesn't evaluate. 
> 
> This potentially is a lack of documentation issue. I have no information on
> how the lua backend works besides it uses luajit. I don't know if there's
> any extra API extension to properly output or exit a command entry. The
> documentation panel is blank, all user input besides the search bar in the
> panel is greyed out. Further there's no example worksheets for the Lua
> backend available.
Thanks for reporting this problem. It was an implementation issue. This code was unmaintained, I picked up the work and I'll spend more time in the next days for Lua in Cantor.
Comment 3 Alexander Semke 2023-03-29 06:29:24 UTC
Git commit 872008a2ca0a983adb49141dd7e866f549658176 by Alexander Semke.
Committed on 29/03/2023 at 06:26.
Pushed by asemke into branch 'release/23.04'.

Squash commit of multiple fixes that need to go into 23.04.

[tests] make initTestCase() in the base class a slot so it's properly found by QtTest
and skip two tests in Maxima and Python that are failing on CI right now,
will be activated once the underlying issue is fixed.

[tests] skip testInterrupt for python.

[lua] refactored and fixed the parsing of LuaJIT's output.

The current implementation doesn't work at all, the output of LuaJIT doesn't fit to the parsing logic (anymore) that was implemented initially.
The refactored code works and handles also multi-line commands where the tests were deactivated earlier for.
More testing and more investment is still probably required to cover more code syntax in Lua/LuaJIT.
This commit makes the lua backend in Cantor working now first, more improvements will come later.
Related: bug 465277
FIXED-IN: 23.03

[maxima] always trim the command string and remove line breaks and not only for plot commands so we get one single response in stdout from Maxima
instead of multiple outputs that we only partially handle. This addresses multiple issues with multi-line commands with $ and ; endings.
FIXED-IN: 23.03

Added changes that were forgotten in the previous two commits.

When using cantor in labplot, connectToShell() is called after widget() inDocumentationPanelWidget.
We need to add one more connect in connectToShell() so the actions are also working in labplot.

[octave] evaluate the option "integrate plots" on every expression execution and not only during the login
so the user doesn't need to restart Cantor if the options is being changed.

Previously, this option was evaluate at the very beginning and send to Octave via  set (0, "defaultfigurevisible","off")
during the login. In this commit we switch to figure('visible','on') and figure('visible','off') that are prepended to every expression
containing plot commands.

Also, we set the recommended version of Octave to 7.2 which is available for one year already.

[octave] restored the slot OctaveSession::processError() that was deleted in the previous commit.

M  +1    -1    src/backends/lua/luabackend.cpp
M  +17   -4    src/backends/lua/luaexpression.cpp
M  +31   -107  src/backends/lua/luasession.cpp
M  +10   -16   src/backends/lua/luasession.h
M  +64   -29   src/backends/lua/testlua.cpp
M  +2    -6    src/backends/lua/testlua.h
M  +10   -10   src/backends/maxima/maximaexpression.cpp
M  +1    -1    src/backends/maxima/maximasession.cpp
M  +57   -16   src/backends/maxima/testmaxima.cpp
M  +6    -2    src/backends/maxima/testmaxima.h
M  +1    -1    src/backends/octave/octavebackend.cpp
M  +13   -4    src/backends/octave/octaveexpression.cpp
M  +45   -65   src/backends/octave/octavesession.cpp
M  +5    -8    src/backends/octave/octavesession.h
M  +4    -4    src/backends/python/testpython.cpp
M  +3    -1    src/lib/test/backendtest.h
M  +6    -1    src/panelplugins/documentationpanel/documentationpanelplugin.cpp

https://invent.kde.org/education/cantor/commit/872008a2ca0a983adb49141dd7e866f549658176