wc3campaigns
WC3C Homepage - www.wc3c.netUser Control Panel (Requires Log-In)Engage in discussions with other users and join contests in the WC3C forums!Read one of our many tutorials, ranging in difficulty from beginner to advanced!Show off your artistic talents in the WC3C Gallery!Download quality models, textures, spells (vJASS/JASS), systems, and scripts!Download maps that have passed through our rigorous approval process!

Go Back   Wc3C.net > Resources > Code Resources > Scripts
User Name
Password
Register Rules Get Hosted! Chat Pastebin FAQ and Rules Members List Calendar



Reply
 
Thread Tools Search this Thread
Old 09-22-2009, 02:23 PM   #106
Troll-Brain
User
 
Join Date: Oct 2006
Posts: 1,490

Submissions (1)

Troll-Brain has a spectacular aura about (134)

Default

Quote:
Originally Posted by Vexorian
You can't use neither a integer key nor a string key if you want Table as a 2d integer array.
That's why i said, i've edited it for myself ?
Troll-Brain is offline   Reply With Quote
Sponsored Links - Login to hide this ad!
Old 11-02-2009, 08:52 PM   #107
Mr.Malte
User
 
Mr.Malte's Avatar
 
Join Date: Apr 2008
Posts: 286

Submissions (2)

Mr.Malte is on a distinguished road (11)

Default

Could you please add sth. like this?

Collapse JASS:
//! textmacro TableModule__make takes name, type
module $name$
    static $name$ ThisTable
    
    method operator[] takes $type$ key returns thistype
        return thistype.ThisTable[key]
    endmethod
    
    method operator []= takes $type$ key, thistype value returns nothing
        set thistype.ThisTable[key] = value
    endmethod
    
    static method onInit takes nothing returns nothing
        set thistype.ThisTable = $name$.create()
    endmethod
endmodule
//! endtextmacro 
//! runtextmacro TableModule__make("Table","integer")
//! runtextmacro TableModule__make("HandleTable","handle")
//! runtextmacro TableModule__make("StringTable","string")

Of course it should be better coded, but I want a syntax like this:

Collapse JASS:
struct Syntax
    implement Table
endstruct

set Syntax[100] = Syntax.create()

Of course it's already possible, but the Table can't have the name of the struct.
Or is it not possible?
Mr.Malte is offline   Reply With Quote
Old 11-02-2009, 08:53 PM   #108
Vexorian
Free Software Terrorist
 
Vexorian's Avatar


Technical Director
 
Join Date: Apr 2003
Posts: 14,898

Submissions (37)

Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)

Hero Contest #3 - 2nd Place

Default

hmnn a module is actually a good idea. Hmnn.
__________________
Zoom (requires log in)Wc3 map optimizer 5.0
Someone should fix .wav sound in this thing.
Zoom (requires log in)JassHelper 0.A.2.A
Turns your simple code into something that is complicated enough to work.
Faster != more useful
Vexorian is offline   Reply With Quote
Old 11-02-2009, 11:32 PM   #109
Vexorian
Free Software Terrorist
 
Vexorian's Avatar


Technical Director
 
Join Date: Apr 2003
Posts: 14,898

Submissions (37)

Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)

Hero Contest #3 - 2nd Place

Default

Actually, this is coming soon to jasshelper:


Collapse JASS:
struct StructTable<type T>
    private delegate Table tab
    static method create takes nothing returns thistype
     local thistype this = allocate()
        set tab = Table.create()  
        return this
    endmethod
    
    method operator[] takes integer x returns T
        return T(tab[x])
    endmethod
    method operator[]= takes integer x, T y returns nothing
        set tab[x] = integer(y)
    endmethod
    
    method onDestroy takes nothing returns nothing
        call tab.destroy()
    endmethod    
endstruct

So, we'll be able to do :

Collapse JASS:
struct myAB
    integer a
    integer b
endstruct
globals
      StructTable<myAB> st
endglobals

function test takes nothing returns nothing
     call st[5].a = st[6].b
endfunction

__________________
Zoom (requires log in)Wc3 map optimizer 5.0
Someone should fix .wav sound in this thing.
Zoom (requires log in)JassHelper 0.A.2.A
Turns your simple code into something that is complicated enough to work.
Faster != more useful
Vexorian is offline   Reply With Quote
Old 11-03-2009, 02:24 AM   #110
Deaod
User
 
Join Date: Jan 2007
Posts: 542

Submissions (11)

Deaod is a jewel in the rough (192)Deaod is a jewel in the rough (192)Deaod is a jewel in the rough (192)

Default

vJass native Tables, frecking cool. Saves me the need to import Table into every map.
__________________
Deaod is offline   Reply With Quote
Old 11-03-2009, 09:39 PM   #111
Mr.Malte
User
 
Mr.Malte's Avatar
 
Join Date: Apr 2008
Posts: 286

Submissions (2)

Mr.Malte is on a distinguished road (11)

Default

Can Tables have the names of structs then?
Actually you could also make a normal array to replace the StructTable, couldn't you?
Mr.Malte is offline   Reply With Quote
Old 11-04-2009, 02:58 AM   #112
weaaddar
User


Respected User
 
Join Date: Apr 2002
Posts: 2,372

Submissions (3)

weaaddar has a spectacular aura about (131)

Default

Completely awesome. Will jasshelper start supporting function with type parameters?
So can I then right default(T) from C#? (This might be tricky as actually default is a keyword in C#, but if Zinc will support a typed function it might work okay too). The issue is that while usually generic functions expose the same code, the following would work for most of them::
Collapse Zinc:
Library DefaultValues
{
  function default<T>()->T
  {
     local T[] val; // is this valid Zinc or is it Local T array val;
     return val[0];
  }
}
But it wouldn't work work for custom types, and code. As you have your weird rules about arrays, and blizzard hates code and doesn't let you declare an array of them.

But that's barely an issue. [Actually I just realized now that you can't store code in a hash table, that is a bit of a bummer]. once you get generics up and running, I'll happily taking my hand at trying to write a bunch of zinc generic containers and iterators. I still wish you used a real "for" structure though.

Last edited by weaaddar : 11-04-2009 at 02:58 AM.
weaaddar is offline   Reply With Quote
Old 11-04-2009, 05:29 AM   #113
Vexorian
Free Software Terrorist
 
Vexorian's Avatar


Technical Director
 
Join Date: Apr 2003
Posts: 14,898

Submissions (37)

Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)

Hero Contest #3 - 2nd Place

Default

functions with type arguments, yes.

T val[];
Bleh I might add a for(;;) thing after adding generics.

There will be specialization anyway.

Collapse JASS:

function Default<handle> takes nothing returns unit
    return null
endfunction

function Default<integer> takes nothing returns integer
    return 0
endfunction


function Default<code> takes nothing returns code //not sure if returns code actually compiles anymore...
    return null
endfunction

// for types not specialized correctly (in this case it would mean real , string and structs/dynamic arrays ...)
function Default<type T> takes nothing returns T
    return 0
endfunction

What I can't decide is if I will be able to declare specializations outside the library that declares the non-specialized template..

Like allowing this:

Collapse JASS:
library ARGB
struct ARGB //insert that ARGB library here
endstruct
function DefaultValue<ARGB> takes nothing returns ARGB
    return ARGB(0xFFFFFFFF)
endfunction
endlibrary

Well, in the case of structs it is sort of fixable without doing that, though...

Collapse JASS:
interface def
    static method  default takes nothing returns integer
    endmethod
endinterface
//declare template for types that extend def
function Default<def T> takes nothing returns T
    return def( T.default()  )
endfunction

Though things other than type (like interfaces) will take a while to come for tempalte arguments... (not to practical without multiple interface implementation anyway)


Edit: code is useless to store anyway, you generally need a trigger to actually run it. So you can just store the trigger itself.


edit: I guess we can just go over the top and ...

Collapse JASS:
function Default<type T> takes nothing returns T
    static if ( T.default.exists ) then
           return T.default()
    else
           return 0
    endif
endfunction
__________________
Zoom (requires log in)Wc3 map optimizer 5.0
Someone should fix .wav sound in this thing.
Zoom (requires log in)JassHelper 0.A.2.A
Turns your simple code into something that is complicated enough to work.
Faster != more useful
Vexorian is offline   Reply With Quote
Old 11-05-2009, 01:42 AM   #114
weaaddar
User


Respected User
 
Join Date: Apr 2002
Posts: 2,372

Submissions (3)

weaaddar has a spectacular aura about (131)

Default

I guess your write, I suppose that means you can't have a code member inside a struct.

That would be neat, and really I think the exist clause is probably the best way to go on a lot of things. However, you need to add something like CJASS's assert keyword so that it can be a compilation error if thats whats intended.


Collapse Zinc:
ForEach takes <type T> col, Func<A,R> funcToApply returns nothing
{
     static if (T.GetEnumerator.Exists)
     {
           ....
     }
     else
     {
           assert("Collection must implement a GetEnumerator method!")
     }
}

This can get around multiple inheritance, of course it feels like cheating too. Also does .exist check in delegates or modules (which I guess are your mixins you talked about)?

Edit:
I'd also like to thank you again for getting rid of the interface name being required when invoking function interfaces. (i.e. func_int_int.Double can now be written Double)

Last edited by weaaddar : 11-05-2009 at 01:48 AM.
weaaddar is offline   Reply With Quote
Old 12-09-2009, 05:15 PM   #115
Hans_Maulwurf
root bloody root
 
Hans_Maulwurf's Avatar
 
Join Date: Mar 2007
Posts: 117

Hans_Maulwurf will become famous soon enough (52)Hans_Maulwurf will become famous soon enough (52)

Send a message via ICQ to Hans_Maulwurf
Default

Could someone post a short example on how to use 2d array syntax?

set Table["thisstring"][ 7 ] = 2 from the readme gives me a syntaxerror
__________________

Suit up! Tonight is gonna be legen... wait for it... DARY!
Hans_Maulwurf is offline   Reply With Quote
Old 12-11-2009, 02:28 PM   #116
Anachron
User
 
Anachron's Avatar
 
Join Date: Mar 2009
Posts: 1,079

Anachron will become famous soon enough (51)Anachron will become famous soon enough (51)

Default

Maybe a small addon?

Collapse JASS:
library Table
//***************************************************************
//* Table object 3.0
//* ------------
//*
//*   set t=Table.create() - instanceates a new table object
//*   call t.destroy()     - destroys it
//*   t[1234567]           - Get value for key 1234567
//*                          (zero if not assigned previously)
//*   set t[12341]=32      - Assigning it.
//*   call t.flush(12341)  - Flushes the stored value, so it
//*                          doesn't use any more memory
//*   t.exists(32)         - Was key 32 assigned? Notice
//*                          that flush() unassigns values.
//*   call t.reset()       - Flushes the whole contents of the
//*                          Table.
//*
//*   call t.destroy()     - Does reset() and also recycles the id.
//*
//*   If you use HandleTable instead of Table, it is the same
//* but it uses handles as keys, the same with StringTable.
//*
//*  You can use Table on structs' onInit  if the struct is
//* placed in a library that requires Table or outside a library.
//*
//*  You can also do 2D array syntax if you want to touch
//* mission keys directly, however, since this is shared space
//* you may want to prefix your mission keys accordingly:
//*
//*  set Table["thisstring"][ 7 ] = 2
//*  set Table["thisstring"][ 5 ] = Table["thisstring"][7]
//*
//***************************************************************

//=============================================================
    globals
        private constant integer MAX_INSTANCES=8100 //400000
        //Feel free to change max instances if necessary, it will only affect allocation
        //speed which shouldn't matter that much.

    //=========================================================
        private hashtable ht
    endglobals

    private struct GTable[MAX_INSTANCES]

        method reset takes nothing returns nothing
            call FlushChildHashtable(ht, integer(this) )
        endmethod

        private method onDestroy takes nothing returns nothing
            call this.reset()
        endmethod

        //=============================================================
        // initialize it all.
        //
        private static method onInit takes nothing returns nothing
            set ht = InitHashtable()
        endmethod

    endstruct

    //Hey: Don't instanciate other people's textmacros that you are not supposed to, thanks.
    //! textmacro Table__make takes name, type, key
    struct $name$ extends GTable
    
        public static method create takes nothing returns thistype
            local thistype this = thistype.allocate()
            
            if this == 0 then
                call BJDebugMsg(SCOPE_PREFIX"ERROR: Increase the instance limit!")
                return -1
            endif

            return this
        endmethod

        method operator [] takes $type$ key returns integer
            return LoadInteger(ht, integer(this), $key$)
        endmethod

        method operator []= takes $type$ key, integer value returns nothing
            call SaveInteger(ht,  integer(this)  ,$key$, value)
        endmethod

        method flush takes $type$ key returns nothing
            call RemoveSavedInteger(ht, integer(this), $key$)
        endmethod

        method exists takes $type$ key returns boolean
            return HaveSavedInteger( ht,  integer(this), key$)
        endmethod

        static method flush2D takes string firstkey returns nothing
            call $name$(- StringHash(firstkey)).reset()
        endmethod

        static method operator [] takes string firstkey returns $name$
            return $name$(- StringHash(firstkey) )
        endmethod

    endstruct
    //! endtextmacro

    //! runtextmacro Table__make("Table","integer","key" )
    //! runtextmacro Table__make("StringTable","string", "StringHash(key)" )
    //! runtextmacro Table__make("HandleTable","handle","GetHandleId(key)" )

endlibrary
__________________
CustomInventory [Discussion - Download] - Got Directors Cut!
CustomMissle [Discussion - [Download (not yet)] - In development!
Other systems [Spawn System] [Move System] [CustomBar] [SpellBar]

Last edited by Anachron : 12-11-2009 at 02:29 PM.
Anachron is offline   Reply With Quote
Old 12-11-2009, 06:58 PM   #117
Mr.Malte
User
 
Mr.Malte's Avatar
 
Join Date: Apr 2008
Posts: 286

Submissions (2)

Mr.Malte is on a distinguished road (11)

Default

Well, I wouldn't add that.
8191 are big enough and you can easily increase the limit, if you think it was too small.
Mr.Malte is offline   Reply With Quote
Old 12-11-2009, 10:24 PM   #118
Fledermaus
default string
 
Fledermaus's Avatar
 
Join Date: May 2006
Posts: 705

Submissions (1)

Fledermaus is a jewel in the rough (194)Fledermaus is a jewel in the rough (194)Fledermaus is a jewel in the rough (194)

Send a message via MSN to Fledermaus
Default

I belive the allocate method already does that anyway?

Collapse JASS:
//Generated allocator of Table___GTable
function s__Table___GTable__allocate takes nothing returns integer
 local integer this=si__Table___GTable_F
    if (this!=0) then
        set si__Table___GTable_F=si__Table___GTable_V[this]
    else
        set si__Table___GTable_I=si__Table___GTable_I+1
        set this=si__Table___GTable_I
    endif
    if (this>8100) then
        call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,1000.,"Unable to allocate id for an object of type: Table___GTable")
        return 0
    endif

    set si__Table___GTable_type[this]=2
    set si__Table___GTable_V[this]=-1
 return this
endfunction

Last edited by Fledermaus : 12-11-2009 at 10:25 PM.
Fledermaus is offline   Reply With Quote
Old 12-11-2009, 11:24 PM   #119
Vexorian
Free Software Terrorist
 
Vexorian's Avatar


Technical Director
 
Join Date: Apr 2003
Posts: 14,898

Submissions (37)

Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)

Hero Contest #3 - 2nd Place

Default

That's only during debug mode.
__________________
Zoom (requires log in)Wc3 map optimizer 5.0
Someone should fix .wav sound in this thing.
Zoom (requires log in)JassHelper 0.A.2.A
Turns your simple code into something that is complicated enough to work.
Faster != more useful
Vexorian is offline   Reply With Quote
Old 12-12-2009, 11:50 AM   #120
Anachron
User
 
Anachron's Avatar
 
Join Date: Mar 2009
Posts: 1,079

Anachron will become famous soon enough (51)Anachron will become famous soon enough (51)

Default

Yeah. Btw, how does the 2 dimensional stuff work?
__________________
CustomInventory [Discussion - Download] - Got Directors Cut!
CustomMissle [Discussion - [Download (not yet)] - In development!
Other systems [Spawn System] [Move System] [CustomBar] [SpellBar]
Anachron is offline   Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off


All times are GMT. The time now is 08:22 PM.


Affiliates
The Hubb The JASS Vault Clan WEnW Campaign Creations Clan CBS GamesModding Flixreel Videos

Powered by vBulletin (Copyright ©2000 - 2020, Jelsoft Enterprises Ltd).
Hosted by www.OICcam.com
IT Support and Services provided by Executive IT Services