gh-1006: Menu.SetItemExtendedData#1024
Conversation
|
Hi @MKadaner, Did you try Copilot? Here is a result (see below 2 solutions to convert table to key/value arguments): Accepting a table for extended data Modify Menu.SetItemExtendedData to accept either the existing vararg key/value form or a single table for the data. Detect the argument type and normalize to a table inside the function. Backward compatibility and notes Then: The built-in Far Manager Lua macro API does not automatically convert a single table into the keyed varargs form — you must pass the data in the form the API expects or convert your table to key/value varargs before calling Menu.SetItemExtendedData. Far’s API functions that accept key/value pairs from Lua are usually implemented to receive varargs, not a single table. If the C-side (or existing Lua wrapper) does not explicitly detect and accept a table, calling Menu.SetItemExtendedData(hDlg, pos, { Line = 496, Position = 28, Length = 6 }) will not work as-is. Two simple options
Use a small helper that flattens the table into alternating key/value arguments and call the API with table.unpack: local data = { Line = 496, Position = 28, Length = 6 } This requires no changes to Far or to existing API wrappers and preserves backward compatibility. If you can add a small Lua wrapper function in your macros library, normalize both calling forms and forward to the API: This keeps old code working and gives you the nicer table call everywhere else. If you are writing or can modify the C-side binding or existing Lua wrapper for Menu.SetItemExtendedData, implement the normalization there (detect a single table argument and convert it to key/value pairs). That is the cleanest solution but requires changing the API wrapper code. If you cannot change the API implementation, add the small Lua wrapper (option 2). If you can change the API, add table acceptance at the wrapper layer so both forms are supported natively. |
|
Thank you, yulian5. It seems to be a correct solution for a wrong problem. |
|
@MKadaner, I tried to help and used PR description. What did I understand wrong? |
|
@yulian5, here I am actually "writing ... the C-side binding" for Other suggestions of our artificial friend are as obvious as they are awkward. Having Lua wrappers transforming tables to KVPs is not an option, mostly from aesthetics perspective. |
055a099 to
1cdd1f4
Compare
26a03ff to
13694f6
Compare
I couldn't get this to work. Maybe I'm not doing it right. After calling |
I apologize. I've spent too much time in this feature, so it's all obvious to me, and I failed to clearly specify the expected behavior. What you observed is exactly what is implemented. The new Lua function sets the extended data, it is observable with So, I would say everything works. Thank you very much for testing. To add some details. The appearance of the menu item is not affected by P.S. BTW, these should work as well: -- Current menu
Menu.SetItemExtendedData(SelectPos, { Line = 496, Position = 28, Length = 6 })
-- Currently selected item
Menu.SetItemExtendedData(FarDialogEvent.hDlg, { Line = 496, Position = 28, Length = 6 })
-- Currently selected item in the current menu
Menu.SetItemExtendedData({ Line = 496, Position = 28, Length = 6 }) |
8fa887d to
6b3ddb2
Compare
|
I added a comment explaining enigmatic All other |
|
|
@rohitab, may I ask you to kindly remind the motivation for It would also be great if you could share the macro we discussed in #1006 and which inspired this new function, so that the maintainer could get better idea of what functionality cannot be properly supported without |
04d2e9b to
353ea6b
Compare
|
Minor updates according to offline discussion with @zg0, rebased to master, and adjusted changelogs and versions. Ready for review. |
353ea6b to
aa0215b
Compare
At the annual Worldwide FAR Manager Developers Conference? :) |
aa0215b to
ed18794
Compare
1. FarGroupgh-1006: Macro API to set menu item extended data: `Menu.SetItemExtendedData`. 2. Updated `Edit.SyncEditorAndFindAllMenu.lua` to demonstrate usage of this API.
ed18794 to
5180a05
Compare
|
|
Thank you |
|
Thank you! |



Summary
Added Lua API
B=Menu.SetItemExtendedData([hDlg,][N,]T).Also, updated
Edit.SyncEditorAndFindAllMenu.luato demonstrate usage of this API.References
Checklist
If not checked, I accept that this work might be rejected in favor of a different great big ineffable plan.
Details
The implementation is ready for review, complete with the support in the Editor. Special thanks to @shmuz for the great help with passing Lua tables as parameters to native functions, and to @zg0 for the suggested improvements.
Now, one can write in Lua:
@rohitab, could you please test the new function with your macro?
@alabuzhev, could you please look at Editor and VMenu?