[haXe] best strategy to port an existing js library

Ian bcposn802 at sneakemail.com
Fri Dec 7 17:50:17 CET 2007


I hadn't seen that before.  I'll have to read over the rest of the magic 
reference.

strangely, the first example works, but the second doesn't compile:

---
class Main {
  public static function main() {
    var tmp = untyped __js__("niceAlert(\"hello to you\");");
  }
}
---
class Main {
  public static function main() {
    __js__("niceAlert(\"hello to you\");");
  }
}
---
the compiler says: "Test1.hx:5: characters 4-10 : Unknown identifier : __js__"


Benjamin Dasnois benjamin.dasnois-at-gmail.com |haxe| wrote:
> Don't forget about the magic __js__ too, it could be useful.
>
> On Dec 7, 2007 5:10 PM, Franco Ponticelli <franco.ponticelli at gmail.com> wrote:
>   
>> Yes, I think you are correct. The only two options are depicted in the
>> example below... any other idea?
>>
>> // js library
>> function niceAlert(txt) {
>>   alert("### " + txt + " ###");
>> }
>>
>> // haxe code
>> class Main {
>>     public static function main() {
>>     Main.msg("hello to you");
>>     Main.msg2("goodbye");
>>     }
>>
>>   public static var msg : String -> Void = untyped niceAlert;
>>
>>   public static function msg2(s : String) {
>>     untyped niceAlert(s);
>>   }
>> }
>>
>> Franco.
>>
>>
>>
>> On Dec 7, 2007 3:42 PM, Ian <bcposn802 at sneakemail.com > wrote:
>>     
>>> how would you call a javascript function from haXe?  It seems like
>>> extern only works with classes.
>>> I guess I could wrap the javascript functions in a javascript class.
>>>
>>> -ianxm
>>>
>>>
>>> Franco Ponticelli franco.ponticelli-at-gmail.com |haxe| wrote:
>>>       
>>>> There is no loader and I doubt you need one since you can include your
>>>> JS library just before the haXe generated file.
>>>> About wrapping you can use both extern or typedef depending on what
>>>> you are implementing.
>>>> In your case the extern could be the right solution.
>>>>
>>>> extern HelloClass {
>>>>   public function new() : Void;
>>>>   public function showText() : String;
>>>> }
>>>>
>>>> Pay attention to the case of fields that in haXe must start with a
>>>> lower case letter. This can be origin to incompabilities.
>>>>
>>>> Regards,
>>>> Franco.
>>>>
>>>> On Dec 7, 2007 11:00 AM, picnic < bitvolt at gmail.com
>>>>         
>>>> <mailto:bitvolt at gmail.com>> wrote:
>>>>
>>>>     hi
>>>>     what is best strategy to port an existing js library? How is
>>>>     encapsulation done, e.g.  for an js class in a separate file:
>>>>
>>>>     -------------HelloClass.js------------------
>>>>     function HelloClass(){
>>>>        var m_text = "Hello World";
>>>>        this.ShowText = DisplayText;
>>>>       function DisplayText(){
>>>>            alert( m_text );
>>>>            return;}}
>>>>     --------------------------------------------------
>>>>
>>>>     i guess there should be some kind of a loader function in haxe.js
>>>>
>>>>     thanks
>>>>     picnic
>>>>
>>>>     --
>>>>     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
>>
>>     
>
>   





More information about the Haxe mailing list