Vanilla JASS Table

Level 33
Joined
Apr 24, 2012
Messages
5,113
Sometime ago I deleted some of my resources which doesn't use Unit Indexer and instead used my own indexing method (our indexing method). This is allocating ofc.

But the flaws of those resources is that they must have a much faster lookup, so that it won't have to iterate the lists everytime it has to lookup an index.

Solution is that I have to create a hashtable, but It seems to be expensive just for a lookup, so I decided to create this monstrosity:
JASS:
//*************************************************************************************
//*
//*     Table by Almia
//*
//*     Vanilla JASS Implementation of Bribe's Table
//*
//*************************************************************************************
//*
//*     API
//*
//*     function InitTable takes nothing returns boolean
//*         - Initialize System, optional
//*     function CreateTable takes nothing returns integer
//*         - Creates table instance
//*     function IsTable takes integer i returns boolean
//*         - Checks if instance is a table
//*     function FlushTable takes integer t returns nothing
//*         - Flushes table memory
//*     function DestroyTable takes integer t returns nothing
//*         - Destroys table
//*
//*     SAVE API
//*
//*    function TableSaveInteger takes integer t, integer key, integer val returns nothing 
//*    function TableSaveReal takes integer t, integer key, real val returns nothing 
//*    function TableSaveBoolean takes integer t, integer key, boolean val returns nothing 
//*    function TableSaveStr takes integer t, integer key, string val returns nothing 
//*
//*    function TableSavePlayer takes integer t, integer key, player val returns nothing 
//*    function TableSaveWidget takes integer t, integer key, widget val returns nothing 
//*    function TableSaveDestructable takes integer t, integer key, destructable val returns nothing 
//*    function TableSaveItem takes integer t, integer key, item val returns nothing 
//*    function TableSaveUnit takes integer t, integer key, unit val returns nothing 
//*    function TableSaveAbility takes integer t, integer key, ability val returns nothing 
//*    function TableSaveTimer takes integer t, integer key, timer val returns nothing 
//*    function TableSaveTrigger takes integer t, integer key, trigger val returns nothing 
//*    function TableSaveTriggerCondition takes integer t, integer key, triggercondition val returns nothing 
//*    function TableSaveTriggerAction takes integer t, integer key, triggeraction val returns nothing 
//*    function TableSaveTriggerEvent takes integer t, integer key, event val returns nothing 
//*    function TableSaveForce takes integer t, integer key, force val returns nothing 
//*    function TableSaveGroup takes integer t, integer key, group val returns nothing 
//*    function TableSaveLocation takes integer t, integer key, location val returns nothing 
//*    function TableSaveRect takes integer t, integer key, rect val returns nothing 
//*    function TableSaveBooleanExpr takes integer t, integer key, boolexpr val returns nothing 
//*    function TableSaveSound takes integer t, integer key, sound val returns nothing 
//*    function TableSaveEffect takes integer t, integer key, effect val returns nothing 
//*    function TableSaveUnitPool takes integer t, integer key, unitpool val returns nothing 
//*    function TableSaveItemPool takes integer t, integer key, itempool val returns nothing 
//*    function TableSaveQuest takes integer t, integer key, quest val returns nothing 
//*    function TableSaveQuestItem takes integer t, integer key, questitem val returns nothing 
//*    function TableSaveDefeatCondition takes integer t, integer key, defeatcondition val returns nothing 
//*    function TableSaveTimerDialog takes integer t, integer key, timerdialog val returns nothing 
//*    function TableSaveLeaderboard takes integer t, integer key, leaderboard val returns nothing 
//*    function TableSaveMultiboard takes integer t, integer key, multiboard val returns nothing 
//*    function TableSaveMultiboardItem takes integer t, integer key, multiboarditem val returns nothing 
//*    function TableSaveTrackable takes integer t, integer key, trackable val returns nothing 
//*    function TableSaveDialog takes integer t, integer key, dialog val returns nothing 
//*    function TableSaveButton takes integer t, integer key, button val returns nothing 
//*    function TableSaveTextTag takes integer t, integer key, texttag val returns nothing 
//*    function TableSaveLightning takes integer t, integer key, lightning val returns nothing 
//*    function TableSaveImage takes integer t, integer key, image val returns nothing 
//*    function TableSaveUbersplat takes integer t, integer key, ubersplat val returns nothing 
//*    function TableSaveRegion takes integer t, integer key, region val returns nothing 
//*    function TableSaveFogState takes integer t, integer key, fogstate val returns nothing 
//*    function TableSaveFogModifier takes integer t, integer key, fogmodifier val returns nothing 
//*    function TableSaveAgent takes integer t, integer key, agent val returns nothing 
//*    function TableSaveHashtable takes integer t, integer key, hashtable val returns nothing 
//*
//*    LOAD API
//*
//*    function TableLoadInteger takes integer t, integer key returns integer  
//*    function TableLoadReal takes integer t, integer key returns real  
//*    function TableLoadBoolean takes integer t, integer key returns boolean  
//*    function TableLoadStr takes integer t, integer key returns string  
//*
//*    function TableLoadPlayer takes integer t, integer key returns player  
//*    function TableLoadWidget takes integer t, integer key returns widget  
//*    function TableLoadDestructable takes integer t, integer key returns destructable  
//*    function TableLoadItem takes integer t, integer key returns item  
//*    function TableLoadUnit takes integer t, integer key returns unit  
//*    function TableLoadAbility takes integer t, integer key returns ability  
//*    function TableLoadTimer takes integer t, integer key returns timer  
//*    function TableLoadTrigger takes integer t, integer key returns trigger  
//*    function TableLoadTriggerCondition takes integer t, integer key returns triggercondition  
//*    function TableLoadTriggerAction takes integer t, integer key returns triggeraction  
//*    function TableLoadTriggerEvent takes integer t, integer key returns event  
//*    function TableLoadForce takes integer t, integer key returns force  
//*    function TableLoadGroup takes integer t, integer key returns group  
//*    function TableLoadLocation takes integer t, integer key returns location  
//*    function TableLoadRect takes integer t, integer key returns rect  
//*    function TableLoadBooleanExpr takes integer t, integer key returns boolexpr  
//*    function TableLoadSound takes integer t, integer key returns sound  
//*    function TableLoadEffect takes integer t, integer key returns effect  
//*    function TableLoadUnitPool takes integer t, integer key returns unitpool  
//*    function TableLoadItemPool takes integer t, integer key returns itempool  
//*    function TableLoadQuest takes integer t, integer key returns quest  
//*    function TableLoadQuestItem takes integer t, integer key returns questitem  
//*    function TableLoadDefeatCondition takes integer t, integer key returns defeatcondition  
//*    function TableLoadTimerDialog takes integer t, integer key returns timerdialog  
//*    function TableLoadLeaderboard takes integer t, integer key returns leaderboard  
//*    function TableLoadMultiboard takes integer t, integer key returns multiboard  
//*    function TableLoadMultiboardItem takes integer t, integer key returns multiboarditem  
//*    function TableLoadTrackable takes integer t, integer key returns trackable  
//*    function TableLoadDialog takes integer t, integer key returns dialog  
//*    function TableLoadButton takes integer t, integer key returns button  
//*    function TableLoadTextTag takes integer t, integer key returns texttag  
//*    function TableLoadLightning takes integer t, integer key returns lightning  
//*    function TableLoadImage takes integer t, integer key returns image  
//*    function TableLoadUbersplat takes integer t, integer key returns ubersplat  
//*    function TableLoadRegion takes integer t, integer key returns region  
//*    function TableLoadFogState takes integer t, integer key returns fogstate  
//*    function TableLoadFogModifier takes integer t, integer key returns fogmodifier  
//*    function TableLoadHashtable takes integer t, integer key returns hashtable  
//*
//*    HAS API
//*
//*    function TableHasInteger takes integer t, integer key returns boolean 
//*    function TableHasReal takes integer t, integer key returns boolean 
//*    function TableHasBoolean takes integer t, integer key returns boolean 
//*    function TableHasString takes integer t, integer key returns boolean 
//*    function TableHasHandle takes integer t, integer key returns boolean 
//*
//*     REMOVE API
//*
//*    function TableRemoveInteger takes integer t, integer key returns nothing  
//*    function TableRemoveReal takes integer t, integer key returns nothing  
//*    function TableRemoveBoolean takes integer t, integer key returns nothing  
//*    function TableRemoveString takes integer t, integer key returns nothing  
//*    function TableRemoveHandle takes integer t, integer key returns nothing  
//*
//*************************************************************************************
//*
//*     Credits
//*
//*     Bribe - Table
//*
//*************************************************************************************
function InitTable takes nothing returns boolean
    if udg_Table == null then
        set udg_Table = InitHashtable()
        set udg_Table_R[0] = 1
        return true 
    endif
    return false
endfunction
function FlushTable takes integer t returns nothing
    call FlushChildHashtable(udg_Table, t)
endfunction
function CreateTable takes nothing returns integer
    local integer i = udg_Table_R[0]
    if InitTable() then
        set i = 1
    endif
    if udg_Table_R[i] == 0 then
        set udg_Table_R[0] = i + 1
    else 
        set udg_Table_R[0] = udg_Table_R[i]
        call FlushTable(i)
    endif
    set udg_IsTable[i] = true
    return i
endfunction
function IsTable takes integer i returns boolean
    return udg_IsTable[i]
endfunction
function DestroyTable takes integer t returns nothing
    call FlushTable(t)
    set udg_Table_R[t] = udg_Table_R[0]
    set udg_Table_R[0] = t
    set udg_IsTable[t] = false
endfunction

//*************************************************************************************
//*
//*     Save and Load Handles
//*
//*************************************************************************************
function TableSavePlayer takes integer t, integer key, player val returns nothing 
   if IsTable(t) then 
       call SavePlayerHandle(udg_Table, t, key, val) 
   endif 
endfunction 
function TableLoadPlayer takes integer t, integer key returns player  
   return LoadPlayerHandle(udg_Table, t, key) 
endfunction 
function TableSaveWidget takes integer t, integer key, widget val returns nothing 
   if IsTable(t) then 
       call SaveWidgetHandle(udg_Table, t, key, val) 
   endif 
endfunction 
function TableLoadWidget takes integer t, integer key returns widget  
   return LoadWidgetHandle(udg_Table, t, key) 
endfunction 
function TableSaveDestructable takes integer t, integer key, destructable val returns nothing 
   if IsTable(t) then 
       call SaveDestructableHandle(udg_Table, t, key, val) 
   endif 
endfunction 
function TableLoadDestructable takes integer t, integer key returns destructable  
   return LoadDestructableHandle(udg_Table, t, key) 
endfunction 
function TableSaveItem takes integer t, integer key, item val returns nothing 
   if IsTable(t) then 
       call SaveItemHandle(udg_Table, t, key, val) 
   endif 
endfunction 
function TableLoadItem takes integer t, integer key returns item  
   return LoadItemHandle(udg_Table, t, key) 
endfunction 
function TableSaveUnit takes integer t, integer key, unit val returns nothing 
   if IsTable(t) then 
       call SaveUnitHandle(udg_Table, t, key, val) 
   endif 
endfunction 
function TableLoadUnit takes integer t, integer key returns unit  
   return LoadUnitHandle(udg_Table, t, key) 
endfunction 
function TableSaveAbility takes integer t, integer key, ability val returns nothing 
   if IsTable(t) then 
       call SaveAbilityHandle(udg_Table, t, key, val) 
   endif 
endfunction 
function TableLoadAbility takes integer t, integer key returns ability  
   return LoadAbilityHandle(udg_Table, t, key) 
endfunction 
function TableSaveTimer takes integer t, integer key, timer val returns nothing 
   if IsTable(t) then 
       call SaveTimerHandle(udg_Table, t, key, val) 
   endif 
endfunction 
function TableLoadTimer takes integer t, integer key returns timer  
   return LoadTimerHandle(udg_Table, t, key) 
endfunction 
function TableSaveTrigger takes integer t, integer key, trigger val returns nothing 
   if IsTable(t) then 
       call SaveTriggerHandle(udg_Table, t, key, val) 
   endif 
endfunction 
function TableLoadTrigger takes integer t, integer key returns trigger  
   return LoadTriggerHandle(udg_Table, t, key) 
endfunction 
function TableSaveTriggerCondition takes integer t, integer key, triggercondition val returns nothing 
   if IsTable(t) then 
       call SaveTriggerConditionHandle(udg_Table, t, key, val) 
   endif 
endfunction 
function TableLoadTriggerCondition takes integer t, integer key returns triggercondition  
   return LoadTriggerConditionHandle(udg_Table, t, key) 
endfunction 
function TableSaveTriggerAction takes integer t, integer key, triggeraction val returns nothing 
   if IsTable(t) then 
       call SaveTriggerActionHandle(udg_Table, t, key, val) 
   endif 
endfunction 
function TableLoadTriggerAction takes integer t, integer key returns triggeraction  
   return LoadTriggerActionHandle(udg_Table, t, key) 
endfunction 
function TableSaveTriggerEvent takes integer t, integer key, event val returns nothing 
   if IsTable(t) then 
       call SaveTriggerEventHandle(udg_Table, t, key, val) 
   endif 
endfunction 
function TableLoadTriggerEvent takes integer t, integer key returns event  
   return LoadTriggerEventHandle(udg_Table, t, key) 
endfunction 
function TableSaveForce takes integer t, integer key, force val returns nothing 
   if IsTable(t) then 
       call SaveForceHandle(udg_Table, t, key, val) 
   endif 
endfunction 
function TableLoadForce takes integer t, integer key returns force  
   return LoadForceHandle(udg_Table, t, key) 
endfunction 
function TableSaveGroup takes integer t, integer key, group val returns nothing 
   if IsTable(t) then 
       call SaveGroupHandle(udg_Table, t, key, val) 
   endif 
endfunction 
function TableLoadGroup takes integer t, integer key returns group  
   return LoadGroupHandle(udg_Table, t, key) 
endfunction 
function TableSaveLocation takes integer t, integer key, location val returns nothing 
   if IsTable(t) then 
       call SaveLocationHandle(udg_Table, t, key, val) 
   endif 
endfunction 
function TableLoadLocation takes integer t, integer key returns location  
   return LoadLocationHandle(udg_Table, t, key) 
endfunction 
function TableSaveRect takes integer t, integer key, rect val returns nothing 
   if IsTable(t) then 
       call SaveRectHandle(udg_Table, t, key, val) 
   endif 
endfunction 
function TableLoadRect takes integer t, integer key returns rect  
   return LoadRectHandle(udg_Table, t, key) 
endfunction 
function TableSaveBooleanExpr takes integer t, integer key, boolexpr val returns nothing 
   if IsTable(t) then 
       call SaveBooleanExprHandle(udg_Table, t, key, val) 
   endif 
endfunction 
function TableLoadBooleanExpr takes integer t, integer key returns boolexpr  
   return LoadBooleanExprHandle(udg_Table, t, key) 
endfunction 
function TableSaveSound takes integer t, integer key, sound val returns nothing 
   if IsTable(t) then 
       call SaveSoundHandle(udg_Table, t, key, val) 
   endif 
endfunction 
function TableLoadSound takes integer t, integer key returns sound  
   return LoadSoundHandle(udg_Table, t, key) 
endfunction 
function TableSaveEffect takes integer t, integer key, effect val returns nothing 
   if IsTable(t) then 
       call SaveEffectHandle(udg_Table, t, key, val) 
   endif 
endfunction 
function TableLoadEffect takes integer t, integer key returns effect  
   return LoadEffectHandle(udg_Table, t, key) 
endfunction 
function TableSaveUnitPool takes integer t, integer key, unitpool val returns nothing 
   if IsTable(t) then 
       call SaveUnitPoolHandle(udg_Table, t, key, val) 
   endif 
endfunction 
function TableLoadUnitPool takes integer t, integer key returns unitpool  
   return LoadUnitPoolHandle(udg_Table, t, key) 
endfunction 
function TableSaveItemPool takes integer t, integer key, itempool val returns nothing 
   if IsTable(t) then 
       call SaveItemPoolHandle(udg_Table, t, key, val) 
   endif 
endfunction 
function TableLoadItemPool takes integer t, integer key returns itempool  
   return LoadItemPoolHandle(udg_Table, t, key) 
endfunction 
function TableSaveQuest takes integer t, integer key, quest val returns nothing 
   if IsTable(t) then 
       call SaveQuestHandle(udg_Table, t, key, val) 
   endif 
endfunction 
function TableLoadQuest takes integer t, integer key returns quest  
   return LoadQuestHandle(udg_Table, t, key) 
endfunction 
function TableSaveQuestItem takes integer t, integer key, questitem val returns nothing 
   if IsTable(t) then 
       call SaveQuestItemHandle(udg_Table, t, key, val) 
   endif 
endfunction 
function TableLoadQuestItem takes integer t, integer key returns questitem  
   return LoadQuestItemHandle(udg_Table, t, key) 
endfunction 
function TableSaveDefeatCondition takes integer t, integer key, defeatcondition val returns nothing 
   if IsTable(t) then 
       call SaveDefeatConditionHandle(udg_Table, t, key, val) 
   endif 
endfunction 
function TableLoadDefeatCondition takes integer t, integer key returns defeatcondition  
   return LoadDefeatConditionHandle(udg_Table, t, key) 
endfunction 
function TableSaveTimerDialog takes integer t, integer key, timerdialog val returns nothing 
   if IsTable(t) then 
       call SaveTimerDialogHandle(udg_Table, t, key, val) 
   endif 
endfunction 
function TableLoadTimerDialog takes integer t, integer key returns timerdialog  
   return LoadTimerDialogHandle(udg_Table, t, key) 
endfunction 
function TableSaveLeaderboard takes integer t, integer key, leaderboard val returns nothing 
   if IsTable(t) then 
       call SaveLeaderboardHandle(udg_Table, t, key, val) 
   endif 
endfunction 
function TableLoadLeaderboard takes integer t, integer key returns leaderboard  
   return LoadLeaderboardHandle(udg_Table, t, key) 
endfunction 
function TableSaveMultiboard takes integer t, integer key, multiboard val returns nothing 
   if IsTable(t) then 
       call SaveMultiboardHandle(udg_Table, t, key, val) 
   endif 
endfunction 
function TableLoadMultiboard takes integer t, integer key returns multiboard  
   return LoadMultiboardHandle(udg_Table, t, key) 
endfunction 
function TableSaveMultiboardItem takes integer t, integer key, multiboarditem val returns nothing 
   if IsTable(t) then 
       call SaveMultiboardItemHandle(udg_Table, t, key, val) 
   endif 
endfunction 
function TableLoadMultiboardItem takes integer t, integer key returns multiboarditem  
   return LoadMultiboardItemHandle(udg_Table, t, key) 
endfunction 
function TableSaveTrackable takes integer t, integer key, trackable val returns nothing 
   if IsTable(t) then 
       call SaveTrackableHandle(udg_Table, t, key, val) 
   endif 
endfunction 
function TableLoadTrackable takes integer t, integer key returns trackable  
   return LoadTrackableHandle(udg_Table, t, key) 
endfunction 
function TableSaveDialog takes integer t, integer key, dialog val returns nothing 
   if IsTable(t) then 
       call SaveDialogHandle(udg_Table, t, key, val) 
   endif 
endfunction 
function TableLoadDialog takes integer t, integer key returns dialog  
   return LoadDialogHandle(udg_Table, t, key) 
endfunction 
function TableSaveButton takes integer t, integer key, button val returns nothing 
   if IsTable(t) then 
       call SaveButtonHandle(udg_Table, t, key, val) 
   endif 
endfunction 
function TableLoadButton takes integer t, integer key returns button  
   return LoadButtonHandle(udg_Table, t, key) 
endfunction 
function TableSaveTextTag takes integer t, integer key, texttag val returns nothing 
   if IsTable(t) then 
       call SaveTextTagHandle(udg_Table, t, key, val) 
   endif 
endfunction 
function TableLoadTextTag takes integer t, integer key returns texttag  
   return LoadTextTagHandle(udg_Table, t, key) 
endfunction 
function TableSaveLightning takes integer t, integer key, lightning val returns nothing 
   if IsTable(t) then 
       call SaveLightningHandle(udg_Table, t, key, val) 
   endif 
endfunction 
function TableLoadLightning takes integer t, integer key returns lightning  
   return LoadLightningHandle(udg_Table, t, key) 
endfunction 
function TableSaveImage takes integer t, integer key, image val returns nothing 
   if IsTable(t) then 
       call SaveImageHandle(udg_Table, t, key, val) 
   endif 
endfunction 
function TableLoadImage takes integer t, integer key returns image  
   return LoadImageHandle(udg_Table, t, key) 
endfunction 
function TableSaveUbersplat takes integer t, integer key, ubersplat val returns nothing 
   if IsTable(t) then 
       call SaveUbersplatHandle(udg_Table, t, key, val) 
   endif 
endfunction 
function TableLoadUbersplat takes integer t, integer key returns ubersplat  
   return LoadUbersplatHandle(udg_Table, t, key) 
endfunction 
function TableSaveRegion takes integer t, integer key, region val returns nothing 
   if IsTable(t) then 
       call SaveRegionHandle(udg_Table, t, key, val) 
   endif 
endfunction 
function TableLoadRegion takes integer t, integer key returns region  
   return LoadRegionHandle(udg_Table, t, key) 
endfunction 
function TableSaveFogState takes integer t, integer key, fogstate val returns nothing 
   if IsTable(t) then 
       call SaveFogStateHandle(udg_Table, t, key, val) 
   endif 
endfunction 
function TableLoadFogState takes integer t, integer key returns fogstate  
   return LoadFogStateHandle(udg_Table, t, key) 
endfunction 
function TableSaveFogModifier takes integer t, integer key, fogmodifier val returns nothing 
   if IsTable(t) then 
       call SaveFogModifierHandle(udg_Table, t, key, val) 
   endif 
endfunction 
function TableLoadFogModifier takes integer t, integer key returns fogmodifier  
   return LoadFogModifierHandle(udg_Table, t, key) 
endfunction 
function TableSaveHashtable takes integer t, integer key, hashtable val returns nothing 
   if IsTable(t) then 
       call SaveHashtableHandle(udg_Table, t, key, val) 
   endif 
endfunction 
function TableLoadHashtable takes integer t, integer key returns hashtable  
   return LoadHashtableHandle(udg_Table, t, key) 
endfunction
//*************************************************************************************
//*
//*     Save Load Integer, Real, Boolean, String
//*
//*************************************************************************************
function TableSaveInteger takes integer t, integer key, integer val returns nothing 
   if IsTable(t) then 
       call SaveInteger(udg_Table, t, key, val) 
   endif 
endfunction 
function TableLoadInteger takes integer t, integer key returns integer  
   return LoadInteger(udg_Table, t, key) 
endfunction 
function TableSaveReal takes integer t, integer key, real val returns nothing 
   if IsTable(t) then 
       call SaveReal(udg_Table, t, key, val) 
   endif 
endfunction 
function TableLoadReal takes integer t, integer key returns real  
   return LoadReal(udg_Table, t, key) 
endfunction 
function TableSaveBoolean takes integer t, integer key, boolean val returns nothing 
   if IsTable(t) then 
       call SaveBoolean(udg_Table, t, key, val) 
   endif 
endfunction 
function TableLoadBoolean takes integer t, integer key returns boolean  
   return LoadBoolean(udg_Table, t, key) 
endfunction 
function TableSaveStr takes integer t, integer key, string val returns nothing 
   if IsTable(t) then 
       call SaveStr(udg_Table, t, key, val) 
   endif 
endfunction 
function TableLoadStr takes integer t, integer key returns string  
   return LoadStr(udg_Table, t, key) 
endfunction 
//*************************************************************************************
//*
//*     Save Agent
//*
//*************************************************************************************
function TableSaveAgent takes integer t, integer key, agent val returns nothing 
   if IsTable(t) then 
       call SaveAgentHandle(udg_Table, t, key, val) 
   endif 
endfunction
//*************************************************************************************
//*
//*     Has / Remove Functionality
//*
//*************************************************************************************
function TableHasInteger takes integer t, integer key returns boolean 
   return HaveSavedInteger(udg_Table, t, key) 
endfunction 
function TableRemoveInteger takes integer t, integer key returns nothing  
   call RemoveSavedInteger(udg_Table, t, key) 
endfunction 
function TableHasReal takes integer t, integer key returns boolean 
   return HaveSavedReal(udg_Table, t, key) 
endfunction 
function TableRemoveReal takes integer t, integer key returns nothing  
   call RemoveSavedReal(udg_Table, t, key) 
endfunction 
function TableHasBoolean takes integer t, integer key returns boolean 
   return HaveSavedBoolean(udg_Table, t, key) 
endfunction 
function TableRemoveBoolean takes integer t, integer key returns nothing  
   call RemoveSavedBoolean(udg_Table, t, key) 
endfunction 
function TableHasString takes integer t, integer key returns boolean 
   return HaveSavedString(udg_Table, t, key) 
endfunction 
function TableRemoveString takes integer t, integer key returns nothing  
   call RemoveSavedString(udg_Table, t, key) 
endfunction 
function TableHasHandle takes integer t, integer key returns boolean 
   return HaveSavedHandle(udg_Table, t, key) 
endfunction 
function TableRemoveHandle takes integer t, integer key returns nothing  
   call RemoveSavedHandle(udg_Table, t, key) 
endfunction


So many people are going to hate me, but I have no choice :ogre_hurrhurr:
 
Level 33
Joined
Apr 24, 2012
Messages
5,113
(Part 2 post because It might reach the limit)
I have made this using a much faster method, using my Macro lib(which I deleted):
JASS:
//*************************************************************************************
//*
//*    Macro by Almia
//*
//*    Allows users to generate codes or simply generate CnP codes and replaces words
//*    with wanted words for much easier replacement. JASS and GUI doesn't have this
//*    kind of functionality, so I gave them the ability to do so. The system is similar
//*    to vJASS Text Macro though has the following "ugly" features:
//*        - Macro generates the code outside the map,read the next statement.
//*        - Codes are generated inside a .bat file and you need to download the
//*          generated codes from the .bat file.
//*        - Copy paste generate codes into your map code.
//*        - Because of these features, it uses Preload.
//*        - You can't replace the macro variable names,
//*          all are sequenced with an integer, so you need to use those integers
//*          instead of these.
//*
//*************************************************************************************
//*
//*    API
//*
//*    function Macro takes nothing returns integer
//*        Creates a macro instance
//*
//*    function MacroAppend takes integer macro, string phrase returns nothing
//*        Declares a macro phrase
//*
//*    function MacroPushArgument takes integer macro, string val returns nothing
//*        Declares a macro variable's value
//*
//*    function MacroParse takes integer macro returns nothing
//*        Run a macro and generates its code
//*
//*    function DownloadMacro takes integer macro returns nothing
//*        Download generated macro code
//*    
//*    function ClearMacro takes integer macro returns nothing
//*        Clears macro memory 
//*
//*    function DestroyMacro takes integer macro returns nothing
//*        Destroys a macro instance
//*
//*************************************************************************************
//*
//*    How does Macro works?
//*
//*    - First,you need to create a Macro Instance:
//*        local integer macro = Macro()
//*    - Do declare phrase use:
//*        call MacroAppend(whichMacro, "someStatement")
//*    - Variables are done like these:
//*      {1}
//*      {2}
//*    - Declare a phrase with macro variable
//*        call MacroAppend(whichMacro, "someSortOfStuffLike{1} or {2}")
//*    - Those won't be complete without declaring what is the value of the macro variable
//*        call MacroPushArgument(whichMacro, "This") // replaces {1}
//*        call MacroPushArgument(whichMacro, "That") // replaces {2}
//*    - Generate code by running:
//*        call MacroParse(m)
//*    - Download code:
//*        call DownloadMacro(m)
//*
//*************************************************************************************
//*
//*   About Macro Var
//*
//*   Noticed that Macro variables uses integers. Setting macro variable integer's value 
//*   must be equal to how many times MacroVarSet was called to a given macro.
//*   For example:
//*       call MacroPushArgument(whichMacro, "that")
//*       call MacroPushArgument(whichMacro, "this")
//*       call MacroPushArgument(whichMacro, "those")
//*
//*       "that" replaces {1}, "this" replaces {2}, "those" replaces {3}
//*   Another example:
//*       call MacroPushArgument(whichMacro, "hahah")
//*       call BJDebugMsg("hahah")
//*       call MacroPushArgument(whichMacro, "hahaha")
//*
//*       "hahah" replaces {1} and "hahaha" replaces {2}
//*
//*************************************************************************************
constant function MACRO_FOLDER takes nothing returns string
    return "MacroFiles\\"
endfunction

constant function MAP_NAME takes nothing returns string
    return "Table"
endfunction

function PreloadMacroPhrase takes integer macro, integer k returns string
    local string s = LoadStr(udg_MacroTable, macro, k)
    local integer i = 0
    local integer i2 = StringLength(s)
    local string s2
    local string s3 = ""
    local boolean open = false
    loop
        exitwhen i == i2
        set s2 = SubString(s, i, i + 1)
        if s2 == "{" then
            set open = true
        elseif s2 == "}" then
            set open = false
        elseif open then
            set s3 = s3 + s2
        elseif s3 != "" then
            set s = SubString(s, 0, i - StringLength(s3) - 2) + LoadStr(udg_MacroTable, macro, 8192 + S2I(s3)) + SubString(s, i, i2)
            set i2 = StringLength(s)
            set s3 = ""
        endif
        set i = i + 1
    endloop
    return s
endfunction

function Macro takes nothing returns integer
    local integer macro = udg_Macro_R[0]
    if 0 == macro then
        set macro = udg_Macro + 1
        set udg_Macro = macro
    else
        set udg_Macro_R[0] = udg_Macro_R[macro]
    endif
    if null == udg_MacroTable then
        set udg_MacroTable = InitHashtable()
        call BJDebugMsg("Note:")
        call BJDebugMsg("All macro files can be found in your Warcraft III folder -> " + MACRO_FOLDER() + MAP_NAME())
    endif
    set udg_Macro_Var[macro] = 0
    set udg_Macro_Phrase[macro] = 0
    set udg_Macro_Use[macro] = 0
    call FlushChildHashtable(udg_MacroTable, macro)
    return macro
endfunction

function MacroAppend takes integer macro, string phrase returns nothing
    call SaveStr(udg_MacroTable, macro, udg_Macro_Phrase[macro], phrase)
    set udg_Macro_Phrase[macro] = udg_Macro_Phrase[macro] + 1
endfunction

function MacroPushArgument takes integer macro, string val returns nothing
    set udg_Macro_Var[macro] = udg_Macro_Var[macro] + 1
    call SaveStr(udg_MacroTable, macro, 8192 + udg_Macro_Var[macro], val)
endfunction

function MacroParse takes integer macro returns nothing
    local integer i = 0
    loop
        exitwhen i == udg_Macro_Phrase[macro]
        call SaveStr(udg_MacroTable, macro, 16384 + (udg_Macro_Use[macro] * udg_Macro_Phrase[macro]) + i, "\")\r\n\techo " + PreloadMacroPhrase(macro, i) + " >> macro" + I2S(macro) + ".txt\r\n\t(\"")
        set i = i + 1
    endloop
    set udg_Macro_Use[macro] = udg_Macro_Use[macro] + 1
    set udg_Macro_Var[macro] = 0
endfunction

function DownloadMacro takes integer macro returns nothing
    local integer i = 0
    call PreloadGenClear()
    call PreloadGenStart()
    call Preload("\")\r\n\tdel macro" + I2S(macro) + ".txt\r\n\t(\"")
    loop
        exitwhen i == udg_Macro_Use[macro] * udg_Macro_Phrase[macro]
        call Preload(LoadStr(udg_MacroTable, macro, 16384 + i))
        set i = i + 1
    endloop
    call Preload("\")\r\n\tstart macro" + I2S(macro) + ".txt\r\n\t(\"")
    call Preload("\")\r\n\tdel macroDL" + I2S(macro) + ".bat\r\n\t(\"")
    call PreloadGenEnd(MACRO_FOLDER() + MAP_NAME() + "\\macroDL" + I2S(macro) + ".bat")
    set udg_Macro_Use[macro] = 0
endfunction

function ClearMacro takes integer macro returns nothing
    set udg_Macro_Var[macro] = 0
    set udg_Macro_Preload[macro] = 0
    set udg_Macro_Phrase[macro] = 0
    call FlushChildHashtable(udg_MacroTable, macro)
endfunction

function DestroyMacro takes integer macro returns nothing
    call ClearMacro(macro)
    set udg_Macro_R[macro] = udg_Macro_R[0]
    set udg_Macro_R[0] = macro
endfunction

and installed it :
JASS:
function InstallTable1 takes integer m returns boolean
    call MacroAppend(m, "function TableSave{1} takes integer t, integer key, {2} val returns nothing")
    call MacroAppend(m, "   if IsTable(t) then")
    call MacroAppend(m, "       call Save{1}Handle(udg_Table, t, key, val)")
    call MacroAppend(m, "   endif")
    call MacroAppend(m, "endfunction")
    call MacroAppend(m, "function TableLoad{1} takes integer t, integer key returns {2} ")
    call MacroAppend(m, "   return Load{1}Handle(udg_Table, t, key)")
    call MacroAppend(m, "endfunction")
    call MacroPushArgument(m, "Player")
    call MacroPushArgument(m, "player")
    call MacroParse(m)
    call MacroPushArgument(m, "Widget")
    call MacroPushArgument(m, "widget")
    call MacroParse(m)
    call MacroPushArgument(m, "Destructable")
    call MacroPushArgument(m, "destructable")
    call MacroParse(m)
    call MacroPushArgument(m, "Item")
    call MacroPushArgument(m, "item")
    call MacroParse(m)
    call MacroPushArgument(m, "Unit")
    call MacroPushArgument(m, "unit")
    call MacroParse(m)
    call MacroPushArgument(m, "Ability")
    call MacroPushArgument(m, "ability")
    call MacroParse(m)
    call MacroPushArgument(m, "Timer")
    call MacroPushArgument(m, "timer")
    call MacroParse(m)
    call MacroPushArgument(m, "Trigger")
    call MacroPushArgument(m, "trigger")
    call MacroParse(m)
    call MacroPushArgument(m, "TriggerCondition")
    call MacroPushArgument(m, "triggercondition")
    call MacroParse(m)
    call MacroPushArgument(m, "TriggerAction")
    call MacroPushArgument(m, "triggeraction")
    call MacroParse(m)
    call MacroPushArgument(m, "TriggerEvent")
    call MacroPushArgument(m, "event")
    call MacroParse(m)
    call MacroPushArgument(m, "Force")
    call MacroPushArgument(m, "force")
    call MacroParse(m)
    call MacroPushArgument(m, "Group")
    call MacroPushArgument(m, "group")
    call MacroParse(m)
    call MacroPushArgument(m, "Location")
    call MacroPushArgument(m, "location")
    call MacroParse(m)
    call MacroPushArgument(m, "Rect")
    call MacroPushArgument(m, "rect")
    call MacroParse(m)
    call MacroPushArgument(m, "BooleanExpr")
    call MacroPushArgument(m, "boolexpr")
    call MacroParse(m)
    call MacroPushArgument(m, "Sound")
    call MacroPushArgument(m, "sound")
    call MacroParse(m)
    call DownloadMacro(m)
    call DestroyMacro(m)
    return true
endfunction
function InstallTable2 takes integer m returns boolean
    call MacroAppend(m, "function TableSave{1} takes integer t, integer key, {2} val returns nothing")
    call MacroAppend(m, "   if IsTable(t) then")
    call MacroAppend(m, "       call Save{1}Handle(udg_Table, t, key, val)")
    call MacroAppend(m, "   endif")
    call MacroAppend(m, "endfunction")
    call MacroAppend(m, "function TableLoad{1} takes integer t, integer key returns {2} ")
    call MacroAppend(m, "   return Load{1}Handle(udg_Table, t, key)")
    call MacroAppend(m, "endfunction")
    call MacroPushArgument(m, "Effect")
    call MacroPushArgument(m, "effect")
    call MacroParse(m)
    call MacroPushArgument(m, "UnitPool")
    call MacroPushArgument(m, "unitpool")
    call MacroParse(m)
    call MacroPushArgument(m, "ItemPool")
    call MacroPushArgument(m, "itempool")
    call MacroParse(m)
    call MacroPushArgument(m, "Quest")
    call MacroPushArgument(m, "quest")
    call MacroParse(m)
    call MacroPushArgument(m, "QuestItem")
    call MacroPushArgument(m, "questitem")
    call MacroParse(m)
    call MacroPushArgument(m, "DefeatCondition")
    call MacroPushArgument(m, "defeatcondition")
    call MacroParse(m)
    call MacroPushArgument(m, "TimerDialog")
    call MacroPushArgument(m, "timerdialog")
    call MacroParse(m)
    call MacroPushArgument(m, "Leaderboard")
    call MacroPushArgument(m, "leaderboard")
    call MacroParse(m)
    call MacroPushArgument(m, "Multiboard")
    call MacroPushArgument(m, "multiboard")
    call MacroParse(m)
    call MacroPushArgument(m, "MultiboardItem")
    call MacroPushArgument(m, "multiboarditem")
    call MacroParse(m)
    call MacroPushArgument(m, "Trackable")
    call MacroPushArgument(m, "trackable")
    call MacroParse(m)
    call MacroPushArgument(m, "Dialog")
    call MacroPushArgument(m, "dialog")
    call MacroParse(m)
    call MacroPushArgument(m, "Button")
    call MacroPushArgument(m, "button")
    call MacroParse(m)
    call MacroPushArgument(m, "TextTag")
    call MacroPushArgument(m, "texttag")
    call MacroParse(m)
    call MacroPushArgument(m, "Lightning")
    call MacroPushArgument(m, "lightning")
    call MacroParse(m)
    call MacroPushArgument(m, "Image")
    call MacroPushArgument(m, "image")
    call MacroParse(m)
    call MacroPushArgument(m, "Ubersplat")
    call MacroPushArgument(m, "ubersplat")
    call MacroParse(m)
    call DownloadMacro(m)
    return true
endfunction

function InstallTable3 takes integer m returns boolean
    call MacroAppend(m, "function TableSave{1} takes integer t, integer key, {2} val returns nothing")
    call MacroAppend(m, "   if IsTable(t) then")
    call MacroAppend(m, "       call Save{1}Handle(udg_Table, t, key, val)")
    call MacroAppend(m, "   endif")
    call MacroAppend(m, "endfunction")
    call MacroAppend(m, "function TableLoad{1} takes integer t, integer key returns {2} ")
    call MacroAppend(m, "   return Load{1}Handle(udg_Table, t, key)")
    call MacroAppend(m, "endfunction")
    call MacroPushArgument(m, "Region")
    call MacroPushArgument(m, "region")
    call MacroParse(m)
    call MacroPushArgument(m, "FogState")
    call MacroPushArgument(m, "fogstate")
    call MacroParse(m)
    call MacroPushArgument(m, "FogModifier")
    call MacroPushArgument(m, "fogmodifier")
    call MacroParse(m)
    call MacroPushArgument(m, "Agent")
    call MacroPushArgument(m, "agent") //Remove TableLoadAgent after installing
    call MacroParse(m)
    call MacroPushArgument(m, "Hashtable")
    call MacroPushArgument(m, "hashtable")
    call MacroParse(m)
    call DownloadMacro(m)
    return true
endfunction

function InstallTable4 takes integer m returns boolean
    call MacroAppend(m, "function TableSave{1} takes integer t, integer key, {2} val returns nothing")
    call MacroAppend(m, "   if IsTable(t) then")
    call MacroAppend(m, "       call Save{1}(udg_Table, t, key, val)")
    call MacroAppend(m, "   endif")
    call MacroAppend(m, "endfunction")
    call MacroAppend(m, "function TableLoad{1} takes integer t, integer key returns {2} ")
    call MacroAppend(m, "   return Load{1}(udg_Table, t, key)")
    call MacroAppend(m, "endfunction")
    call MacroPushArgument(m, "Integer")
    call MacroPushArgument(m, "integer")
    call MacroParse(m)
    call MacroPushArgument(m, "Real")
    call MacroPushArgument(m, "real")
    call MacroParse(m)
    call MacroPushArgument(m, "Boolean")
    call MacroPushArgument(m, "boolean")
    call MacroParse(m)
    call MacroPushArgument(m, "Str")
    call MacroPushArgument(m, "string")
    call MacroParse(m)
    call DownloadMacro(m)
    return true
endfunction
function InstallTable5 takes integer m returns boolean
    call MacroAppend(m, "function TableHas{1} takes integer t, integer key returns boolean")
    call MacroAppend(m, "   return HaveSaved{1}(udg_Table, t, key)")
    call MacroAppend(m, "endfunction")
    call MacroAppend(m, "function TableRemove{1} takes integer t, integer key returns nothing ")
    call MacroAppend(m, "   call RemoveSaved{1}(udg_Table, t, key)")
    call MacroAppend(m, "endfunction")
    call MacroPushArgument(m, "Integer")
    call MacroParse(m)
    call MacroPushArgument(m, "Real")
    call MacroParse(m)
    call MacroPushArgument(m, "Boolean")
    call MacroParse(m)
    call MacroPushArgument(m, "String")
    call MacroParse(m)
    call MacroPushArgument(m, "Handle")
    call MacroParse(m)
    call DownloadMacro(m)
    return true 
endfunction

function InitTrig_Table_Installation takes nothing returns nothing
    local integer m1 = Macro()
    local integer m2 = Macro()
    local integer m3 = Macro()
    local integer m4 = Macro()
    local integer m5 = Macro()
    call InstallTable1(m1) //Disable after 1st installation, run map again
    call BJDebugMsg("Install Part 1 Complete")
    call InstallTable2(m2) //Disable after 2nd installation, run map again
    call BJDebugMsg("Install Part 2 Complete")
    call InstallTable3(m3)
    call BJDebugMsg("Install Part 3 Complete")
    call InstallTable4(m4)
    call BJDebugMsg("Install Part 4 Complete")
    call InstallTable5(m5)
    call BJDebugMsg("Install Part 5 Complete")
endfunction
 
Level 6
Joined
Jul 30, 2013
Messages
282
i totally fail to see WHY?!

i mean you stil luse external tools to generate code so you win nothing over Bribes Table.. its just a more obscure tool..

and why dont you just compile Bribes table once and extract the generated raw jass output you really dont have a reason to make a new thing from scratch
 

Bannar

Code Reviewer
Level 26
Joined
Mar 19, 2008
Messages
3,139
When I'm googling for Table, 'NewTable' seems to be the top result. Once clicked, I'm immidiately moved to thread of interest which contains all informations required for one to use and implement it.

Most GUI (Vanilla/ ) users are "afraid" as vJass just because they don't really understand object oriented programming or had no contact with scritping at all. If one has enough "courage" to finally look for Table, she/he probably already has installed NewGen (what in fact is trivial operation and easier to do than understanding usage of Table for someone who never did something similar before).
That said, they WILL quickly realise that Table (NewTable) is the way to go and forget about this.
"Just passing by" - seems to be the name of the game for this snippet.
 
Level 6
Joined
Jul 30, 2013
Messages
282
oop may sound scary and all, but honestly it's such a core concept that if you cant even get a bit of it you must be a true beginner, a status that does not last long.

also jass2 is procedural by nature but the underlying state being manipulated is still objects, and it leaks thru.
JASS:
unit u = CreateUnit()       // Unit.create()
call SetUnitLife(u, 33)      // u.setLife(33) or u.life=33
what i'm trying to say is, underneath its all objects anyway, its just that you have standalone methods to manipulate them in jass2 in stead of methods.

this can be seen well looking at python
JASS:
class C:
    def manipulate_object(self):
        pass
c = C()

#the following two lines  are exactly equivalent.
c.manipulate_object() # this style is what we are used to in most oop languages
C.manipulate_object(c) # but this also works, and is basically what jass2 has

# not convinced?
cmop = C.manipulate_object
cmop(c)
# believe me now?
 
Top