wiki‎ > ‎Documentation‎ > ‎

Programming Guidelines

Keep your code simple as not all code constructs can be translated to other languages (yet).

Microsoft Visual Studio

  JSC uses Microsoft Visual Studio to build applications as a .Net IDE to target other platforms. So building for multi-platform JSC applications is a lot like building ordinary .Net applications. JSC uses Managed Classes, library references,  Namespaces, classes, etc. Certain things are not supported when converting code to other platforms, so make sure to read the Limitations section below.
  In building your projects, it is highly recommended you start with either a JSC Ultra Template or a sample application, both of which are available from this website. Go ahead and create a JSC project with a template or sample to help you follow along with these guidelines. 
   Post-build events in Visual Studio can be found by opening the Project Properties, Events Tab, Post-Build events Tab. JSC Templates and samples use one of two methods to invoke post-build events: it may include the post-build commands directly in the post-build window or by calling a build.bat file which is found under Tools folder inside the project files.
   Post-build events are communicated to Visual Studio with either success of failure, and most of the post-build errors can be better understood from the Output window instead of the Error window listings.

What's not Supported / Limitations

  • Common Methods that are currently unsupported are either unavailable within the IDE (syntax error) or will throw a NotImplemented Exception at compile time.
  • Java database annotations are not yet supported
  • Not all Native Classes are yet supported but most can be added within your project (see section below, Adding Native Classes). We're also working on having these added directly to JSC ScriptCoreLib.
  • 'switch' statements are not supported
  • highly complex if-statements are recommended to be broken up into multiple smaller boolean statements for the time-being.

Adding Native Classes

    A Native class is a class belonging to a platform such as java.awt.CheckBox in Java, or flash.display.Sprite for Flash.  JSC requires stub files and classes to be defined in C#/VB in order to use these Native classes within Visual Studio.  JSC ScriptCoreLib, ScriptCorelibJava and other JSC libraries are stubs to native classes of the various platforms.  We plan to have most of the Native classes defined in JSC libraries, but there will always be some classes you will want to  use that we have not yet included. The following example shows how this is done:

  Say you wanted to use Java CheckBox and you found that it was not available in ScriptCoreLib. First step is to find where CheckBox is in the namespace: java.awt.CheckBox. Next step it to find a similar class file within ScriptCoreLib and use it as a model template, such as Button: Search the CheckBox class on the Internet or vendor site (Java, for this example) to make sure you're creating the class correctly within JSC. Once you've created your new Native file, just add it to your project. You can now use the CheckBox class and methods you define normally.

Useful links for this section:

Sharing common Classes Among Platforms 

With JSC, your multi-platform solutions can share code seamlessly from any generic-coded Class. But sometimes it makes most sense to have a separate project within the multi-platform solution that contains this base or common code.  This section describes how to use a separate Library Project, within a Visual Studio Solution, to contain all your Multi-Platform Common Classes that can be re-used and shared among all your target platforms.

NOTE: You can share common code with other platforms without the use of such a Library Project as described here. This is simply one of the methodologies you may want to employ.

The best way to do this is using a DLL Class Library project. Steps must be taken to ensure API or platform-dependent code isn't used within this shared code in order to provide seamless interoperability between platforms. Review our references and programming guidelines as to which types and APIs are available for all platforms (or your target platforms) and these are safe to use within your shared code.

Take the following steps to enable your Shared/Common project to work with any of JSC supported platforms:
  • First step is to add the Class Library  Project (let's call it the Common project)  to the multi-platform solution in your Microsoft Visual Studio
  • Turn off Optimize Code (under Common project properties, in Build tab, un-check Optimize Code)
  • Add references to ScriptCoreLib and ScriptCoreLibA ( right-click References folder in the Common project, select Add Reference, Browse, and find the ScriptCoreLib.dll and ScriptCoreLibA.dll inside the JSC installation, usually at c:\util\jsc\bin )
  • Add the "[Script]" tag to each class you wish to share within the Common project
  • Add the following code at the end of the AssemblyInfo.cs file, under Properties folder in your Common project:      
                        [assembly: Obfuscation(Feature = "script")]
  • Now in the "Other" web-platform projects:
    • add a reference to the Common project ( right-click References folder in your "Other" projects, and from the Projects tab, select Common).
    • Then add the following code at the top of the "Other" project  files: 
                                using Common;   (Assuming this is the Namespace in the Common project that you used)
    • Done. Use the classes from the Common project freely.

Working with External/3rd Party Libraries

    Similar to Native classes, external libraries can easily be included inside your project using the same stub method as for Adding Native Classes.  The difference here is that JSC will need to be able to find the external libraries for the given platform. The FiNT Particle blog post shows how this is done. JSC Classic Templates and some sample projects currently support 3rd party libraries.
   JSC Ultra templates currently have not yet integrated using 3rd party libraries. See Roadmap for target for this feature.

Basic Types

the type int is treated the same throughout all platforms. Managed code for int also includes int.parse method which is also supported throughout all JSC platforms. All int comparisons and arithmetic operations can also be used as normally.

the type string also exhibits common behavior. Using '+' or += for string concat is supported, and  assignment within "quotes" are also as expected behaviors.
  JSC also supports using StringBuilder as a managed string class. Review the JSC Programming Reference module below to see all detailed methods supported for the various platforms for StringBuilder.

this is another type that can be used among all platforms without reservations, treated equally.

Programming with ScriptCoreLib

ScriptCoreLib contains all the API libraries for all platforms. You can use these libraries accordingly withing JSC projects.