The Open Type System

The cornerstone of Gosu, the thing that makes it different than other languages, is the Open Type System. This is the API that allows Gosu to use various kinds of resources in a statically typed, easily toolbable manner. The beauty is that all you need to do is implement some java interfaces and, blam, you've got your custom type system.

As a concrete example, the OTS is what allows Gosu to work with WSDL types directly, without code generation.

There are two sides to the OTS: clients of the type system and tool/framework implementors who want to expose their framework in a statically typed way.

gw.lang.reflect.TypeSystem

As a client, this is a good jumping-off spot to get at types:

      
  var type = TypeSystem.getByFullName( aTypeName )
    
It has many useful methods for exploring the type system (and plenty of hacks too).

gw.lang.reflect.IType

This is the core type abstraction in Gosu, the equivalent of java.lang.reflect.Class.

gw.lang.reflect.ITypeInfo

This holds all the common information about types: constructors, methods, properties, etc. You can get the type info for a type like so:

      
  var ti = someType.TypeInfo
    
To get all the methods on a type, you would do this:
      
  var ti = String.Type.TypeInfo.Methods // String.Type is how you refer to the String type statically, like String.class in Java
    

gw.lang.reflect.IMethodInfo

This represents an invokable method. Let's use feature literals to get to one of these:

      
    var methodInfo = Object#toString().MethodInfo // returns the method info for Object#toString()
    print( methodInfo.ReturnType )                // prints java.lang.String
    

gw.lang.reflect.IPropertyInfo

Just like an IMethodInfo but for properties.

gw.lang.reflect.IConstructorInfo

And constructors.

gw.lang.reflect.ITypeLoader

OK, if you are client then this isn't very interesting, but if you are an implementor, this is crucial. This is what you implement to get into your type system. In particular, the gw.lang.reflect.ITypeLoader#getIntrinsicType method, which takes a string type name and returns an IType, is where the magic begins.

If you are interested in creating a custom type system, you should take a look at the examples that come with gosu, or maybe take a look at one of my pet projects here:

    http://protocols.github.com/