Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (481)
Games in Android Showcase (110)
games submitted by our members
Games in WIP (548)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Scripting for games using Java  (Read 2974 times)
0 Members and 1 Guest are viewing this topic.
Offline zingbat

Senior Member




Java games rock!


« Posted 2009-09-01 22:15:29 »

Better than using some crappy scripting language for a game is to use Janino

http://www.janino.net/

an embedded java compiler and which can load java classes directly from java source.

The problem with this is nothing prevents a modder who creates some extension for a game to access the java.io.* package and do all sorts of nasty things  without any restrictions.

My question is there a simple way to restrict a modders script when using Janino or other embedded java compiler as a game scripting solution?
Offline Nate

JGO Kernel


Medals: 145
Projects: 4
Exp: 14 years


Esoteric Software


« Reply #1 - Posted 2009-09-01 22:48:51 »

How is Janino better than using a different JVM language? Java syntax can be had using BeanShell (though I don't personally like BeanShell). Java-the-language is not very expressive, so I think you may be limiting yourself unnecessarily.

You should be able to use the Java Security mechanism. Methods that you don't want users to call should check a permission that users don't have. There are also ways to control permissions to file access, network access, etc.

Pnuts has some additional mechanisms:
http://pnuts.org/doc/secure.html
http://pnuts.org/doc/limitedclass.html
http://pnuts.org/doc/configuration.html
More on Pnuts:
http://pnuts.org/snapshot/latest/
http://pnuts.org/articles/pnutsHighlights.html

Offline Riven
« League of Dukes »

JGO Overlord


Medals: 781
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #2 - Posted 2009-09-01 23:27:45 »

My question is there a simple way to restrict a modders script when using Janino or other embedded java compiler as a game scripting solution?

A crappy solution is to not directly convert the sourcecode into classes, but save the intermediate result to either a file or a byte[]. Then you can peek around the constantpool (you must write a parser...) and terminate any naughty attempt to take over your machine. That said, you can't so much about "for(;Wink;", only Thread.stop() will get you out of that.

So much for the problems of this 'ultimate runtime compiler' -- scripting languages are not that bad after all.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline oNyx

JGO Coder


Medals: 2


pixels! :x


« Reply #3 - Posted 2009-09-02 19:02:57 »

How is Janino better than using a different JVM language?[...]

It's a very fast on-the-fly compiler. This means you get full speed. It also means you can script full classes and it also means that you can replace them with compiled versions as soon as you're done with em.

So, you can for example prototype rather complex things (even integral parts of your framework) pretty quickly. E.g. model or image loaders, collision detection, physics, etc. The console of my scripting framework was also done like that for example.

弾幕 ☆ @mahonnaiseblog
Offline Nate

JGO Kernel


Medals: 145
Projects: 4
Exp: 14 years


Esoteric Software


« Reply #4 - Posted 2009-09-02 21:36:26 »

It's a very fast on-the-fly compiler. This means you get full speed.

Other JVM langauges (eg, Pnuts Grin) can compile to bytecodes on the fly. Of course, speed is going to vary depending on what the language is doing. I think you are saying that Janino compiled classes are exactly as fast as using bytecodes from javac?

Quote
It also means you can script full classes and it also means that you can replace them with compiled versions as soon as you're done with em.

I write Java classes using a standard Java IDE (Eclipse). If I change the Java source for a class and save the file, the IDE recompiles the class and (assuming my application is running) it uses Java HotSwap to patch the bytecodes for the class in the running application. I can't imagine Janino's workflow can be smoother than this?

IMO, the real benefit to use a JVM language other than Java-the-language is for added expressiveness. There is also the benefit of being able to load code at runtime, when an IDE is not present.

So far, the only argument I could accept for using Janino would be:

1) If you needed to compile Java source at runtime, with no IDE. But isn't there a JSR for this that made it into the JDK? Does Janino provide extra funcitonality?

2) If you absolutely needed the same speed as javac, and are willing to sacrifice expressiveness to get it. Then I wonder what the speed differences actually are in real world usage.

Offline zingbat

Senior Member




Java games rock!


« Reply #5 - Posted 2009-09-02 22:06:52 »

Thanks for the input. I will check pnuts. It looks a solid scripting language.

"1) If you needed to compile Java source at runtime, with no IDE. But isn't there a JSR for this that made it into the JDK? Does Janino provide extra funcitonality?"

I have two requirements for a game scripting language 1) scripts can be compiled to bytecode and 2) it can be compiled dynamically. I know that java 1.6 has some support for dynamic compilation but i have a mac with with java 1.5 and i'm not sure if it works. Anyway it looks like Pnuts can do the job. 
Offline oNyx

JGO Coder


Medals: 2


pixels! :x


« Reply #6 - Posted 2009-09-02 23:22:14 »

>I think you are saying that Janino compiled classes are exactly as fast as using bytecodes from javac?

Yes. I never noticed any speed difference. (Complete classes.)

>I can't imagine Janino's workflow can be smoother than this?

Well, it means you easily get a workflow like that (with instant turn-overs) on very dated or very weak machines.

Janino can also compile/execute statements or method bodies, which might be handy here and there.

弾幕 ☆ @mahonnaiseblog
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

atombrot (26 views)
2014-08-19 09:29:53

Tekkerue (24 views)
2014-08-16 06:45:27

Tekkerue (23 views)
2014-08-16 06:22:17

Tekkerue (14 views)
2014-08-16 06:20:21

Tekkerue (22 views)
2014-08-16 06:12:11

Rayexar (60 views)
2014-08-11 02:49:23

BurntPizza (38 views)
2014-08-09 21:09:32

BurntPizza (30 views)
2014-08-08 02:01:56

Norakomi (37 views)
2014-08-06 19:49:38

BurntPizza (67 views)
2014-08-03 02:57:17
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!