set up Ruby load path for runtime modules; add runtime.rb
This commit is contained in:
parent
71578566fe
commit
5c9cc2223e
71
runtime/lib/runtime.rb
Normal file
71
runtime/lib/runtime.rb
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
module Runtime
|
||||||
|
class << self
|
||||||
|
|
||||||
|
# Return the base paths to the runtime directories.
|
||||||
|
#
|
||||||
|
# @return [Array] Current runtime paths.
|
||||||
|
def paths
|
||||||
|
@paths ||= default_paths
|
||||||
|
end
|
||||||
|
|
||||||
|
# Find a runtime file.
|
||||||
|
#
|
||||||
|
# @param type [Symbol]
|
||||||
|
# Type of runtime file to find. Options:
|
||||||
|
# - :shader
|
||||||
|
# - :font
|
||||||
|
# @param name [String]
|
||||||
|
# Name of the runtime file to locate.
|
||||||
|
#
|
||||||
|
# @return [String, nil]
|
||||||
|
# Path to the runtime file, or +nil+ if not found.
|
||||||
|
def find(type, name)
|
||||||
|
path = nil
|
||||||
|
paths.find do |runtime_path|
|
||||||
|
path = find_in(type, name, runtime_path)
|
||||||
|
end
|
||||||
|
path
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
# Return the default runtime paths.
|
||||||
|
#
|
||||||
|
# @return [Array] Default runtime paths.
|
||||||
|
def default_paths
|
||||||
|
[
|
||||||
|
File.expand_path("~/.jes"),
|
||||||
|
File.expand_path("../../runtime", $0),
|
||||||
|
]
|
||||||
|
end
|
||||||
|
|
||||||
|
# Find a runtime file within a single runtime path.
|
||||||
|
#
|
||||||
|
# @param type [Symbol]
|
||||||
|
# Type of runtime file to find. Options:
|
||||||
|
# - :shader
|
||||||
|
# - :font
|
||||||
|
# @param name [String]
|
||||||
|
# Name of the runtime file to locate.
|
||||||
|
# @param runtime_path [String]
|
||||||
|
# The runtime path to look in.
|
||||||
|
#
|
||||||
|
# @return [String, nil]
|
||||||
|
# Path to the runtime file, or +nil+ if not found.
|
||||||
|
def find_in(type, name, runtime_path)
|
||||||
|
path =
|
||||||
|
case type
|
||||||
|
when :shader
|
||||||
|
File.join(runtime_path, "shaders", name)
|
||||||
|
else
|
||||||
|
raise "Unknown runtime type: #{type.inspect}"
|
||||||
|
end
|
||||||
|
if File.exists?(path)
|
||||||
|
path
|
||||||
|
else
|
||||||
|
nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
@ -1,6 +1,14 @@
|
|||||||
def main
|
def init_loadpath
|
||||||
puts "hi from main.rb"
|
$LOAD_PATH.unshift(File.expand_path("../../runtime/lib", $0))
|
||||||
p ARGV
|
|
||||||
end
|
end
|
||||||
|
|
||||||
main
|
def load_lib_files
|
||||||
|
require "runtime"
|
||||||
|
end
|
||||||
|
|
||||||
|
def main(argv)
|
||||||
|
init_loadpath
|
||||||
|
load_lib_files
|
||||||
|
end
|
||||||
|
|
||||||
|
main(ARGV)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user