         null
 
   # Converts an object to a function.
-  # 
-  # If the passed object is a string, it will be converted using 
+  #
+  # If the passed object is a string, it will be converted using
   # ST.stringToProc.
   toProc: (object) ->
     if object.call

      return namespace[className] if namespace[className]
      namespace = namespace._namespace
    null
  
  # Creates a new class in this namespace
  makeClass: (className, superClass, definition) ->
    # If superclass parameter omitted, use 'Object' as superclass
    unless definition
      definition = superClass
      superClass = 'Object'
    
    newClass = ->
      @_class = newClass
      this
    
    newClass._classMethods = []
    
    # Inherit superclass
    superClass = @getClass superClass if superClass && (typeof superClass == 'string')
    if superClass
      newClass.prototype = new superClass
      newClass._superclass = superClass
      
      # Inherit class methods
      for methodName in superClass._classMethods
        newClass[methodName] = superClass[methodName]
        newClass._classMethods.push methodName
    
    # Set _name variable to name of class
    newClass._name = className
      
    # Add class to namespace
    this[className] = newClass
    newClass._namespace = this
    
    # Run class definition
    definition.call newClass
  
  class: (className, superClass, definition) ->
    if arguments.length > 1
      @makeClass className, superClass, definition
    else
      @getClass className
  
  module: (name, definition) ->
    @[name] ||= {
      _namespace: this

    ST._history.push command if command.reverse
    ST._command = null
    command

  command: (name, forward, reverse=null) ->
    command = @beginCommand name
    result = forward()
    command.reverse = reverse
    @endCommand()
    result

  undo: ->
    if command = ST._history.pop()
      console.log "Undo command: #{command.name}" if _logging
      command.reverse()

  once: (key, fn) ->
    if ST._command
      ST._command.oneTimeTasks[key] ||= fn
