/* MarcusDaniels Dec 27, 1999 Below is an example of how to use the `foreign action' FCall feature found in the current sources. It avoids wrapping scalars in Objects, and thus avoids the problem you're having. Note that unlike C, that `long' in Java is fixed at 64 bits. That's why use of the addLongLong:. I fixed some things related to long in today's snapshot, so if you're using longs, be sure to grab it. ftp://ftp.santafe.edu/pub/swarm/testing/swarm-1999-12-27.tar.gz */ import swarm.objectbase.SwarmImpl; import swarm.defobj.Zone; import swarm.activity.Schedule; import swarm.activity.ScheduleImpl; import swarm.objectbase.Swarm; import swarm.activity.Activity; import swarm.defobj.FCallImpl; import swarm.defobj.FCall; import swarm.defobj.FArgumentsImpl; import swarm.defobj.FArgumentsCImpl; import swarm.defobj.FArguments; import swarm.defobj.FArgumentsC; import swarm.Selector; import swarm.Globals; public class TestFAction extends SwarmImpl { TestFAction (Zone aZone) { super (aZone); } Schedule schedule; Schedule stopSchedule; public void stepSwarm (long val) { System.out.println ("step @ " + Globals.env.getCurrentTime () + " val: " + val); } public void stopSwarm () { getActivity ().terminate (); } FCall createCall () { try { FArgumentsC creating = new FArgumentsCImpl (new FArgumentsImpl ()); Selector sel = new Selector (getClass (), "stepSwarm", false); creating.createBegin (getZone ()); creating.setJavaFlag (true); creating.setSelector (sel); creating.addLongLong (100); return new FCallImpl (getZone (), this, sel, (FArguments) creating.createEnd ()); } catch (Exception e) { e.printStackTrace (System.err); } return null; } FCall createStopCall () { try { Selector sel = new Selector (getClass (), "stopSwarm", false); return new FCallImpl (getZone (), this, sel, new FArgumentsImpl (getZone (), sel, true)); } catch (Exception e) { e.printStackTrace (System.err); } return null; } public Object buildActions () { super.buildActions (); schedule = new ScheduleImpl (this, 1); stopSchedule = new ScheduleImpl (this, true); schedule.at$createFAction (0, createCall ()); stopSchedule.at$createFAction (10, createStopCall ()); return this; } public Activity activateIn (Swarm swarmContext) { super.activateIn (swarmContext); schedule.activateIn (this); stopSchedule.activateIn (this); return getActivity (); } static void main (String[] args) { Globals.env.initSwarm ("TestFAction", "0.0", "bug-swarm@santafe.edu", args); TestFAction testFAction = new TestFAction (Globals.env.globalZone); testFAction.buildObjects (); testFAction.buildActions (); testFAction.activateIn (null).run (); } }