| 06-10-2009, 03:01 AM | #1 |
With return-bug cast deprecated, and blizzard not supporting explicit cast, widget event responses became difficult to use. This library is designed to deal with such problem by using hashtable as a converter medium. This script requires 1.23b or later. JASS:library TypeConverter initializer init // This library provides typesafe conversion between widget and its childs. // Functions will return null if conversion is not applicable. // ==================================================== // Version: 1.0 // Author: ToukoAozaki // Required minimum Warcraft III version: 1.23b globals private hashtable ht endglobals // converts widget to item function WidgetToItem takes widget w returns item call SaveWidgetHandle(ht, 0, 0, w) return LoadItemHandle(ht, 0, 0) endfunction // converts widget to unit function WidgetToUnit takes widget w returns unit call SaveWidgetHandle(ht, 0, 0, w) return LoadUnitHandle(ht, 0, 0) endfunction // converts widget to destructable function WidgetToDestructable takes widget w returns destructable call SaveWidgetHandle(ht, 0, 0, w) return LoadDestructableHandle(ht, 0, 0) endfunction private function init takes nothing returns nothing set ht = InitHashtable() endfunction endlibrary |
| 06-10-2009, 03:07 AM | #2 |
You know, I'm pretty sure this exact typecasting is the whole thing Blizzard is trying to remove with this patch. |
| 06-10-2009, 03:19 AM | #3 | |
Quote:
This is not an unsafe typecast. unit, item and destructable are child type of widgets. Almost every language that support upcast also support downcast, and every language should. However, Jass2 never had capability to downcast while upcast has been possible. Also note that there is a Blizzard safety layer on the hashtable. This library is not bypassing it; that behavior is by design. Blizzard uses internal type metadata, not the type when the handle is stored. If the widget is not an item then WidgetToItem will return null. |
| 06-10-2009, 05:02 AM | #4 |
I see. Anyways, I don't like your function names; might I suggest W2I, W2U, and W2D? |
| 06-10-2009, 05:05 AM | #5 |
I like these function names, W2U, W2D and W2I sound like return bug exploiters. |
| 06-10-2009, 05:06 PM | #6 |
Wait, this one-line-return is considered as a return bug ? common.j:constant native GetTriggerWidget takes nothing returns widget blizzard.j:function GetDyingDestructable takes nothing returns destructable return GetTriggerWidget() endfunction I can't download the beta patch so i can't take a look in the new blizzard.j If not, then this script is useless. |
| 06-10-2009, 05:24 PM | #7 | |
Quote:
JASS:function GetDyingDestructable takes nothing returns destructable return GetTriggerDestructable() endfunction This is their new implementation. Seems that they have added GetTriggerDestructable native. However I am not sure whether this native returns properly for every widget events. Practically conversion for destructable wouldn't be needed. However, I see no reason that they shouldn't exist as a set. What if one decides to use widget arrays or pass parameter as a widget... |
| 06-10-2009, 10:50 PM | #8 |
Approved BTW. |
| 06-11-2009, 03:02 AM | #9 | |
Quote:
|
