Skip to content

Commit

Permalink
crude library loader
Browse files Browse the repository at this point in the history
  • Loading branch information
monkstone committed Feb 20, 2015
1 parent 64585c6 commit fb3fe74
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 3 deletions.
1 change: 1 addition & 0 deletions lib/jruby_art.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
Java::ProcessingFastmath::DeglutLibrary.new.load(JRuby.runtime, false)
Java::ProcessingVecmathVec2::Vec2Library.new.load(JRuby.runtime, false)
Java::ProcessingVecmathVec3::Vec3Library.new.load(JRuby.runtime, false)

AppRender = Java::ProcessingVecmath::AppRender
ShapeRender = Java::ProcessingVecmath::ShapeRender
require 'jruby_art/app'
Expand Down
17 changes: 16 additions & 1 deletion lib/jruby_art/app.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require_relative 'helper_methods'
require_relative 'library_loader'

# The Processing module is a wrapper for JRubyArt
# Author:: Martin Prout (extends / re-implements ruby-processing)
Expand Down Expand Up @@ -76,8 +77,21 @@ def sketch_title
# This class is for default (Java2D) sketches only
class App < PApplet
include Common, HelperMethods
Java::ProcessingVecmathArcball::ArcballLibrary.new.load(JRuby.runtime, false)
attr_reader :title, :args, :opts

# Handy getters and setters on the class go here:
class << self
attr_accessor :sketch_class, :library_loader
end

def sketch_class
self.class.sketch_class
end

def self.load_library(args)
App.library_loader ||= LibraryLoader.new
App.library_loader.load_libraries(args)
end

# App should be instantiated with an optional list of opts
# and array of args.
Expand Down Expand Up @@ -118,6 +132,7 @@ class AppGL < PApplet
include Processing, Common
include_package 'processing.opengl' # imports the processing.opengl package.
include HelperMethods
Java::ProcessingVecmathArcball::ArcballLibrary.new.load(JRuby.runtime, false)
attr_reader :title, :args, :opts

# App should be instantiated with an optional list of opts
Expand Down
31 changes: 29 additions & 2 deletions lib/jruby_art/library_loader.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,32 @@

class LibraryLoader
attr_reader :libraries_path

def initialize
p "init LibraryLoader"
@libraries_path = "#{ENV['HOME']}/.jruby_art/libraries"
@loaded_libraries = Hash.new(false)
end

# Load a list of Ruby or Java libraries (in that order)
# Usage: load_libraries :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 load_libraries(*args)
installed_java_lib(*args)
end
end
alias_method :load_library, :load_libraries



def installed_java_lib(*args)
libraries = "#{ENV['HOME']}/.jruby_art/libraries/"
args.each do |arg|
lib = File.join(libraries, arg.to_s)
jar_files = File.join(lib, '**', '*.jar')
Dir.glob(jar_files).each do |jar|
require jar
end
end
end
end

0 comments on commit fb3fe74

Please sign in to comment.