Skip to content

Instantly share code, notes, and snippets.

@jneen
Created January 29, 2011 16:34
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jneen/801972 to your computer and use it in GitHub Desktop.
Save jneen/801972 to your computer and use it in GitHub Desktop.
a module system for Io
# 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"
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