Extension command error

82 views
Skip to first unread message

Tony Bigbee

unread,
Dec 17, 2013, 6:14:22 PM12/17/13
to netlog...@googlegroups.com
Hi,

When I try to execute the first-n-integers extension example:

show noise:first-n-integers 5

I receive an error "ERROR: Expected command. " in the console or in the code tab.
I have mostly copied and pasted the class examples as is, just renaming them and putting them in a different package.  I wish the ERROR command was a little more descriptive, as I suspect I am making a simple error somewhere.

I'm using 5.0.4 without the JRE and 1.7.0_45 JRE/JDK on a x64 Windows 7 machine. 

My manifest.txt file with fully-qualified class-manager and crlf at the end of the version line--

Manifest-Version: 1.0
Extension-Name: noise
Class-Manager: org.xyz.extensions.NoiseExtension
NetLogo-Extension-API-Version: 5.0  <--there is a crlf here

the jar is in a subfolder with my model file

test/
  test.nlogo
  noise/
    noise.jar


This is my Class-Manager:

package org.xyz.extensions;

import org.nlogo.api.*;

/**
 * @author Tony Bigbee
 */
public class NoiseExtension extends DefaultClassManager {
  public void load(PrimitiveManager primitiveManager) {
    primitiveManager.addPrimitive(
      "first-n-integers", new org.xyz.extensions.NoiseGenerator());
  }
}

This is the NoiseGenerator file:

package org.xyz.extensions;
import org.nlogo.api.*;

public class NoiseGenerator extends DefaultReporter {

    public Syntax getSynax() {
        return Syntax.reporterSyntax(
        new int[] {Syntax.NumberType()}, Syntax.ListType());
       
    }
   
    public Object report(Argument args[], Context context) throws ExtensionException {
    // create a NetLogo list for the result
    LogoListBuilder list = new LogoListBuilder();
    int n ;
    // use typesafe helper method from
    // org.nlogo.api.Argument to access argument
    try {
      n = args[0].getIntValue(); 
    }
    catch(LogoException e) {
      throw new ExtensionException( e.getMessage() ) ;
    }
    if (n < 0) {
    // signals a NetLogo runtime error to the modeler
    throw new ExtensionException
      ("input must be positive");
    }
    // populate the list. note that we use Double objects; NetLogo
    // numbers are always Doubles
    for (int i = 0; i < n; i++) {
      list.add(Double.valueOf(i));
    }
    return list.toLogoList();
  }
}

Thanks for any help.

AJB
 

Tony Bigbee

unread,
Dec 17, 2013, 6:27:43 PM12/17/13
to netlog...@googlegroups.com
Sorry - I meant to post this to one of the other user-oriented lists.  Please disregard.

Seth Tisue

unread,
Dec 17, 2013, 6:49:00 PM12/17/13
to netlog...@googlegroups.com
>>>>> "Tony" == Tony Bigbee <tony....@gmail.com> writes:

Tony> Sorry - I meant to post this to one of the other user-oriented
Tony> lists. Please disregard.

netlogo-devel is the right list for API questions, including extensions
API questions. (Stack Overflow is fine as well.)

>> public Syntax getSynax() { return Syntax.reporterSyntax( new int[]
>> {Syntax.NumberType()}, Syntax.ListType());

Does changing `getSynax` to `getSyntax` fix it?

--
Seth Tisue | Northwestern University | http://tisue.net
developer, NetLogo: http://ccl.northwestern.edu/netlogo/

Tony Bigbee

unread,
Dec 17, 2013, 10:38:12 PM12/17/13
to netlog...@googlegroups.com
Yes, that was the problem.  Thanks for the quick reply.
Reply all
Reply to author
Forward
0 new messages