| 01-07-2009, 04:19 AM | #1 |
I'm aware the general WC3 compiler does not support Function Overloading directly but I'm curious if there's some way to pull it off. Essentialy what I'm trying to do is overload a function: Code:
struct method TakesAnything takes integer a returns nothing call BJDebugMsg(I2S(a)) endmethod method TakesAnything takes real a returns nothing call BJDebugMsg(R2S(a)) endmethod endstruct Essentialy what I'm trying. I know I can mock-overload something with interfaces, but it requires use of structs whereas I'm trying to use native types. I'd also like to avoid wrapping the native types as structs (if possible) A problem of convenince, it's entirely possible (and simpler) to just make several functions and call them by hand, but it loses oh so much elegance. Thanks ;P. |
| 01-07-2009, 12:17 PM | #2 |
Use a function interface? It's in JassHelper manual |
| 01-07-2009, 10:42 PM | #3 |
I'm overloading natives, as far as I know interfacing only works with structs. Additionaly creating a struct wrapper for the natives would defeat the point of overloading them in the first place :/. Therin lies my problem. |
| 01-08-2009, 12:15 AM | #4 |
Function interfaces don't need structs, they just allow functions to be derived from a main interface as long as they take and return the same paramaters. Does that help? |
| 01-08-2009, 01:46 AM | #5 |
Yes, but my problem comes in when I'm trying to announce the interface for the type. Code:
interface Something method Does takes nothing returns nothing endmethod endinterface type unitx extends Something extends unit For one that wont compile, two I have no idea how I'd even announce the Does function for unitx outside of a struct. But if interfaces have the ability to work outside of a struct... structure, could you show me an example of that? |
| 01-08-2009, 01:55 AM | #6 |
JASS:function interface ValueMessager takes real v returns nothing function FloatMessage takes real x returns nothing call BJDebugMsg(R2S(x)) endfunction function IntMessage takes real x returns nothing call BJDebugMsg(I2S(x)) endfunction function TestMessager takes ValueMessage v returns nothing call v.evaluate() endfunction function DeclareMessager takes nothing returns nothing local ValueMessager v=ValueMessager.IntMessage call TestMessager(v) endfunction This is basically copied from the JassHelper Manual. |
| 01-08-2009, 02:53 AM | #7 |
Basically this shows of what the non-sense the word "overloading" is. For some retarded reason it means 3 different things. What Blackroot was asking for was not function interfaces, as to answer the question, no, not yet. But maybe one day. |
| 01-08-2009, 03:00 AM | #8 |
At least Blackroot knows function interfaces exist now. I was unsure as to what was being sought out. |
| 01-08-2009, 04:43 AM | #9 |
Yes I guess I wasn't very clear on my intentions, it is an ambigious thing -,-. What I really wanted was this: Code:
function Something takes integer x || real x returns nothing case integer: //Do stuff case real: //Do stuff endfunction There is really nothing special about this, I just wanted to avoid: Code:
function SomethingInt takes integer x returns nothing endfunction function SomethingReal takes integer y returns nothing endfunction Interfaces don't help me because I cannot change native types nor can I make wrappers to extend them. The only way to implement it would be: Code:
interface Something method Do takes nothing returns nothing endinterface struct IntWrapper extends Something integer I method Do takes nothing returns nothing call BJDebugMsg(I2S(I)) endmethod endstruct struct RealWrapper extends Something real I method Do takes nothing returns nothing call BJDebugMsg(R2S(I)) endmethod endstruct struct MyStruct IntWrapper I RealWrapper F static method create takes nothing returns nothing local MyStruct ms = MyStruct.allocate() set ms.F = RealWrapper.create() set ms.I = IntWrapper.create() endmethod method DoSomething takes Something f returns nothing call Do(f) endmethod method OrDoItThisWay takes boolean b returns nothing if(b == true)then call Do(.I) else call Do(.F) endif endmethod endstruct I doubt that code would actually run, but it's a godawful mess to implement if it does and it's not even as elegant as it should be. One method requires the user to pass a boolean and would mean he would have to pass arguments for both cases if there were any arguments. In the other method it requires the user to create a wrapper, which defeats the point of trying to make it look prittier. Oh well though, I have no way of comparing types so I guess I'm stranded with announcing clone functions >.<. Oh well, thank you very much for the help anyways Zerzax and Vex :P. |
