Is there a way to create "cross-platform scripting" in GWT?

91 views
Skip to first unread message

Sebastien Diot

unread,
Jun 26, 2013, 7:06:42 AM6/26/13
to google-we...@googlegroups.com
Hi.

I would like to make a "web game" with GWT, and have some of the code "scripted" rather then compiled, to allow dynamic updates/tweaking without rebuilding and re-deploying.

Now the hard part is, what scripting language could I use to execute the scripts that would both run within the JVM and in JavaScript on the browser?

While "JavaScript" would seem like an obvious answer, I fear it would not do, due to the fact that is doesn't support "longs" natively (which I use a lot as IDs ...). Maybe there is an easy work-around, I haven't actually dived into GWT, yet so I would not know about it. I do know that GWT can compile Java code to work correctly as JavaScript even with long, but I don't know if the same solution can be used within hand-made scripts.

Regards,
Sebastien

Carl

unread,
Jun 26, 2013, 10:55:19 AM6/26/13
to google-we...@googlegroups.com
wrt numbers in JavaScript...

All numbers in JavaScript are stored as 64-bit (8-bytes) base 10, floating point numbers. This will probably provide enough space for your IDs. 

Sebastien Diot

unread,
Jun 26, 2013, 11:16:19 AM6/26/13
to google-we...@googlegroups.com
On Wednesday, June 26, 2013 4:55:19 PM UTC+2, Carl wrote:
wrt numbers in JavaScript...

All numbers in JavaScript are stored as 64-bit (8-bytes) base 10, floating point numbers. This will probably provide enough space for your IDs.

This is only true if you assume my IDs start with 0/1, and slowly grow. I also use Java longs to store 64-bit MurmurHash of Strings (class names, ...), which cover the whole "bit range" of a long. This has the great advantage that it allows things that would otherwise be "variable size" to then be "fixed size" when serialized.

Carl Roach

unread,
Jun 26, 2013, 11:25:57 AM6/26/13
to google-we...@googlegroups.com
Why not use Strings in that use case?


--
You received this message because you are subscribed to a topic in the Google Groups "Google Web Toolkit" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-web-toolkit/gC76hol4ZIo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-web-tool...@googlegroups.com.
To post to this group, send email to google-we...@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

David

unread,
Jun 27, 2013, 3:44:37 AM6/27/13
to google-we...@googlegroups.com
Hi,
 
Longs are emulated with 2 doubles. Which is slow, but it should support the full range.
 
If you are only using them for ID's then you better send them over as strings or something else because Long emulation is slow and can sometimes slow down RPC operations.
 
David

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-tool...@googlegroups.com.

Philippe Lhoste

unread,
Jun 27, 2013, 5:01:47 AM6/27/13
to Google-We...@googlegroups.com
You can use Lua, commonly used to script games.
There are some implementations in JavaScript, for example:
http://kripken.github.io/lua.vm.js/lua.vm.js.html
which is optimized and fast.
It might have the same issue with longs, thought, like most languages compiling to
JavaScript... unless a specific workaround / implementation is made.

I haven't tried it in GWT...

--
Philippe Lhoste
-- (near) Paris -- France
-- http://Phi.Lho.free.fr
-- -- -- -- -- -- -- -- -- -- -- -- -- --

Oliver Krylow

unread,
Jul 1, 2013, 4:18:24 PM7/1/13
to google-we...@googlegroups.com


Why does your code need to run on the JVM?

If I was in your position, I would look for a Gwt-only solution. It definitely supports your use case,  look at JSNI and the ScriptInjector.

https://www.google.com/url?q=https://developers.google.com/web-toolkit/doc/latest/DevGuideCodingBasicsJSNI&sa=U&ei=COLRUZbQA4mFtAbvioHQBg&ved=0CAgQFjAA&usg=AFQjCNGfT9UPdKfETb1mMCigT1bLnSruHg

https://www.google.com/url?q=http://www.gwtproject.org/javadoc/latest/com/google/gwt/core/client/ScriptInjector.html&sa=U&ei=2-LRUabPC8XRtAbZwID4Cg&ved=0CAcQFjAA&usg=AFQjCNFUtlqJqyMonzcQM6PMrxIoWl2SsQ

Nonetheless, overall I would advise to use such techniques as little as possible. They make large and complex code bases unstable and hardly testable. They are meant to provide an interface to existing javascript. If your code base is not going to be large and complex, why are you using gwit ;-)

- Oliver

--
Reply all
Reply to author
Forward
0 new messages