1 Importer := Object clone do(
2 //metadoc
Importer description A simple search path based auto
-importer
.
4 //doc
Importer paths
List of paths the
proto importer will check while searching
for protos to load
.
5 paths
:= method(FileImporter folders
)
7 //doc
Importer addSearchPath(path
) Add a search path to the auto importer
. Relative paths are made absolute before adding
.
8 addSearchPath
:= method(p
, paths
appendIfAbsent(Path
absolute(p
) asSymbol
))
10 //doc
Importer removeSearchPath(path
) Removes a search path from the auto importer
. Relative paths should be removed from the same working directory as they were added
.
11 removeSearchPath
:= method(p
, paths
remove(Path
absolute(p
) asSymbol
))
13 //doc
Importer FileImporter An
Importer for local source files
.
14 FileImporter
:= Object clone do(
19 import
:= method(protoName
,
20 if(?launchPath
, folders
appendIfAbsent(launchPath
))
22 folders
foreach(folder
,
23 path
:= Path
with(folder
, protoName
.. ".io") asSymbol
24 if(File with(path
) exists
,
33 //doc
Importer AddonImporter An
Importer for addon modules
.
34 AddonImporter
:= Object clone do(
37 import
:= method(protoName
,
38 if(hasAddon
:= AddonLoader
hasAddonNamed(protoName
),
39 AddonLoader
loadAddonNamed(protoName
)
45 //doc
Importer importers
List of
Importer objects
.
46 importers
:= list(FileImporter
, AddonImporter
)
48 //doc
Importer import(originalCallMessage
) Imports an object
or addon
for the given
Message.
49 import
:= method(originalCall
,
50 protoName
:= originalCall
message name
52 if(protoName
at(0) isUppercase
and(importer
:= importers
detect(import(protoName
))),
53 if(Lobby hasSlot(protoName
) not
,
54 Exception raiseFrom(originalCall
, "Importer slot '" .. protoName
.. "' missing after " .. importer importsFrom
.. " load")
56 Lobby getSlot(protoName
)
58 targetType
:= originalCall target
type
59 Exception raiseFrom(originalCall
, targetType
.. " does not respond to '" .. protoName
.. "'")
63 //doc
Importer autoImportingForward A
forward method implementation placed in the
Lobby when Importing is turned on
.
64 autoImportingForward
:= method(
68 //doc
Importer turnOn Turns on the
Importer. Returns
self.
70 Lobby forward := self getSlot("autoImportingForward")
74 //doc
Importer turnOff Turns off the
Importer. Returns
self.
76 Lobby removeSlot("forward")
80 // Auto
Importer is on by default