BugFix: multiple issues with TKey creation from lua script commands#1069
BugFix: multiple issues with TKey creation from lua script commands#1069vadi2 merged 6 commits intoMudlet:developmentfrom
Conversation
Bug fixes for issue(s) raised in: Mudlet#1068 * in TLuaInterpreter::permKey(...) corrected luaL_typename(...) calls to refer to correct argument instead of hard-coded 1. * in TLuaInterpreter::permKey(...) and tempKey(...) corrected tests for strings for optional third and required fourth to be the number ones as that is what we want them to be interpreted as; edited the type error message to match; revised the error message to the keyModifier argument to refere to it as optional as it is! * in TLuaInterpreter::tempKey(...) forced the error message generation to no longer be subject to potential translation efforts following the decision already implemented elsewhere in the class NOT to I18n these texts. * in TLuaInterpreter::permKey(...) and tempKey(...) added missing argument number from error messages for cases where the number is a run-time variable rather than a compile time constant. * in TLuaInterpreter::permKey(...) corrected the swap of keyModifier and keyCode in the call to TLuaIntepreter::startPermKey(...) * in TLuaInterpreter::tempKey(...) refactored the luaScript variable to be a QString all the way through and to explicitly retrieve it from the Lua sub-system as UTF-8 text with a QString::fromUtf8(...) call whereas the previous std::string::c_str() as an argument to a plain QString() constructor will fail in the future if/when the QT_NO_CAST_FROM_ASCII macro is #define-d. * As a separate issue I found that the code that checks for TKeys being matched on user text input was defective as it only ran the first match that was found instead of running all - this needed a revision to (bool) KeyUnit::processDataStream(int, int) ... * I have run clang-format over the code that I have touched. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
src/KeyUnit.cpp
Outdated
|
|
||
| bool KeyUnit::processDataStream(int key, int modifier) | ||
| { | ||
| bool isAtLeastOneMatch = false; |
There was a problem hiding this comment.
Sorry - but changing the core behaviour of how keybindings work is not in scope of #1068 at all nor do I want to have a discussion on changing the behaviour on the last day PRs can go into a release. Could you move this to a separate PR for the next release?
src/TLuaInterpreter.cpp
Outdated
| int n = lua_gettop( L ); | ||
| int i = 3; | ||
|
|
||
| quint8 argIndex = 0; |
There was a problem hiding this comment.
C++11 adds a type for this, so we have no need to use the Qt workaround - this stuff is minor so I'll just submit a commit to your branch in the interests of saving time, let me know if you disagree!
|
This works now 😁 permKey("my key", "", mudlet.keymodifier.Control, mudlet.key.F8, [[echo("hey this thing actually works!\n")]])So does this: lua permKey("my key", "", mudlet.key.F8, [[echo("aaaa this thing actually works!\n")]])This does not 😞 If it's optional and you give it nil... it should work! |
It's far too late in the release schedule to be changing this - let's discuss it next time
vadi2
left a comment
There was a problem hiding this comment.
I've applied the changes I'd like to see so we can get this in quicker instead of doing the usual back and forth that goes on for days - merge if you're okay with the changes.
To my mind optional means "you do not have to put anything there", putting in a nil is something, even if it is nothing 😖 - remember the test to determine the situation is based on |
| int TLuaInterpreter::permKey( lua_State *L ) | ||
| { | ||
| quint8 argIndex = 0; | ||
| uint_fast8_t argIndex = 0; |
There was a problem hiding this comment.
It wasn't intended as a "work_around" it was just that I anticipated the maximum number of bits and was willing to be explicit about it instead of just having the generic int and the Qt types are well defined (and will likely now be typedefed to the longer typename of C++1x auto-magically anyhow)...
As it happened I was going to change the keyModifier and keyCode to be quint64 rather than intas I remember that the Qt Clang-analyser plugin does not like assigning the value of lua_tointeger(...)to it but that would be disruptive as it means changing some reference passing of arguments to other functions.
(I have the analyser switched off currently as it is a CPU hog but it gets upset because lua_interpreter(...) returns a long rather than an int on some/all platforms and that is iffy on Windows IIRC...)
| } | ||
|
|
||
| return isAtLeastOneMatch; | ||
| return false; |
There was a problem hiding this comment.
Hang on, the Wiki currently says:
Note: Mudlet by design allows duplicate names - so calling permKey [or tempkey] with the same name [code and modifier] will keep creating new keys. You can check if a key already exists with the exists() function.
It does not say "but only the first one of any code and modifier combination of either permanent or temporary Keys" will work and the remainder will be ignored...! So if you create a key of either type and drop in buggy lua code and then correct it and call the same command again you will have two instances and only the first, buggy one is going to be (and fail to) run. That is not conforming to "principle of least surprise" IMHO.
There was a problem hiding this comment.
That is an edge case scenario. Principle of least surprise is when you press a button and don't get 50 keys going off :)
There was a problem hiding this comment.
As someone who did enter lua permKey("my key", "", mudlet.keymodifier.Control, mudlet.key.F8, [[echo("hey this thing actually works!\n")]]) several times with different function strings to test it I was surprised when I didn't get several Keys going off - especially as they all showed in the Editor (after refreshing the contents).
Not sure what the prioritization is but if a script puts up a tempKey and I then enter one in the editor with the same key+modifier combination will my (effectively a permKey) ever run? IIRC the temporary ones do not show but are given priority (I could easily be rong on that I know) but that must surely be confusing even if it is a corner case...
|
If we are going to roll out (as a "Squash and Merge" I think) this PR out as it is now and defer the "only the first Key+Modifier will ever be run" bug-fix then I think we should mention it as something in the Wiki as a defect that was/will be fixed in Release 3.2++ |
You're confusing
|
|
Changing the core behaviour of how keybindings have worked in Mudlet for the last 8 years will umm we can discuss it but lets hold off on calling it a "bug" for now please! We also have about zero reports from users that it's a problem, unlike the 300+ bugs we have sitting in the queue already. |
|
|
Bug fixes for issue(s) raised in: #1068
in
TLuaInterpreter::permKey(...)correctedluaL_typename(...)calls to refer to correct argument instead of hard-coded1.in
TLuaInterpreter::permKey(...)andtempKey(...)corrected tests for strings for optional third and required fourth to be the number ones as that is what we want them to be interpreted as; edited the type error message to match; revised the error message to thekeyModifierargument to refer to it as optional as it is!in
TLuaInterpreter::tempKey(...)forced the error message generation to no longer be subject to potential translation efforts following the decision already implemented elsewhere in the class NOT to I18n these texts.in
TLuaInterpreter::permKey(...)andtempKey(...)added missing argument number from error messages for cases where the number is a run-time variable rather than a compile time constant.in
TLuaInterpreter::permKey(...)corrected the swap ofkeyModifierandkeyCodein the call toTLuaIntepreter::startPermKey(...)in
TLuaInterpreter::tempKey(...)refactored theluaScriptvariable to be aQStringall the way through and to explicitly retrieve it from the Lua sub-system as UTF-8 text with aQString::fromUtf8(...)call whereas the previousstd::string::c_str()as an argument to a plainQString()constructor will fail in the future if/when theQT_NO_CAST_FROM_ASCIImacro is#define-d.As a separate issue I found that the code that checks for
TKeysbeing matched on user text input was defective as it only ran the first match that was found instead of running all - this needed a revision to(bool) KeyUnit::processDataStream(int, int)...I have run clang-format over the code that I have touched.
Signed-off-by: Stephen Lyons slysven@virginmedia.com