hscript and typedef

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

hscript and typedef

cornel-2
It looks that I cant use typedef in hscript. Are they suported or I am
missing something?

Thanks
Cornel

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

Re: hscript and typedef

back2dos
typedefs are a haXe compile time feature ... hscript is never compiled
and is completely untyped ...

greetz
back2dos
> It looks that I cant use typedef in hscript. Are they suported or I am
> missing something?
>
> Thanks
> Cornel
>
>  


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

Re: hscript and typedef

cornel-2
I see, thanks. I was trying to do something like

typedef AClass = a.very.long.package.name.AClass

Is there any other way to alias a type?

2009/8/6 Juraj Kirchheim <[hidden email]>:

> typedefs are a haXe compile time feature ... hscript is never compiled and
> is completely untyped ...
>
> greetz
> back2dos
>>
>> It looks that I cant use typedef in hscript. Are they suported or I am
>> missing something?
>>
>> Thanks
>> Cornel
>>
>>
>
>
> --
> 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: hscript and typedef

back2dos
well, this is the possibly most hacky solution i could think of ... :D
it allows you to instantiate variables, so you can simply do

var a = a.very.long.package.name.AClass

hope that helps ...

greetz
back2dos

> I see, thanks. I was trying to do something like
>
> typedef AClass = a.very.long.package.name.AClass
>
> Is there any other way to alias a type?
>
> 2009/8/6 Juraj Kirchheim <[hidden email]>:
>  
>> typedefs are a haXe compile time feature ... hscript is never compiled and
>> is completely untyped ...
>>
>> greetz
>> back2dos
>>    
>>> It looks that I cant use typedef in hscript. Are they suported or I am
>>> missing something?
>>>
>>> Thanks
>>> Cornel
>>>
>>>
>>>      
>> --
>> haXe - an open source web programming language
>> http://haxe.org
>>
>>    
>
>  

Index: Interp.hx
===================================================================
--- Interp.hx (revision 26)
+++ Interp.hx (working copy)
@@ -200,7 +200,15 @@
  locals.set(d.n,d.old);
  }
  }
-
+    function getVarValue(id:String, ?panicIfUnknown = true) : Dynamic {
+ var l = locals.get(id);
+ if( l != null )
+ return l.r;
+ var v = variables.get(id);
+ if( panicIfUnknown && (v == null) && !variables.exists(id) )
+ throw Error.EUnknownVariable(id);
+ return v;
+ }
  public function expr( e : Expr ) : Dynamic {
  switch( e ) {
  case EConst(c):
@@ -211,13 +219,7 @@
  case CString(s): return s;
  }
  case EIdent(id):
- var l = locals.get(id);
- if( l != null )
- return l.r;
- var v = variables.get(id);
- if( v == null && !variables.exists(id) )
- throw Error.EUnknownVariable(id);
- return v;
+ return getVarValue(id);
  case EVar(n,e):
  declared.push({ n : n, old : locals.get(n) });
  locals.set(n,{ r : (e == null)?null:expr(e) });
@@ -406,7 +408,10 @@
  }
 
  function cnew( cl : String, args : Array<Dynamic> ) : Dynamic {
- return Type.createInstance(Type.resolveClass(cl),args);
+    var val = getVarValue(cl);
+ if (val == null)
+ return Type.createInstance(Type.resolveClass(cl),args);
+ return Type.createInstance(val, args);
  }
 
 }
\ No newline at end of file

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

Re: hscript and typedef

gershon
In reply to this post by cornel-2
for construction you can use strings and Type:

var path = ["a", "very", "long", "package", "name"];

var resolved = Type.resolveClass(path.push("AClass".join("."));
var args = [];

Type.createInstance(resolved, args);


On Thu, Aug 6, 2009 at 8:05 PM, cornel <[hidden email]> wrote:
I see, thanks. I was trying to do something like

typedef AClass = a.very.long.package.name.AClass

Is there any other way to alias a type?

2009/8/6 Juraj Kirchheim <[hidden email]>:
> typedefs are a haXe compile time feature ... hscript is never compiled and
> is completely untyped ...
>
> greetz
> back2dos
>>
>> It looks that I cant use typedef in hscript. Are they suported or I am
>> missing something?
>>
>> Thanks
>> Cornel
>>
>>
>
>
> --
> haXe - an open source web programming language
> http://haxe.org
>

--
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: hscript and typedef

cornel-2
In reply to this post by back2dos
I'll try this, thanks a lot.

Cornel

2009/8/6 Juraj Kirchheim <[hidden email]>:

> well, this is the possibly most hacky solution i could think of ... :D
> it allows you to instantiate variables, so you can simply do
>
> var a = a.very.long.package.name.AClass
>
> hope that helps ...
>
> greetz
> back2dos
>>
>> I see, thanks. I was trying to do something like
>>
>> typedef AClass = a.very.long.package.name.AClass
>>
>> Is there any other way to alias a type?
>>
>> 2009/8/6 Juraj Kirchheim <[hidden email]>:
>>
>>>
>>> typedefs are a haXe compile time feature ... hscript is never compiled
>>> and
>>> is completely untyped ...
>>>
>>> greetz
>>> back2dos
>>>
>>>>
>>>> It looks that I cant use typedef in hscript. Are they suported or I am
>>>> missing something?
>>>>
>>>> Thanks
>>>> Cornel
>>>>
>>>>
>>>>
>>>
>>> --
>>> haXe - an open source web programming language
>>> http://haxe.org
>>>
>>>
>>
>>
>
>
> Index: Interp.hx
> ===================================================================
> --- Interp.hx   (revision 26)
> +++ Interp.hx   (working copy)
> @@ -200,7 +200,15 @@
>                        locals.set(d.n,d.old);
>                }
>        }
> -
> +    function getVarValue(id:String, ?panicIfUnknown = true) : Dynamic {
> +               var l = locals.get(id);
> +               if( l != null )
> +                       return l.r;
> +               var v = variables.get(id);
> +               if( panicIfUnknown && (v == null) && !variables.exists(id) )
> +                       throw Error.EUnknownVariable(id);
> +               return v;
> +       }
>        public function expr( e : Expr ) : Dynamic {
>                switch( e ) {
>                case EConst(c):
> @@ -211,13 +219,7 @@
>                        case CString(s): return s;
>                        }
>                case EIdent(id):
> -                       var l = locals.get(id);
> -                       if( l != null )
> -                               return l.r;
> -                       var v = variables.get(id);
> -                       if( v == null && !variables.exists(id) )
> -                               throw Error.EUnknownVariable(id);
> -                       return v;
> +                       return getVarValue(id);
>                case EVar(n,e):
>                        declared.push({ n : n, old : locals.get(n) });
>                        locals.set(n,{ r : (e == null)?null:expr(e) });
> @@ -406,7 +408,10 @@
>        }
>
>        function cnew( cl : String, args : Array<Dynamic> ) : Dynamic {
> -               return Type.createInstance(Type.resolveClass(cl),args);
> +           var val = getVarValue(cl);
> +               if (val == null)
> +                       return
> Type.createInstance(Type.resolveClass(cl),args);
> +               return Type.createInstance(val, args);
>        }
>
>  }
> \ No newline at end of file
>
> --
> 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: hscript and typedef

back2dos
ah, no ... just figured, that'll not work at all ... :( ... even i
forgot to pass false to getVarVal in cnew ...

Index: Interp.hx
===================================================================
--- Interp.hx (revision 26)
+++ Interp.hx (working copy)
@@ -200,7 +200,15 @@
  locals.set(d.n,d.old);
  }
  }
-
+    function getVarValue(id:String, ?panicIfUnknown = true) : Dynamic {
+ var l = locals.get(id);
+ if( l != null )
+ return l.r;
+ var v = variables.get(id);
+ if( panicIfUnknown && (v == null) && !variables.exists(id) )
+ throw Error.EUnknownVariable(id);
+ return v;
+ }
  public function expr( e : Expr ) : Dynamic {
  switch( e ) {
  case EConst(c):
@@ -211,13 +219,7 @@
  case CString(s): return s;
  }
  case EIdent(id):
- var l = locals.get(id);
- if( l != null )
- return l.r;
- var v = variables.get(id);
- if( v == null && !variables.exists(id) )
- throw Error.EUnknownVariable(id);
- return v;
+ return getVarValue(id);
  case EVar(n,e):
  declared.push({ n : n, old : locals.get(n) });
  locals.set(n,{ r : (e == null)?null:expr(e) });
@@ -406,7 +408,10 @@
  }
 
  function cnew( cl : String, args : Array<Dynamic> ) : Dynamic {
- return Type.createInstance(Type.resolveClass(cl),args);
+    var val = getVarValue(cl, false);
+ if (val == null)
+ return Type.createInstance(Type.resolveClass(cl),args);
+ return Type.createInstance(val, args);
  }
 
 }
\ No newline at end of file

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

Re: hscript and typedef

back2dos
In reply to this post by cornel-2
woop, that was sent a little too fast ... what i wanted to amend is,
that this way you can use Interp::variables.set("classAlias",
very.long.package.Class) ... it's not exactly what you wanted to do, but
should do the trick as well ...

greetz
back2dos

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