exports.nameFromFilename MIXCO_SCRIPT_FILENAME
else
assert false, "Invalid script"
scriptType =
if issubclass scriptTypeOrDefinition, exports.Script
scriptTypeOrDefinition
else
exports.create scriptTypeOrDefinition
instance = new scriptType
instance.__registeredName = name
targetModule.exports[name] = instance
if targetModule == require.main
instance.main()
exports.create = (scriptDefinition) ->
assert scriptDefinition.constructor?,
"Script definition must have a constructor"
{constructor, init, shutdown} =
scriptDefinition
class NewScript extends exports.Script
constructor: ->
super
try
Control::setRegistry bind @add, @
constructor.apply @, arguments
finally
Control::setRegistry null
this
init: ->
@preinit?.apply @, arguments
super
init?.apply @, arguments
shutdown: ->
shutdown?.apply @, arguments
super
@postshutdown?.apply @, arguments
special = ['name', 'constructor', 'init', 'shutdown']
for k, v of scriptDefinition
if k not in special
NewScript::[k] = v
NewScript