c# to javascript, actionscript

October 1, 2009

jsc is awesome

Filed under: jsc — Tags: , , , , , — zproxy @ 7:40 am

Now that I got your attention:

There is a new release for jsc with two new screencasts. This time around you are able to omit [Script] attribute and ditch the tools/build.bat. The jsc solution now includes  the jsc.meta compiler which will talk to the other compilers for you.

I am also experimenting with pre compilers. For example the Forms example makes use of TextualUserControl and TextComponent. Without getting too technical they generate a new assembly and add the reference to your csproj file. This opens up some really interesting possibilities. I will talk more about this in future posts.

Future pre compilers in jsc solution could include automatic stub generators for java jar files and for flash swf and swc files.

Open javascript version.

Open actionscript version.

Open javascript version.

Open java version:

demobutton.png

PS. Video parameters “&w=800&fmt=18″

August 31, 2009

Delaunay triangulation

Filed under: jsc — Tags: , , , , — zproxy @ 6:28 am

There is a new example in town and it is about Delaunay triangulation. The original java source code can be found here.

DelaunayExample

source

With this example I had to add a significant bit of awt and swing classes to ScriptCoreLibJava which ofcourse will deem helpful once it is time to start implementing Windows Forms for java.

PS. Did you know? javax.swing.plaf stands for platform look and feel :)

Problems at porting which should be fixed in the future versions:

  • C# won’t allow nested classes in interface. Workaround is to use “sattelite” nesting parent class.
  • Calling base method from a virtual method seems to be broken and will cause stack overflow. fixed
  • The is operator in if expression was missing parenthesis. Workaround is to use local variable.
  • The boolean comparision in if expression should be optimized. Workaround is to use local variable.

July 28, 2009

Stress testing Google App Engine

Filed under: jsc — Tags: , , — zproxy @ 6:29 am

So I have this idea to utilize Google App Engine as a multiplayer game lobby. Flash games tend to peak high upon the very first days of the release. As there are quotas for free service I had to run some tests to get an idea what to expect. At this time I am using memcache as a game server registrar. The registration was set to expire within 1 minute. I prepared a stressor program to issue game server registrations an a continuous loop.

count

requests

In 12 hours I had issued about 40000 game server registrations.  It seems the CPU time is quite high. The average response time was also 22 seconds. Now I need to implement the logic that a game would first try to connect another game before promoting itself as a server.

Update: You can use a naked domain with google app engine with an URL redirect.

July 13, 2009

Nobody likes the records that I play

Filed under: jsc — Tags: , , — zproxy @ 7:02 am

It is time to make yet another release of my jsc compiler. This time around you can finally use anonymous non generic delegates with java. Coolness! Subscribing to events and threading is now much easier. For applets you’d need to write a delegate to interface wrapper tho…

In the release you have a project template at C:\util\jsc\templates\OrcasJavaConsoleApplication.zip

At this time I modified it to show off the anonymous delegate support. In debug build mode this project can be debugged using F5 in Visual Studio on .net. If release build was selected the jsc compiler will be invoked as a post build event to generate java source code then javac and jar will be invoked. To run the new java package you need to start the tools/run.jar.bat.

javaevents by you.

How will that delegate keyword work out in java source code you ask? Here is the Program.java for you to inspect.

javaevents2 by you.

As you can see there is some magic involved, where magic is the compile time code generation. While jsc has been around for years – it took just that long to actually implement the delegate support. It is running via reflection and as such not really that performant, but at this time we cannot take a function pointer in java can we.

PS. It seems sourceforge is not showing statistics for me anymore – whats up with that?

June 22, 2009

new example: ThreadingExample

Filed under: jsc — Tags: , , , — zproxy @ 9:08 am

In this example I am going to demonstrate how to write a java applet with a background thread.

Here is a list of the use cases for code written as such:

  • Java Applet
  • Java Console Application
  • .NET Console

Additionally I have added support for mouse enter and leave events the java way. While in .net it is easy to subscribe to events using anonymous delegates, such a feature is not yet supported by jsc compiler for java target. It could be resolved in the future releases by adding support for generics and build dynamic invokation on reflection. Google App Engine and Android markets are probably going to trigger that update.

For what do we need a background thread

I have created a simple infinite incrementing loop to serve as our business layer. There is a special class ThreadedAction, which abstracts away thread creation, which in turn differs from .net to java from being delegate based to being interface based.

24 while (true)

25 {

26 Value++;

27

28 // we should be running on our own thread

29 // which enables us to loop forever and sleep when tired :)

30 Thread.Sleep(100);

31 }

How do we spawn a new thread

As I enjoy the AtDelay and AtInterval extension methods I make use of while programming for actionscript and javascript, I had to implement something similar for the threading API. Therefor spawning a new thread is dead simple:

57 CurrentThreadedAction = 0.AtDelay(Current);

Why not try to test it out running as a console.

The assembly has been defined as a console exe. Hitting F5 in debug build will show you the console asking your input when to stop the computation.

ConsoleScreenshot

We now saw that our threaded application does run inside .net. It is time to run it on java virtual machine. To do that we need to build our project with release build. This will trigger jsc to genereta java source code and afterwards java compiler will add final magic.

You cannot just press F5 now, instead you should start run.jar.bat. I am using Scite and by double clicking on the bat file Scite shows up in which I can press F5.

JVMConsoleScreenshot

Notice that, only the title is different.

Let’s add an applet interface

Console applications are cool, but applets also have its role to play in our example. The applet form is set up in two steps. In file DemoApplet.Designer.cs I am going to define the buttons and attach handlers.

37 this.Button3 = new Button {};

38 this.Button3.setLabel(“Compute”);

39 this.Button3.addMouseListener(new Button3_MouseEnter_Handler { Target = this });

40 this.Button3.addMouseListener(new Button3_MouseExit_Handler { Target = this });

41

42 base.add(Button3);

I know you would rather use delegates – I would, but I cannot just yet. In file DemoApplet.cs I am going to define the actual handlers.

97 #region [this.Button3_MouseEnter]

98 [Script]

99 class Button3_MouseEnter_Handler : MouseListener_MouseEnter

100 {

101 public ThreadingExample Target;

102

103 protected override void Invoke()

104 {

105 Target.Button3_MouseEnter();

106 }

107 }

108 #endregion

109

110 public void Button3_MouseEnter()

111 {

112 this.Button1.Enabled = false;

113 this.Button2.Enabled = false;

114

115 this.MyComputation.Start();

116

117 this.Button1.setLabel(“start @ “ + MyComputation.Current.Value);

118 this.Button2.setLabel(“Stop computing”);

119

120 }

In the applet I could start the computation either by explicitly clicking on the start button or hovering your mouse on the third button.

Summary

In this example I demonstrated how to write a threaded applet which handles mouse enter and mouse leave events for starting and stopping computation.

ThreadingExample

June 9, 2009

Minecraft

Filed under: games — Tags: , , — zproxy @ 7:01 pm

http://www.minecraft.net/img/logo.gif

Check out this cool java game :)

minecraft by you.

May 1, 2009

Mandelbrot

Filed under: jsc — Tags: , , , , , , , — zproxy @ 9:46 am

One single static C# class implementation to rule them all.

The other day I found an example of Mandelbrot implementation for Silverlight. I have created this example solution to serve as a reference implementation.

This single Mandelbrot implementation is reachable for these platforms:

  1. Windows Forms
  2. Windows Presentation Foundation
  3. Silverlight (3.0 beta)
  4. Java Applet
  5. Flash
  6. Javascript (Firefox, Safari)

For those of you who are new, jsc compiler is going to generate source code for you. While you write your algorithm in C# in current case it can be retranslated to java, actionscript, c and javascript to enable other platforms. Do leave a comment if you would like to know more about it.

April 26, 2009

Scenarios for jsc

Filed under: jsc — Tags: , , , , — zproxy @ 8:31 am

This was my first anwser at  Stack Overflow.

The jsc compiler project enables these scenarios:

  • C# to MSIL to JavaScript for browser
  • C# to MSIL to JavaScript for AppJet
  • C# to MSIL to PHP5 for hosting solutions
  • C# to MSIL to Java for browser applets
  • C# to MSIL to Java for applications
  • C# to MSIL to Java for JavaCard
  • C# to MSIL to C99 for native stub applications
  • C# to MSIL to ActionScript3 for Flash 9
  • C# to MSIL to Adobe Alchemy C for Flash 9
  • C# to MSIL to C# 2.0

With some effort Visual Basic could also be used as a source language. The jsc compiler never reads your source code even if GWT and Script# do that. My compiler reads your IL.

jsc compiler is

  • an experimental project
  • one mans effort yet
  • rather useful already.
  • 3 years old.
  • awaiting donations to optimize compilation time and output itself

The latest example is a plasma animation where a single implementation can be used between those platforms:

April 8, 2009

Google App Engine SDK for Java

Filed under: life — Tags: , , , , , — zproxy @ 10:05 am

Powered by Google App Engine

App Engine runs Java applications using the Java 6 virtual machine (JVM).

  • CPU Time: 6.5 hours of CPU time per day
  • Bandwidth: 1 gigabyte of data transferred in and out of the application per day
  • Stored Data & Email Recipients: unchanged

I think I will create an example how to write for Google App Engine in C# via my jsc compiler within this month.

Unless ofcourse they will support MSIL natively which I dont think will happen…

You may wonder whatever happened to MS Java or maybe J#

Some feedback from Slashdot on the Google App Engine topic:

[...] It’s not the restrictions, it’s the implementation. Normally, existing Java code could just be compiled on the embedded system, and compiler errors would specifically identify security reasons for specific classes/methods/etc being disabled. Google removed the classes entirely, so the developer will just get IDontKnowWTFThatClassIs exceptions instead, which are less informative.

It also contravenes existing standards, sort of like making “dangerous” files invisible to unprivileged users in *NIX (via some sort of arcane black magic, perhaps a modified (munged) shell or something…) instead of just setting appropriate file permissions.

Did you know that your application will be running on multiple VM’s. So we do actually have threading support, it is just i another form.

[...] It even supports loading bytecode generated at run time. That means that our new Java runtime can support any language with a compiler that targets the JVM

You need to take extra care to enable HTTP sessions to which you could write data. It may look like a vendor lock in solution whether it is or is not remains to be decided…

(more…)

November 20, 2008

AvalonWebApplication with PHP backend

Filed under: jsc — Tags: , , , , , , , — zproxy @ 7:41 pm

I have created a new project template that demonstrates most of what jsc is capable of. Soon I will publish it on the sourceforge with a tutorial how to get started using it.

Long story short – Here is an application which demonstrates the following features all written in C#:

  1. PHP Backend
  2. JavaScript (WPF)
  3. ActionScript (WPF)
  4. Java Applet

Update: Moved the example to sourceforge and removed the querystring switch.

July 17, 2008

Two New Examples

Filed under: jsc — Tags: , , , , , , — zproxy @ 3:11 pm




The RayCaster is based on this source and is just what you need to when you start making one of these Wolf3D games. The ZIndex demo shows how you could emulate the missing z-index property in flash 9.

June 12, 2008

Jsc June Refresh 2

Filed under: jsc — Tags: , , , , , , , , , , — zproxy @ 4:29 pm

Some updates to the compiler and the framework: Download jsc here. (Others already have!)

Added two Java project templates.

Visit our google groups.

Tutorials to read when just starting with jsc:

This release contains the following Project Templates:

OrcasAppletApplication – C# to Java Applet
OrcasFlashApplication – C# to ActionScript
OrcasScriptApplication – C# to JavaScript
OrcasVisualBasicFlashApplication – VB.NET to ActionScript
OrcasVisualBasicScriptApplication – VB.NET to JavaScript
OrcasWebApplication – C# to JavaScript as Microsoft Web Application
OrcasWebSite – C# to JavaScript as Microsoft ASP.NET Web Site
OrcasJavaConsoleApplication – C# to Java as Console Application
OrcasNativeJavaConsoleApplication – C# to Java as Console Application with JNI bindings.

Have a look at some old screencasts:

June 6, 2008

Jsc June Refresh

Filed under: jsc — Tags: , , , , , , , , , , — zproxy @ 2:43 pm

Some updates to the compiler and the framework: Download jsc here.

Most important update was fixing the virtual + override semantics for jsc:actionscript. It’ did not allow to combine multiple events for example.

Visit our google groups.

Tutorials to read when just starting with jsc:

This release contains the following Project Templates:

OrcasAppletApplication – C# to Java Applet
OrcasFlashApplication – C# to ActionScript
OrcasScriptApplication – C# To JavaScript
OrcasVisualBasicFlashApplication – VB.NET to ActionScript
OrcasVisualBasicScriptApplication – VB.NET to JavaScript
OrcasWebApplication – C# to JavaScript as Microsoft Web Application
OrcasWebSite – C# to JavaScript as Microsoft ASP.NET Web Site

Writing code in VB.NET for flash looks like this:

Blog at WordPress.com.