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
Add a data argument to menus #202
Conversation
…hanges added back in.
…d (even for compiling) because I don't have a new enough compiler on this machine. Will try compiling from Linux.
…teDataMenu is correct, though.
…vailable. Also update return type of CreateMenuEx and CreateDataMenuEx, plus update CreateDataMenuEx to treat it as a menu.
You're going to hate me for this - but I was crossing my fingers and praying to the heavens we wouldn't take API extensions like this for 1.7. The reason is that passing opaque values is not compatible post-transitional-syntax, since there is no way to track the liveness of the value. To do that, we need an extension to the C++ SourcePawn API, and I was hoping to save that for 1.8 (though I could take a stab at it now). If the change was local to scripted API, it'd be easier to deal with. But changing the menu C++ API makes it more troublesome, since we guarantee binary compatibility. |
@dvander Unfortunately, I can't really think of a way of doing it that wouldn't touch the C++ Menu API in some way. In this case, it's modifying IMenuStyle's CreateMenu and adding a convenience method to IBaseMenu (which could just as easily be a stock in the .inc), but the alternative was to have Get and Set methods in IBaseMenu. Either way, the menu interface would be changed and the interface number presumably bumped. This is because the Interface isn't just used by extensions, but also internally by natives. Not adding this isn't a huge deal... but it was a requested feature on multiple occasions. On a site note... if we're discouraging opaque values in the 1.7 syntax, what is going to happen with CreateTimer / Timers in general which also pass in opaque values? |
An excellent question! Short answer, I don't have concrete plans yet, but basically the
The most important part is step 3. Without the new C++ API we can't do anything, but we can always define it ahead of time and just make it wrap the older functionality. |
I nearly forgot about this. Basically, this adds a data argument to
CreateMenu
,CreateMenuEx
, andCreateDataMenu
. This data argument is passed to MenuHandler and VoteResultCallback.There was some discussion of whether we wanted to let programmers assign the data variable after the fact, but it is my opinion that it should be created in the Menu constructor / CreateMenu call. Feel free to comment on this if you disagree.
This patch also changes the return type of
CreateMenuEx
andCreateDataMenu
toMenu
(it wasHandle
) as this prevents a warning when you try to assign the return value from one of these to aMenu
variable.This also adds
CreateDataMenuEx
which combinesCreateMenuEx
andCreateDataMenu
.Now, some notes as to the design of this: You'll note that the
IPluginContext
is saved when a menu is created. This is because mostHandle
types require the owner identity be passed in when you callFreeHandle
on them. You can see this behavior insmn_KillTimer
when a Timer has theTIMER_DATA_HNDL_CLOSE
flag.The
userData != NULL
check shouldn't be necessary as we always create aMenuUserData
struct, but I left it in just in case.