Skip to content

Commit

Permalink
Libraries can now be loaded without caring about their type using `lo…
Browse files Browse the repository at this point in the history
…ad_library :opengl, :boids`.

Former-commit-id: d36f06b
Former-commit-id: 392c11153f1e7cfbf7dcfc6a2784a9e7450d72d1
  • Loading branch information
grossbart committed Jan 16, 2009
1 parent 997b5fc commit 2637c34
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion lib/ruby-processing/app.rb
Expand Up @@ -80,6 +80,20 @@ def self.library_loaded?(folder)
end
def library_loaded?(folder); self.class.library_loaded?(folder); end


# Load a Ruby or Java library (in that order)
# Usage: load_library :opengl, :boids
#
# If a library is put into a 'library' folder next to the sketch it will
# be used instead of the library that ships with Ruby-Processing.
def self.load_library(*args)
args.each do |dir|
unless load_ruby_library(dir) or load_java_library(dir)
puts "Could not find library '#{dir}'"
exit
end
end
end

# For pure ruby libraries.
# The library should have an initialization ruby file
Expand All @@ -94,6 +108,7 @@ def self.load_ruby_library(dir)
local_path = "#{Dir.pwd}/library/#{dir}"
gem_path = "#{RP5_ROOT}/library/#{dir}"
path = File.exists?(local_path) ? local_path : gem_path
return false unless (File.exists?("#{path}/#{dir}.rb"))
return @@loaded_libraries[dir] = (require "#{path}/#{dir}")
end

Expand All @@ -115,7 +130,7 @@ def self.load_java_library(dir)
gem_path = "#{RP5_ROOT}/library/#{dir}"
path = File.exists?(local_path) ? local_path : gem_path
jars = Dir.glob("#{path}/**/*.jar")
raise LoadError if jars.length == 0
return false if jars.empty?
jars.each {|jar| require jar }
# Here goes...
library_path = java.lang.System.getProperty("java.library.path")
Expand Down

0 comments on commit 2637c34

Please sign in to comment.