|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Object | +--newton.Ref
A Ref is a pointer to an underlying NewtonScript object. The following objects are typically pointed to: nil, ints, chars, symbols, frames, arrays, floats, strings, binary objects, functions, and magic pointers.
Refs are generally immutable; they will not change to point to different NewtonScript objects. Of course, you can modify features of the underlying object as you please, changing its class or length or slots, etc. Just use the various set... methods.
The Ref class implements much of the NewtonScript language access facility, with some notable exceptions:
Most of these have been left out because they're not too common, and the class is getting too big as it is. Perhaps at some point some will be added in with popular demand. Let me know.
| Field Summary | |
static int |
ARRAY
The Ref's type() is an array |
static int |
BINARY
The Ref's type() is a binary object other than a string or a float |
static int |
CHAR
The Ref's type() is a character |
static int |
FLOAT
The Ref's type() is a float |
static int |
FRAME
The Ref's type() is a frame |
static int |
FUNCTION
The Ref's type() is a function |
static int |
INT
The Ref's type() is a integer |
static int |
MAGIC
The Ref's type() is a magic pointer of some kind |
static int |
NIL
The Ref's type() is nil |
static int |
STRING
The Ref's type() is a string |
static int |
SYMBOL
The Ref's type() is a symbol |
static int |
UNKNOWN
The Ref's type() is an unknown object |
| Constructor Summary | |
Ref()
Makes nil. |
|
Ref(char val)
Makes a char. |
|
Ref(float val)
Makes a float. |
|
Ref(int val)
Makes an int. |
|
Ref(String val)
Makes a string. |
|
| Method Summary | |
Ref |
call(Ref[] args)
Calls me (a function or symbol) as a function, passing in args. |
static Ref |
call(String name)
Calls a global function named name of no arguments. |
static Ref |
call(String name,
Ref arg1)
Calls a global function named name, of one argument. |
static Ref |
call(String name,
Ref[] args)
Calls a global function named name, passing it args. |
static Ref |
call(String name,
Ref arg1,
Ref arg2)
Calls a global function named name, of two arguments. |
static Ref |
call(String name,
Ref arg1,
Ref arg2,
Ref arg3)
Calls a global function named name, of three arguments. |
char |
charValue()
Returns my char value. |
float |
floatValue()
Returns my float value. |
byte[] |
getBytes(int refStart,
int numBytesToGet)
Gets numBytesToGet bytes out of a binary object, starting at refStart. |
int |
getBytes(int refStart,
int putInStart,
int numBytesToGet,
byte[] putInHere)
Gets numBytesToGet bytes out of a binary object, starting at position refstart in the binary object, and filling at position putInStart in the byte array, which is supplied with putInHere. |
int |
getLength()
Returns the length of the binary object, string, or array. |
Ref |
getObjectClass()
Returns my class. |
Ref |
getPath(String slotName)
Looks up a slot in a frame, searching parent hierarchies if necessary (unlike getSlot). |
Ref |
getSlot(int slot)
Returns the value of a slot in an array. |
Ref |
getSlot(String slotName)
Returns the value of an immediate slot in a frame. |
int |
intValue()
Returns my int value. |
static Ref |
newArray(int size)
Makes an array of the given size, with all elements initialized to nil. |
static Ref |
newBinary(int size,
Ref _class)
Makes a binary object of the given size and class. |
static Ref |
newFrame()
Makes an empty frame. |
static Ref |
newSymbol(String val)
Makes a symbol. |
Ref |
push(Ref val)
Adds val to the end of the array, and returns the array. |
Ref |
send(Ref methodName,
Ref[] args)
Sends a method call to me (a frame), passing in args. |
Ref |
send(String methodName)
Sends a method call on me, named name, with no arguments. |
Ref |
send(String methodName,
Ref arg1)
Sends a method call on me, named name, with one argument. |
Ref |
send(String methodName,
Ref[] args)
Sends a method call on me, named name, with arguments. |
Ref |
send(String methodName,
Ref arg1,
Ref arg2)
Sends a method call on me, named name, with two arguments. |
Ref |
send(String methodName,
Ref arg1,
Ref arg2,
Ref arg3)
Sends a method call on me, named name, with three arguments. |
int |
setBytes(int refStart,
int getFromStart,
int numBytesToSet,
byte[] getFromHere)
Sets up to numBytesToSet bytes in a binary object, increasing the size if necessary (and possible). |
Ref |
setClass(Ref thisClass)
Sets the class of the object. |
Ref |
setClass(String thisClass)
Sets the class of the object and returns the object. |
int |
setLength(int newLength)
Tries to set the length of an array. |
Ref |
setSlot(int slot,
Ref val)
Sets a slot in an array and returns the array. |
Ref |
setSlot(Ref slotName,
Ref slotVal)
Sets an immediate slot in a frame and returns the frame. |
Ref |
setSlot(String slotName,
Ref slotVal)
Sets an immediate slot in a frame and returns the frame. |
String |
stringValue()
Returns my string value. |
String |
symbolValue()
Returns my symbol value. |
int |
type()
Returns the type of the underlying NewtonScript object pointed to by this Ref. |
| Methods inherited from class java.lang.Object |
equals, hashCode, toString |
| Field Detail |
public static final int NIL
public static final int INT
public static final int CHAR
public static final int SYMBOL
public static final int FRAME
public static final int ARRAY
public static final int FLOAT
public static final int STRING
public static final int BINARY
public static final int FUNCTION
public static final int MAGIC
public static final int UNKNOWN
| Constructor Detail |
public Ref()
| Java Code | new Ref() |
| NewtonScript Equivalent | nil |
public Ref(int val)
| Java Code | new Ref(4) |
| NewtonScript Equivalent | 4 |
public Ref(char val)
| Java Code | new Ref('f') |
| NewtonScript Equivalent | $f |
public Ref(String val)
| Java Code | new Ref("hello") |
| NewtonScript Equivalent | "hello" |
public Ref(float val)
| Java Code | new Ref("hello") |
| NewtonScript Equivalent | "hello" |
| Method Detail |
public int type()
public static Ref newSymbol(String val)
| Java Code | Ref.newSymbol("name") |
| NewtonScript Equivalent | 'name |
public static Ref newArray(int size)
| Java Code | Ref.newArray(4) |
| NewtonScript Equivalent | Array(4,nil) |
public static Ref newBinary(int size,
Ref _class)
| Java Code | Ref.newBinary(4, Ref.newSymbol('foo)) |
| NewtonScript Equivalent | MakeBinary(4,'foo) |
public static Ref newFrame()
| Java Code | Ref.newFrame() |
| NewtonScript Equivalent | { } |
public int intValue()
public char charValue()
public String symbolValue()
public String stringValue()
public float floatValue()
public Ref getObjectClass()
| Java Code | myobjRef.getClass() |
| NewtonScript Equivalent | ClassOf(myobj) |
By the way, I'd call this "getClass()", except that there's already a java.lang.Object method of that name. :-(
public Ref getSlot(int slot)
| Java Code | myarrayRef.getSlot(4) |
| NewtonScript Equivalent | myarray[4] |
public Ref getSlot(String slotName)
| Java Code | myframeRef.getSlot("foo") |
| NewtonScript Equivalent | GetSlot(myframe,'foo) |
public Ref getPath(String slotName)
| Java Code | myframeRef.getPath("foo") |
| NewtonScript Equivalent | myframe.foo |
public int getBytes(int refStart,
int putInStart,
int numBytesToGet,
byte[] putInHere)
public byte[] getBytes(int refStart,
int numBytesToGet)
public int getLength()
public int setBytes(int refStart,
int getFromStart,
int numBytesToSet,
byte[] getFromHere)
public int setLength(int newLength)
| Java Code | myarrayRef.setLength(100) |
| NewtonScript Equivalent | SetLength(myarray,100) |
public Ref setClass(Ref thisClass)
| Java Code | Ref foo = Ref.newSymbol(foo); int len = myarrayRef.getLength(); for(int x=0;x<len;x++) myarrayRef.getSlot(x).setClass(foo); |
| NewtonScript Equivalent | local x; for x:= 0 to Length(myarray)-1 do SetClass(myarray[x],'foo); |
public Ref setClass(String thisClass)
| Java Code | myobjRef.setClass("foo") |
| NewtonScript Equivalent | begin SetClass(myobj,'foo); myobj end |
public Ref setSlot(int slot,
Ref val)
| Java Code | myarrayRef.setSlot(4, myobjRef) |
| NewtonScript Equivalent | begin myarray[4]:=myobj; myarray end |
public Ref push(Ref val)
| Java Code | myarrayRef.push(myobjRef) |
| NewtonScript Equivalent | begin AddArraySlot(myarray,myobj); myarray end |
public Ref setSlot(Ref slotName,
Ref slotVal)
| Java Code | Ref foo = Ref.newSymbol(foo); int len = myarrayRef.getLength(); for(int x=0;x<len;x++) myarrayRef.getSlot(x).setSlot(foo, new Ref("Hi!")); |
| NewtonScript Equivalent | local x; for x:= 0 to Length(myarray)-1 do myarray[x].foo := "Hi!"; |
public Ref setSlot(String slotName,
Ref slotVal)
| Java Code | myobjRef.setSlot("foo", new Ref("Hi!")) |
| NewtonScript Equivalent | begin myobj.foo := "Hi"; myobj end |
public Ref call(Ref[] args)
| Java Code | Ref[] args = new Ref[4]; args[0] = new Ref(4); args[1] = new Ref("Yo"); args[2] = new Ref(0); args[3] = new Ref(); Ref returnval = myfuncRef.call(new Ref("Hi!"), args); |
| NewtonScript Equivalent | local returnval := Apply(myfunc, [4,"Yo",0,nil]); |
public static Ref call(String name,
Ref[] args)
| Java Code | Ref[] args = new Ref[4]; args[0] = new Ref(4); args[1] = new Ref("Yo"); args[2] = new Ref(0); args[3] = new Ref(); Ref returnval = Ref.call("Doit", args); |
| NewtonScript Equivalent | local returnval := Doit(4,"Yo",0,nil); |
public static Ref call(String name)
| Java Code | Ref returnval = Ref.call("Doit"); |
| NewtonScript Equivalent | local returnval := Doit(); |
public static Ref call(String name,
Ref arg1)
| Java Code | Ref returnval = Ref.call("Doit", new Ref(4)); |
| NewtonScript Equivalent | local returnval := Doit(4); |
public static Ref call(String name,
Ref arg1,
Ref arg2)
| Java Code | Ref returnval = Ref.call("Doit", new Ref(4), new Ref("Hey!")); |
| NewtonScript Equivalent | local returnval := Doit(4, "Hey!"); |
public static Ref call(String name,
Ref arg1,
Ref arg2,
Ref arg3)
| Java Code | Ref returnval = Ref.call("Doit", new Ref(4), new Ref("Hey!"), new Ref()); |
| NewtonScript Equivalent | local returnval := Doit(4, "Hey!", nil); |
public Ref send(Ref methodName,
Ref[] args)
| Java Code | Ref[] args = new Ref[4]; args[0] = new Ref(4); args[1] = new Ref("Yo"); args[2] = new Ref(0); args[3] = new Ref(); Ref methodname = Ref.newSymbol("Doit"); Ref returnval = myobjRef.send(methodname, args); |
| NewtonScript Equivalent | local returnval := myobj:Doit(4,"Yo",0,nil); |
public Ref send(String methodName,
Ref[] args)
| Java Code | Ref[] args = new Ref[4]; args[0] = new Ref(4); args[1] = new Ref("Yo"); args[2] = new Ref(0); args[3] = new Ref(); Ref returnval = myobjRef.send("Doit", args); |
| NewtonScript Equivalent | local returnval := myobj:Doit(4,"Yo",0,nil); |
public Ref send(String methodName)
| Java Code | Ref returnval = myframeRef.send("Doit"); |
| NewtonScript Equivalent | local returnval := myframe:Doit(); |
public Ref send(String methodName,
Ref arg1)
| Java Code | Ref returnval = myframeRef.send("Doit", new Ref(4)); |
| NewtonScript Equivalent | local returnval := myframe:Doit(4); |
public Ref send(String methodName,
Ref arg1,
Ref arg2)
| Java Code | Ref returnval = myframeRef.send("Doit", new Ref(4), new Ref("Yo")); |
| NewtonScript Equivalent | local returnval := myframe:Doit(4, "Yo"); |
public Ref send(String methodName,
Ref arg1,
Ref arg2,
Ref arg3)
| Java Code | Ref returnval = myframeRef.send("Doit", new Ref(4), new Ref("Yo"), new Ref(0)); |
| NewtonScript Equivalent | local returnval := myframe:Doit(4, "Yo", 0); |
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||