Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ jruby4max.jar
out
*.iml
.idea
.project
.classpath
15 changes: 7 additions & 8 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ require 'rake/clean'
require 'tempfile'
require 'rbconfig'

PROJECT_VERSION = '1.0.2'
PROJECT_VERSION = '1.0.3'
BUILD_DATE = Time.now.utc.strftime '%B %d, %Y (%H:%M GMT)'
MANIFEST =
MANIFEST =
"Library: JRuby for Max
Version: #{PROJECT_VERSION}
Built-Date: #{BUILD_DATE}
Expand All @@ -31,7 +31,7 @@ TESTS = FileList['test/**/*.java']
CLASSPATH = FileList["#{LIB}/**/*.jar"].exclude(/^#{JAR}$/)
TESTS_CLASSPATH = CLASSPATH.clone.add(BUILD)

WINDOWS = Config::CONFIG['host_os'] =~ /mswin/
WINDOWS = RbConfig::CONFIG['host_os'] =~ /mswin/
CLASSPATH_SEPARATOR = if WINDOWS then ';' else ':' end

##############################################################################
Expand Down Expand Up @@ -60,14 +60,14 @@ task :package => [:jar] do
puts "Preparing distribution"
package_lib = File.join PACKAGE,'lib'
mkdir_p package_lib

# Collect the files
FileList['*.txt', '*.example'].each do |filename|
cp filename, PACKAGE
end
FileList["#{LIB}/jruby.jar", JAR_FILE].each do |filename|
cp filename, package_lib
end
end
cp_r PATCHES, PACKAGE
cp_r LICENSE, PACKAGE
end
Expand Down Expand Up @@ -125,7 +125,7 @@ end

def javac classpath, src_files, dst_folder
mkdir_p dst_folder
`javac -classpath #{classpath.join CLASSPATH_SEPARATOR} -d #{dst_folder} -g -source 1.5 -target 1.5 #{src_files}`
`javac -classpath #{classpath.join CLASSPATH_SEPARATOR} -d #{dst_folder} -g #{src_files} -Xlint:deprecation`
end

def jar filename, manifest, dst_folder
Expand All @@ -144,8 +144,7 @@ class FileList
File.open(filename, 'w') do |io|
io.write contents
end
end
end
end
end
end

31 changes: 31 additions & 0 deletions jruby_for_max.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#############################
# Options for JRuby for Max #
#############################

# To use:
# - Rename this file to jruby_for_max.properties
# - Put it on the Max file search path
# - Restart Max (and restart again each time you change this file)


ruby.loadpaths =
# A semicolon-separated list of absolute paths to append to the default $LOAD_PATH.
# You can use this to add gems or other projects installed elsewhere.
# Default value is nothing.

jruby.home = /Users/javier/.rvm/rubies/jruby-9.2.7.0
# If you want to install a lot of gems: instead of adding a loadpath for each one,
# you can install them into a separate jruby installation and set jruby.home to
# run against that jruby instead of the built-in one.
# This variable is not set by default.

gem.home = /Users/javier/.rvm/gems/jruby-9.2.7.0@global
# GEM locations where to install new gems

gem.path = /Users/javier/.rvm/gems/jruby-9.2.7.0@global
# GEM locations where to find them to use them

ruby.initializers = jruby_initialize.rb
# A semicolon-separated list of files.
# These files will be run in the order listed whenever a new jruby context is initialized.
# Default value is jruby_initialize.rb
8 changes: 6 additions & 2 deletions jruby_for_max.properties.example
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,18 @@ ruby.loadpaths =


# jruby.home = /Users/adam/lib/jruby-1.5.5
# If you want to install a lot of gems: instead of adding a loadpath for each one,
# If you want to install a lot of gems: instead of adding a loadpath for each one,
# you can install them into a separate jruby installation and set jruby.home to
# run against that jruby instead of the built-in one.
# This variable is not set by default.

# gem.home = /Users/javier/.rvm/gems/jruby-9.2.7.0@global
# GEM locations where to install new gems

# gem.path = /Users/javier/.rvm/gems/jruby-9.2.7.0@global
# GEM locations where to find them to use them

ruby.initializers = jruby_initialize.rb
# A semicolon-separated list of files.
# A semicolon-separated list of files.
# These files will be run in the order listed whenever a new jruby context is initialized.
# Default value is jruby_initialize.rb
17 changes: 8 additions & 9 deletions jruby_for_max/lib/jruby_initialize.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def bang

# Sets the tooltips for the inlets of this [mxj jruby] object
def inlet_assist(*params)
$max_object.setInletAssist params.to_java(:string)
$max_object.setInletAssist params.to_java(:string)
end

# Sets the tooltips for the outlets of this [mxj jruby] object
Expand All @@ -112,7 +112,7 @@ def max_object(namespace=nil)
context = $max_object.context
id = names[0]
end
$max_object_map[context][id]
$max_object_map[context][id]
end


Expand All @@ -121,25 +121,25 @@ def max_object(namespace=nil)

# Print the arguments to the Max console separated by newlines
def puts(*params)
yield_atoms(*params) {|atom| java.lang.System.out.println(atom)}
yield_atoms(*params) {|atom| $max_object.getSystemOut.println(atom) }
nil
end
end

# Prints the arguments to the Max console
def print(*params)
yield_atoms(*params) {|atom| java.lang.System.out.print(atom)}
yield_atoms(*params) {|atom| $max_object.getSystemOut.print(atom) }
nil
end
end

# Prints an error message to the Max console
def error(*params)
yield_atoms(*params) {|atom| java.lang.System.err.println(atom)}
yield_atoms(*params) {|atom| $max_object.getSystemErr.println(atom) }
nil
end

# Flush the Max console, use after print()
def flush
java.lang.System.out.println
$max_object.getSystemOut.println
nil
end

Expand Down Expand Up @@ -171,4 +171,3 @@ def yield_atoms( *params, &block )
end
end
end

Binary file modified lib/jruby.jar
Binary file not shown.
Binary file modified lib/max.jar
Binary file not shown.
46 changes: 13 additions & 33 deletions src/jruby4max/maxsupport/JRubyMaxObject.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package jruby4max.maxsupport;

import java.io.PrintStream;

/*
Copyright (c) 2008, Adam Murray (adam@compusition.com). All rights reserved.

Expand Down Expand Up @@ -31,14 +33,11 @@ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
import com.cycling74.max.Executable;
import com.cycling74.max.MaxObject;
import com.cycling74.max.MaxQelem;

import jruby4max.rubysupport.IdInUseException;
import jruby4max.rubysupport.MaxRubyAdapter;
import jruby4max.rubysupport.RubyProperties;
import jruby4max.util.Logger;
import jruby4max.util.Utils;
import org.jruby.CompatVersion;

import java.io.PrintStream;

/**
* Superclass for objects that support Ruby scripting.
Expand All @@ -51,9 +50,6 @@ public abstract class JRubyMaxObject extends MaxObject implements Logger {
protected String id = defaultId();
private boolean autoinit = false;

protected Atom[] rubyVersionValue = Atom.newAtom( new String[]{ RubyProperties.DEFAULT_RUBY_VERSION_STRING } );
protected CompatVersion rubyVersion = RubyProperties.DEFAULT_RUBY_VERSION;

protected MaxRubyAdapter ruby;

protected JRubyMaxObject self = this;
Expand All @@ -77,7 +73,6 @@ public JRubyMaxObject() {
declareAttribute( "context", "getcontext", "context" );
declareAttribute( "id", "getid", "id" );
declareAttribute( "autoinit" );
declareAttribute( "ruby_version", "getruby_version", "ruby_version" );
}

private final MaxQelem getInitializerQelem() {
Expand All @@ -101,12 +96,12 @@ protected class DefaultRubyInitializer implements Executable {
public void execute() {
initialized = true;
try {
ruby = new MaxRubyAdapter( self, context, id, rubyVersion );
ruby = new MaxRubyAdapter( self, context, id );
} catch(IdInUseException e) {
String availableId = e.getMessage();
error( "id " + id + " not available. Using: " + availableId );
id = availableId;
ruby = new MaxRubyAdapter( self, context, id, rubyVersion );
ruby = new MaxRubyAdapter( self, context, id );
}
if( autoinit ) {
ruby.init();
Expand Down Expand Up @@ -171,6 +166,14 @@ public void info( String message, boolean force ) {
public void err( String message ) {
error( this.getClass().getName() + ": " + message );
}

public PrintStream getSystemOut() {
return System.out;
}

public PrintStream getSystemErr() {
return System.err;
}

public String toString() {
return getClass().getName() + "#<" + Integer.toHexString( hashCode() ) + ">";
Expand Down Expand Up @@ -221,27 +224,4 @@ public void id( Atom[] params ) {
private String defaultId() {
return Integer.toHexString( hashCode() );
}

public Atom[] getruby_version() {
return rubyVersionValue;
}

// Using Atom[] is annoying but it avoids an annoying warning in the max menu "coerced float to String" when doing @ruby_version 1.9
public void ruby_version(Atom[] rubyVersionValue) {
if (initialized) {
err("ruby_version cannot be changed. Use @ruby_version when creating the object.");
return;
}
if (rubyVersionValue == null || rubyVersionValue.length < 1) return;

String rubyVersionString = rubyVersionValue[0].toString();
// @ruby_version 1.9 comes through as "1.900000" so we have to chop off the trailing zeros
rubyVersionString = rubyVersionString.replaceFirst("(.*?)0+", "$1");

CompatVersion rubyVersion = RubyProperties.getRubyVersion(rubyVersionString);
if (rubyVersion != null) {
this.rubyVersion = rubyVersion;
this.rubyVersionValue = Atom.newAtom(new String[]{rubyVersionString});
} else err("Invalid ruby_version '" + rubyVersionString + "'. Only 1_8 and 1_9 supported.");
}
}
2 changes: 1 addition & 1 deletion src/jruby4max/rubysupport/IScriptEvaluator.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,6 @@ public interface IScriptEvaluator {
void setScriptFile( File scriptFile );

Object eval( CharSequence rubyCode );

void exit();
}
26 changes: 12 additions & 14 deletions src/jruby4max/rubysupport/MaxRubyAdapter.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
package jruby4max.rubysupport;

import java.io.File;
import java.io.IOException;
import java.math.BigInteger;

import org.jruby.RubyArray;
import org.jruby.RubyHash;
import org.jruby.RubySymbol;

/*
Copyright (c) 2008, Adam Murray (adam@compusition.com). All rights reserved.

Expand Down Expand Up @@ -29,19 +37,12 @@ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING

import com.cycling74.max.Atom;
import com.cycling74.max.MaxObject;

import jruby4max.maxsupport.Atomizer;
import jruby4max.util.GlobalVariableStore;
import jruby4max.util.LineBuilder;
import jruby4max.util.Logger;
import jruby4max.util.Utils;
import org.jruby.CompatVersion;
import org.jruby.RubyArray;
import org.jruby.RubyHash;
import org.jruby.RubySymbol;

import java.io.File;
import java.io.IOException;
import java.math.BigInteger;

/**
* The bridge between Max and Ruby.
Expand All @@ -66,20 +67,17 @@ public class MaxRubyAdapter {

private String id;

private CompatVersion rubyVersion;

public MaxRubyAdapter( MaxObject maxObject, String context, String id, CompatVersion rubyVersion ) {
public MaxRubyAdapter( MaxObject maxObject, String context, String id) {
this.maxObject = maxObject;
if( maxObject instanceof Logger ) {
this.logger = (Logger)maxObject;
}
this.maxContext = context;
this.id = id;
this.rubyVersion = rubyVersion;
}

private void getEvaluator() {
ruby = ScriptEvaluatorManager.getRubyEvaluator( maxContext, id, maxObject, rubyVersion );
ruby = ScriptEvaluatorManager.getRubyEvaluator( maxContext, id, maxObject );
ruby.declareGlobal( "max_ruby_adapter", this );
ruby.declareGlobal( "global_variable_store", GlobalVariableStore.getInstance() );
}
Expand Down Expand Up @@ -117,7 +115,7 @@ public void setId( String id ) {
this.id = id;
}
}

public void notifyDeleted() {
ScriptEvaluatorManager.removeRubyEvaluator( maxObject );
}
Expand Down
Loading