-=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- (c) WidthPadding Industries 1987 0|514|0 -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=-
SoCoder -> Showcase Home -> Functions Libraries


 
JL235
Created : 31 January 2009
Edited : 01 February 2009
System : Browser Based
Language : Ruby

Instance DSL

a small domain specific langauge for setting up new instances of instances of a class

Instance is a small scripting language for Java. It allows the user to describing how to setup new instances of a class and then create them at run-time.

For example if you are making an RTS you might create a 'Unit' class that stores the code relating to the Units attack damange, movement speed, defense points, hit points, the image they should use and so on. You then create sub-classes of Unit (i.e. 'Knight', 'Archer', 'Infantry', etc) to state what these values are.

Instead you can describe their fields using Instance and apply these descriptions to new instances of Unit. With instance you are not hard coding units stats and the description files can be reloaded whilst the game is running.

The library consists of a single class, the InstanceFactory, that provides simple methods for loading scripts and creating new instances with them.

Links

Technical

  • Compiled for Java 5, but only tested on Java 6.
  • Both 'instance.jar' and 'java_cup.jar' are required for this to be used.
  • java_cup.jar is a build of the Cup grammar for Java, more info at the home page.

Syntax

The Syntax is based on Java. Only primitive types and strings can currently be set.

Example Instance script:
  • 'knight', 'archer' and 'infantry' are the names of the setup descriptions. The following block of code describes how to setup up a new isntance.
  • Only field declarations and method calls can be made in the block of code.
  • The fields stated must exist in the class used when creating a new instance.
  • All lines must end with a semi-colon or an end of line character.
  • Types supported are: integers, floats, doubles, longs, booleans, null and strings.
  • The class used for making new instances must have a no argument constructor.

Example usage in Java:

 

Comments