Search Unity

JavaScript Dynamic Objects Language Specification

Discussion in 'Scripting' started by waneck, Nov 15, 2009.

  1. waneck

    waneck

    Joined:
    Apr 25, 2009
    Posts:
    8
    Hello all!

    I am creating a Unity JavaScript generator for haXe, but I am finding to be really hard sometimes to understand the language's specifications on a trial and error basis. Is there something more concrete other than some documents at unify ?

    1 - Mostly my concern over unityjs is on dynamic objects. Does it support it at all? Is there any hack to make it work? I have seen that a standards-compilant js compiler for mono was built using the IExpando interface for Dynamic objects. It will be hard, though, to know at compile-time if a field needs to be created. And still, would IExpando work on the iphone?

    2 - Is there any way to create anonymous objects on unityjs? The standard var something = { field:value } does not seem to work, as it is compiled as a Boo hash type.

    3 - I figure that interfaces aren't supported on unityjs, nor do multiple inheritance. Is that right?

    Any information on unityjs will be very much appreciated! Thanks!
     
  2. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    You can not compare Unity's EMCA implementation (called JS or UnityScript) with browser JS.
    It is syntax wise similar and has dynamic typing but that actually is it more or less.
    Its not parsed or alike but compiled to .NET assemblies as Boo and C# too. Its basically a javascript / action script alike syntax thats easier to learn and consume than C# but generally is the more restricted language too as it was designed and created for the purpose of beeing the designer approach to script in unity.
    If you want a powerfull language, then C# (.NET 2.0 level) is the way to go, where you have interfaces and inheritance of a single class in combination with implementing one or more interfaces.
    anonymous xy (xy ={method, object, ...} ) do not exist, outside of the hashtable approach

    As such the answer to all of the 3 questions is no, you can't.
     
  3. waneck

    waneck

    Joined:
    Apr 25, 2009
    Posts:
    8
    Hi dreamora, I am not really comparing UnityScript (actually I really think that this name's more suitable for it) with browser JS. But Dynamic objects is fundamental to ECMA specifications, and it really is quite doable with .NET 2.0, just needs to be some compile-time work on it. You can see it working through microsoft's own implementation of it:

    http://www.microsoft.com/downloads/...FA-7462-47D0-8E56-8DD34C6292F0&displaylang=en

    which does handle closures and dynamic objects!


    But thanks for the answer. My only persisting doubts are if IExpando-like interfaces work with the iPhone target. I actually wanted to do some kind of CLI-magic for dynamic and static interop, but this I think does not work on the iPhone. Am I right?
     
  4. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    iPhone compile is .NET 1.1 AoT compilation, so likely not.


    As for the linked things: Haven't looked deeper into it, but it does not seem to have any relation to Mono 1.2.5 nor in any way usable for Unity work (if you compile own mono 1.2.5 compliant .NET assemblies that uses it then potentially you could use it)

    As for the standard: There are more to the standard than present, right. But there is no requirement to fully implement standards, if thats what is beeing looked for then UnityScript is the wrong thing to learn.

    Once Unity uses Mono 2.x as base, C# will have at least the same level as .NET 3.5 which means it offers most of the things on the desktop (the iphone side can be happy if it ever reaches .NET 2.0 level due to the size constraints for libraries enforced by the iPhone SDK)