-
Notifications
You must be signed in to change notification settings - Fork 226
gh-1006: Menu.SetItemExtendedData
#1024
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
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. |
bf1a40c to
768c494
Compare
055a099 to
1cdd1f4
Compare
|



Summary
POC implementation of
Menu.SetItemExtendedDataLua function.References
Checklist
If not checked, I accept that this work might be rejected in favor of a different great big ineffable plan.
Details
This is a proof-of-concept implementation of a new Lua function
Menu.SetItemExtendedData. It works except for, instead of getting extended data as a table, it takes multiple parameters representing keys and values. So, instead ofone has to write
which is, of course, totally unacceptable.
The function is implemented this awkward way because, I believe, currently there is no way to pass a table parameter using Lua macro API.
I hope @shmuz or @zg0 can help me with adding table support.