Created
January 29, 2011 16:34
-
-
Save jneen/801972 to your computer and use it in GitHub Desktop.
a module system for Io
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Assuming this directory structure: | |
# | |
# MyModule/ | |
# init.io # => Object clone do( foo := "bar" ) | |
# slot1.io # => "LOL" | |
# slot2.io # => method("running slot2" println; self) | |
# slot3/ | |
# subslot1.io # => "this is subslot1" | |
import("/path/to/MyModule") | |
MyModule foo # => "bar" | |
MyModule slot1 # => "LOL" | |
MyModule slot2 # "running slot2" => MyModule | |
MyModule slot3 subslot1 # => "this is subslot 1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NotFound := Error clone | |
Object import := method(path, | |
dir := Directory with(path) | |
obj := if(File exists(path .. ".io"), | |
doFile(path .. ".io") | |
, | |
if(Directory exists(path), | |
if(File exists(path .. "/init.io"), | |
doFile(path .. "/init.io") | |
, | |
Object clone | |
) | |
, | |
NotFound raise("couldn't find <" .. path .. ">") | |
) | |
) | |
call sender setSlot(dir name, obj) | |
dir filesWithExtension(".io") foreach(file, | |
obj setSlot(file baseName, | |
obj doFile(file path) | |
) | |
) | |
dir directories foreach(directory, | |
obj setSlot(directory name, | |
obj import(directory path) | |
) | |
) | |
obj | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment