1 Addon
:= Object clone do(
5 platform
:= System platform asLowercase
8 list("cygwin", "mingw", "windows") detect(dllPlatform
, platform
containsSeq(dllPlatform
)) ifNonNil(return("dll"))
9 if(platform
== "darwin", return "dylib")
13 dllName
:= method("libIo" .. name
.. "." .. dllSuffix
)
15 addonPath
:= method(Path
with(rootPath
, name
))
17 dllPath
:= method(Path
with(addonPath
, "_build/dll", dllName
))
18 sourcePath
:= method(Path
with(addonPath
, "source"))
21 d
:= Directory with(addonPath
) folderNamed("io")
22 if(d
== nil
, return list())
23 files
:= d files
select(path
endsWithSeq(".io"))
24 files
map(name
) sort
map(name
, d
fileNamed(name
))
27 dependencies
:= method(
28 File with(Path
with(addonPath
, "depends")) contents
split(" ")
31 loadDependencies
:= method(
32 //writeln(name
, " depends on ", dependencies
)
33 dependencies
foreach(d
,
34 if(Lobby getSlot(d
) == nil
,
35 //writeln("loading dependency ", d
)
36 AddonLoader
loadAddonNamed(d
)
42 //writeln("Addon ", name
, " loading from ", addonPath
)
44 context
:= Object clone
45 Protos Addons
setSlot(name
, context
)
46 Protos appendProto(context
)
48 if(File with(dllPath
) exists
,
49 DynLib clone setPath(dllPath
) open
call("Io" .. name
.. "Init", context
)
51 // check
for C files
, if found
then addon didn
't compile
52 if(Directory with(sourcePath) size > 1,
53 Exception raise("Failed to load Addon " .. name .. " - it appears that the addon exists but was not compiled. You might try running 'make
" .. name .. "' in the Io source folder.")
56 //ioFiles foreach(f, writeln("loading ", f path))
57 ioFiles foreach(file, context doFile(file path))
61 exists := method(Directory with(addonPath) exists)
63 addonProtos := method(
64 f := File with(Path with(addonPath, "protos"))
65 if(f exists, f contents split, list())
69 AddonLoader := Object clone do(
70 searchPaths := list("io/addons", System installPrefix .. "/lib/io/addons")
71 appendSearchPath := method(p, searchPaths appendIfAbsent(p); self)
74 searchFolders := searchPaths map(path, Directory with(path)) select(exists)
75 addonFolders := searchFolders map(folders) flatten select(isAccessible) select(fileNames contains("build.io"))
76 addons := addonFolders map(f, Addon clone setRootPath(f path pathComponent) setName(f path lastPathComponent))
80 addonFor := method(name,
81 r := addons detect(name == name)
83 addons detect(addonProtos contains(name))
86 hasAddonNamed := method(name, addonFor(name) != nil)
88 loadAddonNamed := method(name,
89 //writeln("loadAddonNamed(", name, ")")
90 addon := addonFor(name)
91 if(addon, addon load, nil)