smarty

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

smarty

go2ghana
hi,
I'd like to write an extern for the smarty template engine.

how can I express the signatures like these in haXe:

|void append(mixed var);|
|void append(string varname,
mixed var,
bool merge);|

cordially,
axel

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: smarty

Robin Palotai
Maybe you can use Dynamic for mixed, if that is the question.

On Thu, Jan 13, 2011 at 8:43 AM, Axel Huizinga <[hidden email]> wrote:

> hi,
> I'd like to write an extern for the smarty template engine.
>
> how can I express the signatures like these in haXe:
>
> |void append(mixed var);|
> |void append(string varname,
> mixed var,
> bool merge);|
>
> cordially,
> axel
>
> --
> haXe - an open source web programming language
> http://haxe.org
>

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: smarty

Simon Krajewski
In reply to this post by go2ghana
  I usually approach method overloading by using an enum as parameter:

enum AppendArgs {
     A1(mixed:Dynamic);
     A2(varname:String, mixed:Dynamic, merge:Bool);
}

static public function append(v:AppendArgs) {
     switch(v) {
         case A1(mixed):
             // call append(mixed)
         case A2(varname, mixed, merge):
             // call append(varname, mixed, merge)
     }
}

append(A1("test"));
append(A2("foo", "test", true));

There's probably an easier solution to this, but this is typesafe and
only requires slighty less typing on the client side than real overloading.

Random idea in the morning: The compiler could (in case of enum method
parameters) match a call to append("test") against the enum constructors
and implicitly insert the matching constructor, so append("test") gets
translated to append(A1("test")). But this probably has some deep
problems I'm not aware of.

Regards
Simon

Am 13.01.2011 08:43, schrieb Axel Huizinga:

> hi,
> I'd like to write an extern for the smarty template engine.
>
> how can I express the signatures like these in haXe:
>
> |void append(mixed var);|
> |void append(string varname,
> mixed var,
> bool merge);|
>
> cordially,
> axel
>

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: smarty

go2ghana
Am 13.01.2011 09:42, schrieb Simon Krajewski:

>  I usually approach method overloading by using an enum as parameter:
>
> enum AppendArgs {
>     A1(mixed:Dynamic);
>     A2(varname:String, mixed:Dynamic, merge:Bool);
> }
>
> static public function append(v:AppendArgs) {
>     switch(v) {
>         case A1(mixed):
>             // call append(mixed)
>         case A2(varname, mixed, merge):
>             // call append(varname, mixed, merge)
>     }
> }
>
> append(A1("test"));
> append(A2("foo", "test", true));
>
> There's probably an easier solution to this, but this is typesafe and
> only requires slighty less typing on the client side than real
> overloading.
>
> Random idea in the morning: The compiler could (in case of enum method
> parameters) match a call to append("test") against the enum
> constructors and implicitly insert the matching constructor, so
> append("test") gets translated to append(A1("test")). But this
> probably has some deep problems I'm not aware of.
Same here but would be really useful to have.

>
> Regards
> Simon
>
> Am 13.01.2011 08:43, schrieb Axel Huizinga:
>> hi,
>> I'd like to write an extern for the smarty template engine.
>>
>> how can I express the signatures like these in haXe:
>>
>> |void append(mixed var);|
>> |void append(string varname,
>> mixed var,
>> bool merge);|
>>
>> cordially,
>> axel
>>
>


--
haXe - an open source web programming language
http://haxe.org