Skip to content

Commit

Permalink
@context and @id can now handle arbitrary values without coercion war…
Browse files Browse the repository at this point in the history
…nings
  • Loading branch information
adamjmurray committed Aug 27, 2010
1 parent b820872 commit b38e024
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/ajm/maxsupport/AbstractMaxRubyObject.java
Expand Up @@ -32,6 +32,7 @@ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
import com.cycling74.max.*;

import ajm.rubysupport.*;
import ajm.util.Utils;

/**
* Superclass for objects that support Ruby scripting.
Expand Down Expand Up @@ -87,30 +88,32 @@ public void execute() {
}
}

public String getcontext() {
return context;
public Atom[] getcontext() {
return Atom.newAtom(new String[]{context});
}

public String context() {
return context;
}

public void context(String context) {
public void context(Atom[] params) {
String context = Utils.toString(params);
this.context = context;
if (ruby != null) {
ruby.setContext(context);
} // else we're still initializing and the initalizer should handle this
}

public String getid() {
return id;
public Atom[] getid() {
return Atom.newAtom(new String[]{id});
}

public String id() {
return id;
}

public void id(String id) {
public void id(Atom[] params) {
String id = Utils.toString(params);
if (id == null || "".equals(id)) {
id = defaultId();
}
Expand Down
16 changes: 16 additions & 0 deletions src/ajm/util/Utils.java
Expand Up @@ -65,6 +65,22 @@ public static boolean equals(Object o1, Object o2) {
public static String toString(Object obj) {
return (obj == null ? null : obj.toString());
}

/**
* Convert Atom[] to a space-separated String
*/
public static String toString(Atom[] atoms) {
String s = "";
if(atoms != null) {
for(int i=0; i< atoms.length; i++) {
if(i > 0) {
s += " ";
}
s += atoms[i].toString();
}
}
return s;
}

public static Atom[] toAtoms(Collection<? extends Atomizer> objs) {
Atom[] atoms = new Atom[objs.size()];
Expand Down

0 comments on commit b38e024

Please sign in to comment.