Internal use.
| Class Methods |
|---|
|
create_duplicate( Object existing ).Object
This factory method initiates object duplication. The
compiler transforms the duplicate(obj) command into
Object.create_duplicate(obj).
Returns: 'null' if 'existing' is null. existing.create_duplicate otherwise |
| Object Variables |
|---|
|
next : PatternMatcher terms : PatternMatcher[] |
| Object Methods |
|---|
|
chain_next( PatternMatcher _next ) compare_to( Object other ).Ternary
This method is used for ordering (quantitative) comparisons
between this object and another.
create_duplicate().ObjectReturns 'eq' if they're equivalent, 'lt' if this object is "less than" the other, or 'gt' if this object is "greater than" another. The compiler converts: 'obj1 < obj2' -> 'obj1.compare_to(obj2) == lt' 'obj1 > obj2' -> 'obj1.compare_to(obj2) == gt' 'obj1 <= obj2' -> 'obj1.compare_to(obj2) != gt' 'obj1 >= obj2' -> 'obj1.compare_to(obj2) != lt'Implementations of compare_to() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract:
if (obj1.compare_to(obj2) == eq)
obj1.equals(obj2) == true
obj1.hash_code == obj2.hash_code
else
obj1.equals(obj2) == false
endIf
Note that two "equal" objects *must* have the same hash code,
but "unequal" objects may or may not have the same hash code.
This default implementation throws an UnsupportedMethodError.
Should create a duplicate of this object such that
obj1.equals(obj1.create_duplicate) return true.
equals( Object other ).BooleanThe command duplicate(obj) is transformed by the compiler into Object.create_duplicate(obj), which then calls this method. For optimal performance (by removing an internal typecast in most situations), have your overridden create_duplicate have the same return type as the class it's defined in. For instance, Strings implementation is 'create_duplicate.String'. This default implementation throws an UnsupportedMethodError.
Returns true if this object is equivalant to another.
hash_code().Int32The compiler converts 'obj1 == obj2' into 'obj1.equals(obj2)' and 'obj1 != obj2' into 'not obj1.equals(obj2)'. Implementations of equals() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract: if (obj1.equals(obj2)) obj1.compare_to(obj2) == eq obj1.hash_code == obj2.hash_code else obj1.compare_to(obj2) != eq endIfNote that two "equal" objects *must* have the same hash code, but "unequal" objects may or may not have the same hash code. This default implementation returns true if the this object and the 'other' reference are the same object ('this is other').
Returns the hash code of this object, which some classes
(like HashTable) rely on. This default implementation
throws an UnsupportedMethodError.
init( PatternMatcher p1, PatternMatcher p2, PatternMatcher p3 )Hash codes are used to quickly test and see if two complex objects are NOT equal. The value returned has no intrinsic meaning, but should conform to the following rules: 1. Two objects that are equivalent should produce the same hash code. 2. If an object's state doesn't change, its hash code shouldn't change either. Internally, this precludes the hash code being based on an object's memory address since Slag doesn't guarantee that an object's address won't change over time. This has the following implications: If you override hash_code you should also override equals() and possibly compare_to() and ensure the following contract. Invariant:
if (obj1.hash_code != obj2.hash_code)
obj1.equals(obj2) == false
obj1.compare_to(obj2) != eq
endIf
init() init( PatternMatcher p1, PatternMatcher p2 ) match( PatternMatchInfo state ).Boolean match_next( PatternMatchInfo state ).Boolean matches_any().Boolean
Overridden in CharRangePatternMatcher
to_String().Stringtype_name().String
Returns the true class name of this object. Implemented by
the runtime; you should not override this method.
Example: local Object obj = "Hello World" println( obj.type_name ) #prints: String |
Internal use.
| Class Methods |
|---|
|
create_duplicate( Object existing ).Object
This factory method initiates object duplication. The
compiler transforms the duplicate(obj) command into
Object.create_duplicate(obj).
Returns: 'null' if 'existing' is null. existing.create_duplicate otherwise |
| Object Variables |
|---|
|
max_count : Int32 min_count : Int32 next : PatternMatcher |
| Object Methods |
|---|
|
chain_next( PatternMatcher _next ) compare_to( Object other ).Ternary
This method is used for ordering (quantitative) comparisons
between this object and another.
create_duplicate().ObjectReturns 'eq' if they're equivalent, 'lt' if this object is "less than" the other, or 'gt' if this object is "greater than" another. The compiler converts: 'obj1 < obj2' -> 'obj1.compare_to(obj2) == lt' 'obj1 > obj2' -> 'obj1.compare_to(obj2) == gt' 'obj1 <= obj2' -> 'obj1.compare_to(obj2) != gt' 'obj1 >= obj2' -> 'obj1.compare_to(obj2) != lt'Implementations of compare_to() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract:
if (obj1.compare_to(obj2) == eq)
obj1.equals(obj2) == true
obj1.hash_code == obj2.hash_code
else
obj1.equals(obj2) == false
endIf
Note that two "equal" objects *must* have the same hash code,
but "unequal" objects may or may not have the same hash code.
This default implementation throws an UnsupportedMethodError.
Should create a duplicate of this object such that
obj1.equals(obj1.create_duplicate) return true.
equals( Object other ).BooleanThe command duplicate(obj) is transformed by the compiler into Object.create_duplicate(obj), which then calls this method. For optimal performance (by removing an internal typecast in most situations), have your overridden create_duplicate have the same return type as the class it's defined in. For instance, Strings implementation is 'create_duplicate.String'. This default implementation throws an UnsupportedMethodError.
Returns true if this object is equivalant to another.
hash_code().Int32The compiler converts 'obj1 == obj2' into 'obj1.equals(obj2)' and 'obj1 != obj2' into 'not obj1.equals(obj2)'. Implementations of equals() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract: if (obj1.equals(obj2)) obj1.compare_to(obj2) == eq obj1.hash_code == obj2.hash_code else obj1.compare_to(obj2) != eq endIfNote that two "equal" objects *must* have the same hash code, but "unequal" objects may or may not have the same hash code. This default implementation returns true if the this object and the 'other' reference are the same object ('this is other').
Returns the hash code of this object, which some classes
(like HashTable) rely on. This default implementation
throws an UnsupportedMethodError.
init( [Int32 min_count], [Int32 max_count] )Hash codes are used to quickly test and see if two complex objects are NOT equal. The value returned has no intrinsic meaning, but should conform to the following rules: 1. Two objects that are equivalent should produce the same hash code. 2. If an object's state doesn't change, its hash code shouldn't change either. Internally, this precludes the hash code being based on an object's memory address since Slag doesn't guarantee that an object's address won't change over time. This has the following implications: If you override hash_code you should also override equals() and possibly compare_to() and ensure the following contract. Invariant:
if (obj1.hash_code != obj2.hash_code)
obj1.equals(obj2) == false
obj1.compare_to(obj2) != eq
endIf
match( PatternMatchInfo state ).Boolean match_next( PatternMatchInfo state ).Boolean matches_any().Boolean
Overridden in CharRangePatternMatcher
to_String().Stringtype_name().String
Returns the true class name of this object. Implemented by
the runtime; you should not override this method.
Example: local Object obj = "Hello World" println( obj.type_name ) #prints: String |
The base class for every Plasmacore game or application. Extend your game class from this class and override methods as warranted. Start with init(), update(), and draw().
| Class Methods |
|---|
|
close_all_archives()
Closes all archives cached by open_archive() and frees the memory
used by them.
create_duplicate( Object existing ).Object
This factory method initiates object duplication. The
compiler transforms the duplicate(obj) command into
Object.create_duplicate(obj).
exit_program()Returns: 'null' if 'existing' is null. existing.create_duplicate otherwise
Causes the native framework to immediately exit the
application. Typically called from on_exit_request(), but
may be called independently.
input_capture( Boolean setting )Example: Application.exit_program
Property-set that specifies whether input is captured by
(and restricted to) this application. This is "false" by
default.
language().StringExample: Application.input_capture = true
Returns the language used by the application. On many platforms this returns
"english". On the Wii this returns one of:
mouse_visible( Boolean setting )english, japanese, german, french, spanish, italian, dutch
Property-set that specifies the visibility of the system
mouse. This is "true" by default.
open_archive( String filename )Example: Application.mouse_visible = false
Attempts to locate and load the named ZIP file
into memory. The archive is not uncompressed when loaded.
Subsequent attempts to open any file for reading (including
loading images and sounds) will first check and see if the file
is in any of the archives that have been opened with
open_archive(). If found, the file is uncompressed and read
from the archive. If not found, Plasmacore searches for the file
in the regular filesystem.
platform().StringIf 'filename' is, for example, "images", Plasmacore will attempt to open the archive using the following paths: images images.zip data/images data/images.zipAny number of archives may be opened concurrently - all of them are searched when a file is requested. Call close_all_archives() to close the archives and free up the memory used by them. Using archives in this fashion allows for a clean and compact distribution with no significant difference in loading speed on the Windows Plasmacore platform. However, writing games to utilize the archive system should yield speed benefits on platforms (e.g. Wii) where I/O seek time and data transfer rates are an issue (such as reading data off optical drive or over the network). Note when opening input files (including loading images and sounds), the following variations of the filename are automatically checked: filename filename.ext (ext = png, jpg, etc. as appropriate) data/filename data/filename.extThis means that when creating this new image object: Image("images/sprites"), the file "sprites.png" could either be located under "data/images/sprites.png" or under "images/sprites.png" in the archive "data/images.zip". WARNING: once again, open_archive does not simply add a search path to the zip file on disc - it actually loads the entire file into memory!
Returns the platform this game is running on. Currently supported
platforms include:
window_title( String title )windows, wii
Window title property-set for this application.
Example: Application.window_title = "MadStone" |
| Object Methods |
|---|
|
call_draw( Int32 window_width, Int32 window_height )
Internal use. Wraps a call to draw() in a try/catch block.
call_init( Int32 display_width, Int32 display_height )
Internal use. Wraps a call to init() in a try/catch block.
call_update()
Internal use. Wraps a call to update() in a try/catch block.
compare_to( Object other ).Ternary
This method is used for ordering (quantitative) comparisons
between this object and another.
create_duplicate().ObjectReturns 'eq' if they're equivalent, 'lt' if this object is "less than" the other, or 'gt' if this object is "greater than" another. The compiler converts: 'obj1 < obj2' -> 'obj1.compare_to(obj2) == lt' 'obj1 > obj2' -> 'obj1.compare_to(obj2) == gt' 'obj1 <= obj2' -> 'obj1.compare_to(obj2) != gt' 'obj1 >= obj2' -> 'obj1.compare_to(obj2) != lt'Implementations of compare_to() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract:
if (obj1.compare_to(obj2) == eq)
obj1.equals(obj2) == true
obj1.hash_code == obj2.hash_code
else
obj1.equals(obj2) == false
endIf
Note that two "equal" objects *must* have the same hash code,
but "unequal" objects may or may not have the same hash code.
This default implementation throws an UnsupportedMethodError.
Should create a duplicate of this object such that
obj1.equals(obj1.create_duplicate) return true.
draw()The command duplicate(obj) is transformed by the compiler into Object.create_duplicate(obj), which then calls this method. For optimal performance (by removing an internal typecast in most situations), have your overridden create_duplicate have the same return type as the class it's defined in. For instance, Strings implementation is 'create_duplicate.String'. This default implementation throws an UnsupportedMethodError.
Redraws the game. Called up to 60 times per second. You
should not change the game's data model at this point.
equals( Object other ).Boolean
Returns true if this object is equivalant to another.
hash_code().Int32The compiler converts 'obj1 == obj2' into 'obj1.equals(obj2)' and 'obj1 != obj2' into 'not obj1.equals(obj2)'. Implementations of equals() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract: if (obj1.equals(obj2)) obj1.compare_to(obj2) == eq obj1.hash_code == obj2.hash_code else obj1.compare_to(obj2) != eq endIfNote that two "equal" objects *must* have the same hash code, but "unequal" objects may or may not have the same hash code. This default implementation returns true if the this object and the 'other' reference are the same object ('this is other').
Returns the hash code of this object, which some classes
(like HashTable) rely on. This default implementation
throws an UnsupportedMethodError.
init()Hash codes are used to quickly test and see if two complex objects are NOT equal. The value returned has no intrinsic meaning, but should conform to the following rules: 1. Two objects that are equivalent should produce the same hash code. 2. If an object's state doesn't change, its hash code shouldn't change either. Internally, this precludes the hash code being based on an object's memory address since Slag doesn't guarantee that an object's address won't change over time. This has the following implications: If you override hash_code you should also override equals() and possibly compare_to() and ensure the following contract. Invariant:
if (obj1.hash_code != obj2.hash_code)
obj1.equals(obj2) == false
obj1.compare_to(obj2) != eq
endIf
Called to set up the game. Do not call any drawing operations
at this point.
listen_to( DispatcherType dispatcher )
Instructs this JoystickListener to listen to the given
dispatcher.
on_exit_request()
Called when the user presses the close window button. Calls
exit_program() by default. You can override this method to
perform cleanup and/or postpone the call to exit_program at
some later point.
on_joystick_button_press( JoystickEvent event )
See JoystickEvent for more information.
on_joystick_button_release( JoystickEvent event )
See JoystickEvent for more information.
on_joystick_connected( JoystickEvent event )
See JoystickEvent for more information.
on_joystick_hat_movement( JoystickEvent event )
See JoystickEvent for more information.
on_joystick_movement( JoystickEvent event )
See JoystickEvent for more information.
on_key_press( KeyEvent event )
Called when a key is pressed. An on_keystroke() event is
generated at the same time. If the key is held down for
a while, key repeat events are sent as additional
on_keystroke() events. 'event' contains information about
the key.
on_key_release( KeyEvent event )
Called when a key is released. 'event' contains information
about the key.
on_keystroke( KeyEvent event )
Called when a key has either been pressed and released or is
pressed and is repeating. 'event' contains information about
the key.
on_mouse_absent()
Called when the the game window loses mouse focus.
on_mouse_button_press( MouseEvent event )
Called when a mouse button has been pressed.
on_mouse_button_release( MouseEvent event )'event.button' contains the index of the mouse button being pressed (1=left, 2=right). 'event.position' contains the absolute mouse position at the time of the press.
Called when a mouse button has been pressed.
on_mouse_movement( MouseEvent event )'event.button' contains the index of the mouse button being pressed (1=left, 2=right). 'event.position' contains the absolute mouse position at the time of the press.
Called when the mouse position changes. 'event' contains the
new mouse position in relative (delta) coordinates.
on_mouse_position( MouseEvent event )on_mouse_position() is also called with the new absolute position.
Called when the mouse position changes. 'event' contains the
new mouse position in absolute coordinates.
on_mouse_present()on_mouse_movement() is also called with the relative position change.
Called when the mouse focus returns to the game window after
being elsewhere.
on_mouse_wheel_down( MouseEvent event )
Called when the mouse wheel has been rotated one click down.
on_mouse_wheel_up( MouseEvent event )'event.position' contains the absolute mouse position at the time of the wheel movement.
Called when the mouse wheel has been rotated one click up.
on_toggle_fullscreen()'event.position' contains the absolute mouse position at the time of the wheel movement.
Called by the input object when an ALT+ENTER key combination
is detected. The default behavior is to toggle the fullscreen
property setting.
on_trackball_movement( JoystickEvent event )
See JoystickEvent for more information.
stop_listening_to( DispatcherType dispatcher )
Stops this JoystickListener from listening to the given
dispatcher.
to_String().String
Returns:
type_name().StringA String representation of this object. Most classes should override this method to summarize an object's state for convenience in testing and debugging.
Returns the true class name of this object. Implemented by
the runtime; you should not override this method.
update()Example: local Object obj = "Hello World" println( obj.type_name ) #prints: String
Called 60 times per second guaranteed. Do not perform any
drawing actions; just update the world's data model.
|
Internal use.
| Class Methods |
|---|
|
create_duplicate( Object existing ).Object
This factory method initiates object duplication. The
compiler transforms the duplicate(obj) command into
Object.create_duplicate(obj).
Returns: 'null' if 'existing' is null. existing.create_duplicate otherwise |
| Object Variables |
|---|
|
max_count : Int32 min_count : Int32 next : PatternMatcher term : PatternMatcher |
| Object Methods |
|---|
|
chain_next( PatternMatcher _next ) compare_to( Object other ).Ternary
This method is used for ordering (quantitative) comparisons
between this object and another.
create_duplicate().ObjectReturns 'eq' if they're equivalent, 'lt' if this object is "less than" the other, or 'gt' if this object is "greater than" another. The compiler converts: 'obj1 < obj2' -> 'obj1.compare_to(obj2) == lt' 'obj1 > obj2' -> 'obj1.compare_to(obj2) == gt' 'obj1 <= obj2' -> 'obj1.compare_to(obj2) != gt' 'obj1 >= obj2' -> 'obj1.compare_to(obj2) != lt'Implementations of compare_to() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract:
if (obj1.compare_to(obj2) == eq)
obj1.equals(obj2) == true
obj1.hash_code == obj2.hash_code
else
obj1.equals(obj2) == false
endIf
Note that two "equal" objects *must* have the same hash code,
but "unequal" objects may or may not have the same hash code.
This default implementation throws an UnsupportedMethodError.
Should create a duplicate of this object such that
obj1.equals(obj1.create_duplicate) return true.
equals( Object other ).BooleanThe command duplicate(obj) is transformed by the compiler into Object.create_duplicate(obj), which then calls this method. For optimal performance (by removing an internal typecast in most situations), have your overridden create_duplicate have the same return type as the class it's defined in. For instance, Strings implementation is 'create_duplicate.String'. This default implementation throws an UnsupportedMethodError.
Returns true if this object is equivalant to another.
find_matches( PatternMatchInfo state ).BooleanThe compiler converts 'obj1 == obj2' into 'obj1.equals(obj2)' and 'obj1 != obj2' into 'not obj1.equals(obj2)'. Implementations of equals() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract: if (obj1.equals(obj2)) obj1.compare_to(obj2) == eq obj1.hash_code == obj2.hash_code else obj1.compare_to(obj2) != eq endIfNote that two "equal" objects *must* have the same hash code, but "unequal" objects may or may not have the same hash code. This default implementation returns true if the this object and the 'other' reference are the same object ('this is other'). hash_code().Int32
Returns the hash code of this object, which some classes
(like HashTable) rely on. This default implementation
throws an UnsupportedMethodError.
init( PatternMatcher term, [Int32 min_count], [Int32 max_count] )Hash codes are used to quickly test and see if two complex objects are NOT equal. The value returned has no intrinsic meaning, but should conform to the following rules: 1. Two objects that are equivalent should produce the same hash code. 2. If an object's state doesn't change, its hash code shouldn't change either. Internally, this precludes the hash code being based on an object's memory address since Slag doesn't guarantee that an object's address won't change over time. This has the following implications: If you override hash_code you should also override equals() and possibly compare_to() and ensure the following contract. Invariant:
if (obj1.hash_code != obj2.hash_code)
obj1.equals(obj2) == false
obj1.compare_to(obj2) != eq
endIf
match( PatternMatchInfo state ).Boolean match_next( PatternMatchInfo state ).Boolean matches_any().Boolean
Overridden in CharRangePatternMatcher
to_String().Stringtype_name().String
Returns the true class name of this object. Implemented by
the runtime; you should not override this method.
Example: local Object obj = "Hello World" println( obj.type_name ) #prints: String |
Primarily for internal use - in most cases use ArrayList instead.
Array is a placeholder type. Arrays are actually implemented in the runtime implementation; calls to array methods are intercepted by the program loader and translated into array-related opcodes.
The exception to this is when a call is made to an array using a reference of aspect types Readable or IndexedData - the loader is unable to intercept. However, the Slag-side implementation of each array simply calls itself, and *that* call *is* intercepted by the compiler.
To get an array in Slag you must be explicit, e.g. "Array<<Int32>>(20)". Convenience notation (such as Array[20]) generates ArrayLists instead.
Arrays are not covariant as they are in Java. An Array<<String>> counts as an Object but not as an Array<<Object>>.
Arrays may be extended or augmented but no new object variables may be added.
| Class Methods |
|---|
|
create_duplicate( Object existing ).Object
This factory method initiates object duplication. The
compiler transforms the duplicate(obj) command into
Object.create_duplicate(obj).
Returns: 'null' if 'existing' is null. existing.create_duplicate otherwise |
| Object Methods |
|---|
|
clear( Int32 first_index, Int32 last_index )
Clears all the elements in this array between the two indices.
compare_to( Object other ).TernaryUsing this method to clear elements at the end of an arraylist allows the runtime to limit the number of reference array elements it searches through during a data collection. Technical note: the runtime tracks the furthest position that a non-null reference array element could possibly be at after various calls to clear() and set().
This method is used for ordering (quantitative) comparisons
between this object and another.
contains( DataType value ).BooleanReturns 'eq' if they're equivalent, 'lt' if this object is "less than" the other, or 'gt' if this object is "greater than" another. The compiler converts: 'obj1 < obj2' -> 'obj1.compare_to(obj2) == lt' 'obj1 > obj2' -> 'obj1.compare_to(obj2) == gt' 'obj1 <= obj2' -> 'obj1.compare_to(obj2) != gt' 'obj1 >= obj2' -> 'obj1.compare_to(obj2) != lt'Implementations of compare_to() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract:
if (obj1.compare_to(obj2) == eq)
obj1.equals(obj2) == true
obj1.hash_code == obj2.hash_code
else
obj1.equals(obj2) == false
endIf
Note that two "equal" objects *must* have the same hash code,
but "unequal" objects may or may not have the same hash code.
This default implementation throws an UnsupportedMethodError.
Returns "true" if this data contains the given value.
copy_elements( ArrayType src_array, Int32 src_index, Int32 dest_index, Int32 number )
Copies 'number' elements from another array (starting at
element 'src_index') into this one (starting at element
'dest_index').
count().Int32Elements may be copied within overlapping regions of the same array.
Returns the count of how many elements are in this array.
create_duplicate().Array<<DataType>>
Creates a duplicate of this array when the "duplicate(array)"
command is given. If the array element type is a reference
type, the new array contains a copy of the same references
to the same objects - the objects themeselves are not
duplicated.
create_reader().Reader<<DataType>>
Returns a reader that can be used to read() this data one
element at a time.
end( Int32 from_end ).DataType
Equivalent to get( (count-1) + from_end ).
equals( DataType value ).Boolean[]For example, end(0) is equivalent to last() and end(-1) is equivalent to get(count-2).
Returns a list of Boolean values where each value true if
the corresponding element of this indexed data equals()
the given value.
equals( Readable<<DataType>> other ).Boolean
Returns true if each element of this data equals() each
corresponding element from in 'other'.
equals( Object other ).Boolean
Returns true if this object is equivalant to another.
first().DataTypeThe compiler converts 'obj1 == obj2' into 'obj1.equals(obj2)' and 'obj1 != obj2' into 'not obj1.equals(obj2)'. Implementations of equals() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract: if (obj1.equals(obj2)) obj1.compare_to(obj2) == eq obj1.hash_code == obj2.hash_code else obj1.compare_to(obj2) != eq endIfNote that two "equal" objects *must* have the same hash code, but "unequal" objects may or may not have the same hash code. This default implementation returns true if the this object and the 'other' reference are the same object ('this is other').
Returns the first element of this data. This convenience
method is equivalent to get(0).
format( String prefix, String prepeat, String suffix ).String
Converts this list into a string using the following format:
format( String str_format, [String repeater_chars] ).Stringprefix + $0 + [prepeat + $N]* + suffixwhere "$0" is the first element and $N is every other element. Example:
local Int32[] nums = 11..15
println( nums.to_String("[", "+", "]") )
# prints: [11+12+13+14+15]
Easier convenience method to accomplish to_String(prefix,prepeat,suffix).
from( Range<<Int32>> range ).Reader<<DataType>>Breaks down a simple format like this:
{$[ or $]}
Into a prefix="{", prepeat=" or ", suffix="}".
Normally "[]" brackets are used to denote the repeater portion, but this may be specified otherwise. Example: local Int32[] nums = 11..15 println( nums.to_String( "[$:+$:]", ":" ) # prints: [11+12+13+14+15]
Returns a reader that can be used to read() this data one
element at a time from the given starting index up to and
including the ending index.
from( Int32 starting_index ).Reader<<DataType>>
Returns a reader that can be used to read() this data one
element at a time with the given 'starting_index'.
get( Int32 index ).DataType
Retieves the element at the zero-based 'index'.
get( Readable<<Boolean>> flags ).DataType[]Requires: 0 <= index < count
Returns a new list containing the subset of elements
of which each of the corresponding 'flags' is true.
get( Readable<<Int32>> indices ).DataType[]Example:
local Int32[] nums = {1..10}
println( nums[nums % 2 == 0] )
#prints: {2,4,6,8,10}
Gets the element at each of the given zero-based 'indices'.
hash_code().Int32Example:
local Int32[] nums = {1..5}
nums[{0,4}] = nums[{4,0}]
println( nums )
#prints: {5,2,3,4,1}
Returns the hash code of this object, which some classes
(like HashTable) rely on. This default implementation
throws an UnsupportedMethodError.
index_of( DataType value, [Int32 starting_index] ).Int32Hash codes are used to quickly test and see if two complex objects are NOT equal. The value returned has no intrinsic meaning, but should conform to the following rules: 1. Two objects that are equivalent should produce the same hash code. 2. If an object's state doesn't change, its hash code shouldn't change either. Internally, this precludes the hash code being based on an object's memory address since Slag doesn't guarantee that an object's address won't change over time. This has the following implications: If you override hash_code you should also override equals() and possibly compare_to() and ensure the following contract. Invariant:
if (obj1.hash_code != obj2.hash_code)
obj1.equals(obj2) == false
obj1.compare_to(obj2) != eq
endIf
Returns the first index that the given value occurs at
starting at index 0 by default. (-1) is returned if
'value' is not found.
indices().Range<<Int32>>
Returns this data's range of indices (0..count-1).
init( Int32 size )
Sets up this array to contain the given number of elements.
is_empty().Boolean
Returns true if count == 0.
is_not_empty().Boolean
Returns true if count > 0.
last().DataType
Returns the last element of this data. This convenience
method is equivalent to get(count-1).
last_index_of( DataType value, [Int32 starting_index] ).Int32
Returns the last index that the given value occurs at
starting at index (count-1) by default. (-1) is
returned if 'value' is not found.
modification_count().Int32
Returns a counter representing the number of times items
has been added to or removed. Used by readers to detect
concurrent list modification errors. For example, when an inner
method removes an item from a list the modification counter
is incremented. An outer "forEach" loop will detect that the
count is different from its original value and throw a
ConcurrentListModification error.
random().DataType
Returns an element of this data at random.
reverse()
Reverses the order of the elements in this data.
reverse_indices().Range<<Int32>>
Returns this data's range of indices reversed (count-1 downTo 0).
reverse_order().Reader<<DataType>>Example:
local Int32[] nums = {5..7}
forEach (i in nums.reverse_indices) println( i )
#prints: 2 | 1 | 0
Returns a reader that can be used to read() this data one
element at a time from the last element (N-1) to the first (0).
reversed().IndexedData<<DataType>>
Returns an list containing the elements of this data
in reverse order.
set( Int32 index, DataType value )
Sets the element at the zero-based 'index' to the new 'value'.
set( Readable<<Boolean>> flags, DataType value )Requires: 0 <= index < count
Starting at index 0, sets each element to the given 'value'
if the corresponding 'element_flags' are true.
set( Readable<<Int32>> indices, Readable<<DataType>> values )Example:
local Int32[] nums = {1..5}
nums[nums%2==1] = 0
println( nums ) #prints: {0,2,0,4,0}
Sets the element at each of the given 'indices' to each of
the corresponding 'values'.
set( Readable<<Boolean>> element_flags, Readable<<DataType>> values )Requires: The number of indices == the number of values.Example:
local Int32[] nums = {1..5}
nums[0..4 step 2] = {7,8,9}
println( nums )
#prints: {7,2,8,4,9}
Starting at index 0, sets each element to the next of the
given 'values' if the corresponding 'element_flags' are true.
set( Readable<<Int32>> indices, DataType value )Example:
local Int32[] nums = {1..5}
nums[nums%2==1] = -nums
println( nums ) #prints: {-1,2,-3,4,-5}
Sets the element at each of the given 'indices' to the given
'value'.
shuffle()Example:
local Int32[] nums = {1..5}
nums[{0,4}] = nums[{4,0}]
println( nums )
#prints: {5,2,3,4,1}
Swaps every element of this data with another element at a
randomly-chosen position.
shuffled().IndexedData<<DataType>>
Returns a shuffled copy of this data.
subset( Int32 first_index, Int32 last_index ).ArrayList<<DataType>>
Returns the subset of this data between indices
[first_index,last_index] inclusive.
swap( Int32 index_a, Int32 index_b )
Swaps the value at 'index_a' with the one at 'index_b'.
to_List().DataType[]Requires: 0 <= index_a < count 0 <= index_b < countInvariant: this[index_a] = old[index_b] this[index_b] = old[index_a]
Converts this data into a list.
to_String().String
Returns a string representation of this data.
type_name().String
Returns the true class name of this object. Implemented by
the runtime; you should not override this method.
Example: local Object obj = "Hello World" println( obj.type_name ) #prints: String |
The most common "collection" type in Slag, an ArrayList is an indexable list of items implemented using arrays.
An array list has 'count' and 'capacity'. Capacity is how many elements an arraylist can store before it has to create a larger backing array. Count is how many elements of the current array are currently in use. When 'count' reaches 'capacity', the next add() operation causes the backing array to be doubled in size.
An arraylist starts out at capacity 10, count 0 by default.
When you use "array notation" in Slag it creates arraylists. The following convenience conversions are performed:
# Create an empty list with 10 capacity
Int32[] nums(10) # 10 capacity
-> List<<Int32>> nums = ArrayList<<Int32>>(10)
# Create a list of 10 zero/null values
Int32[] nums = Int32[10]
-> List<<Int32>> nums = ArrayList<<Int32>>( 10, 0 )
# Create a list with the numbers 1 to 3
Int32[] nums = { 1, 2, 3 }
-> List<<Int32>> nums = ...
ArrayList<<Int32>>().add(1).add(2).add(3)
Invariant:
count >= 0 capacity >= count data.count == capacity
| Class Methods |
|---|
|
create_duplicate( Object existing ).Object
This factory method initiates object duplication. The
compiler transforms the duplicate(obj) command into
Object.create_duplicate(obj).
Returns: 'null' if 'existing' is null. existing.create_duplicate otherwise |
| Object Variables |
|---|
|
counter : Int32
The position to add the next item - also equivalent to the
used item count.
data : Array<<DataType>>
The backing array for this arraylist.
modification_count : Int32 |
| Object Methods |
|---|
|
add( Readable<<DataType>> source ).List<<DataType>>
Adds each item from the Readable source to this list.
add( DataType value, Int32 after_index ).List<<DataType>>Returns a reference to this list for call-chaining.
Inserts 'value' after the given index.
add( DataType value ).ArrayList<<DataType>>Returns: A reference to this list for call-chaining.Requires: after_index >= -1 and after_index < countInvariant: new.count == old.count + 1 new[after_index+1] == value
Adds the given 'value' to the end of this list.
capacity().Int32Returns a reference to this list for call chaining. Invariant: count = old.count + 1 get[count-1] == value
Returns how many values this list can store before its backing
array must be doubled in size.
clear()
Removes all elements from this list. The capacity
is unchanged.
compare_to( Object other ).TernaryInvariant: new.count == 0 new.capacity == old.capacity
This method is used for ordering (quantitative) comparisons
between this object and another.
contains( DataType value ).BooleanReturns 'eq' if they're equivalent, 'lt' if this object is "less than" the other, or 'gt' if this object is "greater than" another. The compiler converts: 'obj1 < obj2' -> 'obj1.compare_to(obj2) == lt' 'obj1 > obj2' -> 'obj1.compare_to(obj2) == gt' 'obj1 <= obj2' -> 'obj1.compare_to(obj2) != gt' 'obj1 >= obj2' -> 'obj1.compare_to(obj2) != lt'Implementations of compare_to() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract:
if (obj1.compare_to(obj2) == eq)
obj1.equals(obj2) == true
obj1.hash_code == obj2.hash_code
else
obj1.equals(obj2) == false
endIf
Note that two "equal" objects *must* have the same hash code,
but "unequal" objects may or may not have the same hash code.
This default implementation throws an UnsupportedMethodError.
Returns "true" if this data contains the given value.
count().Int32
Returns how many values there are in this list.
create_duplicate().ArrayList<<DataType>>
Creates a duplicate of this list when the "duplicate(list)"
command is given. If the list element type is a reference
type, the new list contains a copy of the same references
to the same objects - the objects themeselves are not
duplicated.
create_reader().Reader<<DataType>>Results: A duplicate list such that "all(this is result)" equals true.
Returns a reader that can be used to read() this data one
element at a time.
discard( Int32 first_index, [Int32 last_index] )
Removes the elements in the specified range. Does not return
the list of removed elements like remove() does. If only
the 'first' parameter is given, elements from 'first' to the
end of the list are discarded.
discard( Range<<Int32>> range )'first' and 'last' are clipped to be a valid range.
Removes elements in the specified range.
end( Int32 from_end ).DataTypeRequires: range.is_contiguous_ascending
Equivalent to get( (count-1) + from_end ).
ensure_capacity( Int32 min_capacity )For example, end(0) is equivalent to last() and end(-1) is equivalent to get(count-2).
Effects that this list has a capacity of at least
'min_capacity'. If it has a lower capacity, the backing
array is reallocated to have the necessary capacity.
equals( Readable<<DataType>> other ).Boolean
Returns true if each element of this data equals() each
corresponding element from in 'other'.
equals( Object other ).Boolean
Returns true if this object is equivalant to another.
equals( DataType value ).Boolean[]The compiler converts 'obj1 == obj2' into 'obj1.equals(obj2)' and 'obj1 != obj2' into 'not obj1.equals(obj2)'. Implementations of equals() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract: if (obj1.equals(obj2)) obj1.compare_to(obj2) == eq obj1.hash_code == obj2.hash_code else obj1.compare_to(obj2) != eq endIfNote that two "equal" objects *must* have the same hash code, but "unequal" objects may or may not have the same hash code. This default implementation returns true if the this object and the 'other' reference are the same object ('this is other').
Returns a list of Boolean values where each value true if
the corresponding element of this indexed data equals()
the given value.
expand_to_capacity().ArrayList<<DataType>>
Effectively adds enough null/zero values to this arraylist so
that the count matches the capacity. Technically the backing
array is maintained with null/zero values and so a counter
is adjusted.
first().DataTypeReturns: A reference to this list for call chaining.Invariant: count == capacity
Returns the first element of this data. This convenience
method is equivalent to get(0).
format( String str_format, [String repeater_chars] ).String
Easier convenience method to accomplish to_String(prefix,prepeat,suffix).
format( String prefix, String prepeat, String suffix ).StringBreaks down a simple format like this:
{$[ or $]}
Into a prefix="{", prepeat=" or ", suffix="}".
Normally "[]" brackets are used to denote the repeater portion, but this may be specified otherwise. Example: local Int32[] nums = 11..15 println( nums.to_String( "[$:+$:]", ":" ) # prints: [11+12+13+14+15]
Converts this list into a string using the following format:
from( Int32 starting_index ).Reader<<DataType>>prefix + $0 + [prepeat + $N]* + suffixwhere "$0" is the first element and $N is every other element. Example:
local Int32[] nums = 11..15
println( nums.to_String("[", "+", "]") )
# prints: [11+12+13+14+15]
Returns a reader that can be used to read() this data one
element at a time with the given 'starting_index'.
from( Range<<Int32>> range ).Reader<<DataType>>
Returns a reader that can be used to read() this data one
element at a time from the given starting index up to and
including the ending index.
get( Readable<<Int32>> indices ).DataType[]
Gets the element at each of the given zero-based 'indices'.
get( Readable<<Boolean>> flags ).DataType[]Example:
local Int32[] nums = {1..5}
nums[{0,4}] = nums[{4,0}]
println( nums )
#prints: {5,2,3,4,1}
Returns a new list containing the subset of elements
of which each of the corresponding 'flags' is true.
get( Int32 index ).DataTypeExample:
local Int32[] nums = {1..10}
println( nums[nums % 2 == 0] )
#prints: {2,4,6,8,10}
Returns the element at the given zero-based index.
hash_code().Int32Requires: 0 <= index and index < count
Returns the hash code of this object, which some classes
(like HashTable) rely on. This default implementation
throws an UnsupportedMethodError.
index_of( DataType value, [Int32 starting_index] ).Int32Hash codes are used to quickly test and see if two complex objects are NOT equal. The value returned has no intrinsic meaning, but should conform to the following rules: 1. Two objects that are equivalent should produce the same hash code. 2. If an object's state doesn't change, its hash code shouldn't change either. Internally, this precludes the hash code being based on an object's memory address since Slag doesn't guarantee that an object's address won't change over time. This has the following implications: If you override hash_code you should also override equals() and possibly compare_to() and ensure the following contract. Invariant:
if (obj1.hash_code != obj2.hash_code)
obj1.equals(obj2) == false
obj1.compare_to(obj2) != eq
endIf
Returns the first index that the given value occurs at
starting at index 0 by default. (-1) is returned if
'value' is not found.
indices().Range<<Int32>>
Returns this data's range of indices (0..count-1).
init()
Creates an empty arraylist of capacity 10.
init( Int32 initial_capacity )
Creates an empty arraylist with a specified initial capacity.
init( Readable<<DataType>> readable )
Initializes this list to contain all the items from the
'readable' data source.
init( Int32 initial_capacity, DataType content )
Creates an array list full of 'initial_capacity' duplicates of
the given 'content'.
insert( IndexedData<<DataType>> seq, [Int32 before_index] ).ArrayList<<DataType>>
Inserts all the given values in front of 'before_index'. Elements
at 'begin_index' and higher are shifted over by one.
insert( DataType value, [Int32 before_index] ).ArrayList<<DataType>>Returns: A reference to this list for call chaining.Requires: 0 <= before_index and before_index <= countInvariant: this[before_index] = value this[before_index+seq.count] = old[before_index] count = old.count + seq.count
Inserts the 'value' in front of 'before_index'. Elements
at 'begin_index' and higher are shifted over by one.
is_empty().BooleanReturns: A reference to this list for call chaining.Requires: 0 <= before_index and before_index <= countInvariant: this[before_index] = value this[before_index+1] = old[before_index] count = old.count + 1
Returns true if count == 0.
is_not_empty().Boolean
Returns true if count > 0.
last().DataType
Returns the last element of this data. This convenience
method is equivalent to get(count-1).
last_index_of( DataType value, [Int32 starting_index] ).Int32
Returns the last index that the given value occurs at
starting at index (count-1) by default. (-1) is
returned if 'value' is not found.
modification_count().Int32
Returns a counter representing the number of times items
has been added to or removed. Used by readers to detect
concurrent list modification errors. For example, when an inner
method removes an item from a list the modification counter
is incremented. An outer "forEach" loop will detect that the
count is different from its original value and throw a
ConcurrentListModification error.
random().DataType
Returns an element of this data at random.
remove( DataType value ).Boolean
Calls remove_value(value). Only available for non-numerical
lists - see note in remove_value().
remove( Int32 index ).DataType
Removes and returns the element at position 'index'. All
elements higher than 'index' are shifted down by one spot
and the list count is decremented.
remove( Int32 first_index, Int32 last_index ).DataType[]Returns: old[index]Requires: 0 <= index and index < countInvariant: new[index] = old[index+1]
Removes and returns the elements in the specified range.
remove( Range<<Int32>> range ).DataType[]'first' and 'last' are clipped to be a valid range. Returns: The list of elements from old[first] through old[last].
Removes and returns the elements in the specified range.
See discard() for a variant that's optimal when you don't
need the return value.
remove_first().DataTypeRequires: range.is_contiguous_ascending
Equivalent to:
remove_last().DataTypelist.remove(0)
Equivalent to:
remove_value( DataType value ).Booleanlist.remove(list.count-1)
Removes the first occurrence of 'value' from the list.
reverse()Returns: "true" if an occurrence of 'value' was found and removed, or "false" if it was not found.Technical note: this method can't be named remove() because in an Int32[] list, remove(index) and remove(value) would have the same signature.
Reverses the order of the elements in this data.
reverse_indices().Range<<Int32>>
Returns this data's range of indices reversed (count-1 downTo 0).
reverse_order().Reader<<DataType>>Example:
local Int32[] nums = {5..7}
forEach (i in nums.reverse_indices) println( i )
#prints: 2 | 1 | 0
Returns a reader that can be used to read() this data one
element at a time from the last element (N-1) to the first (0).
reversed().IndexedData<<DataType>>
Returns an list containing the elements of this data
in reverse order.
set( Readable<<Int32>> indices, DataType value )
Sets the element at each of the given 'indices' to the given
'value'.
set( Readable<<Boolean>> flags, DataType value )Example:
local Int32[] nums = {1..5}
nums[{0,4}] = nums[{4,0}]
println( nums )
#prints: {5,2,3,4,1}
Starting at index 0, sets each element to the given 'value'
if the corresponding 'element_flags' are true.
set( Int32 index, DataType value )Example:
local Int32[] nums = {1..5}
nums[nums%2==1] = 0
println( nums ) #prints: {0,2,0,4,0}
Sets the element at the given zero-based index.
set( Readable<<Int32>> indices, Readable<<DataType>> values )Requires: 0 <= index and index < count
Sets the element at each of the given 'indices' to each of
the corresponding 'values'.
set( Readable<<Boolean>> element_flags, Readable<<DataType>> values )Requires: The number of indices == the number of values.Example:
local Int32[] nums = {1..5}
nums[0..4 step 2] = {7,8,9}
println( nums )
#prints: {7,2,8,4,9}
Starting at index 0, sets each element to the next of the
given 'values' if the corresponding 'element_flags' are true.
shuffle()Example:
local Int32[] nums = {1..5}
nums[nums%2==1] = -nums
println( nums ) #prints: {-1,2,-3,4,-5}
Swaps every element of this data with another element at a
randomly-chosen position.
shuffled().IndexedData<<DataType>>
Returns a shuffled copy of this data.
sort( [SORT order] )
Sorts this list in place using a HeapSort.
'order' is SORT.ascending by default.
sorted( [SORT order] ).List<<String>>Only implemented for numerical and String lists. To enable it for lists of other types (say, Event), add this augment:
augment List<<Event>>
METHODS
method sort( SORT order=SORT.ascending ):
HeapSort<<DataType>>.sort( this, order )
endAugment
Returns an list containing the elements of this data
sorted into order. Only implemented for numerical and
String lists.
subset( Int32 first_index, Int32 last_index ).ArrayList<<DataType>>
Returns the subset of this data between indices
[first_index,last_index] inclusive.
swap( Int32 index_a, Int32 index_b )
Swaps the value at 'index_a' with the one at 'index_b'.
to_List().DataType[]Requires: 0 <= index_a < count 0 <= index_b < countInvariant: this[index_a] = old[index_b] this[index_b] = old[index_a]
Satisifies the ListAdaptable aspect of the IndexedData aspect
by returning this list with no modifications.
to_String().String
Returns a string representation of this data.
trim_to_count().ArrayList<<DataType>>
Resizes the backing array to exactly fit the values currently
stored in this list. Only recommended when memory usage is
a concern and you won't be adding additional elements in the
near future.
type_name().StringReturns: A reference to this list for call chaining.Invariant: capacity == count
Returns the true class name of this object. Implemented by
the runtime; you should not override this method.
Example: local Object obj = "Hello World" println( obj.type_name ) #prints: String |
Placeholder class that provides a common base type for all Array<<DataType>> classes.
| Class Methods |
|---|
|
create_duplicate( Object existing ).Object
This factory method initiates object duplication. The
compiler transforms the duplicate(obj) command into
Object.create_duplicate(obj).
Returns: 'null' if 'existing' is null. existing.create_duplicate otherwise |
| Object Methods |
|---|
|
clear( Int32 first_index, Int32 last_index )
Clears all the elements in this array between the two indices.
compare_to( Object other ).TernaryUsing this method to clear elements at the end of an arraylist allows the runtime to limit the number of reference array elements it searches through during a data collection. Technical note: the runtime tracks the furthest position that a non-null reference array element could possibly be at after various calls to clear() and set().
This method is used for ordering (quantitative) comparisons
between this object and another.
copy_elements( ArrayType src_array, Int32 src_index, Int32 dest_index, Int32 number )Returns 'eq' if they're equivalent, 'lt' if this object is "less than" the other, or 'gt' if this object is "greater than" another. The compiler converts: 'obj1 < obj2' -> 'obj1.compare_to(obj2) == lt' 'obj1 > obj2' -> 'obj1.compare_to(obj2) == gt' 'obj1 <= obj2' -> 'obj1.compare_to(obj2) != gt' 'obj1 >= obj2' -> 'obj1.compare_to(obj2) != lt'Implementations of compare_to() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract:
if (obj1.compare_to(obj2) == eq)
obj1.equals(obj2) == true
obj1.hash_code == obj2.hash_code
else
obj1.equals(obj2) == false
endIf
Note that two "equal" objects *must* have the same hash code,
but "unequal" objects may or may not have the same hash code.
This default implementation throws an UnsupportedMethodError.
Copies 'number' elements from another array (starting at
element 'src_index') into this one (starting at element
'dest_index').
count().Int32Elements may be copied within overlapping regions of the same array.
Returns the count of how many elements are in this array.
create_duplicate().Object
Should create a duplicate of this object such that
obj1.equals(obj1.create_duplicate) return true.
equals( Object other ).BooleanThe command duplicate(obj) is transformed by the compiler into Object.create_duplicate(obj), which then calls this method. For optimal performance (by removing an internal typecast in most situations), have your overridden create_duplicate have the same return type as the class it's defined in. For instance, Strings implementation is 'create_duplicate.String'. This default implementation throws an UnsupportedMethodError.
Returns true if this object is equivalant to another.
hash_code().Int32The compiler converts 'obj1 == obj2' into 'obj1.equals(obj2)' and 'obj1 != obj2' into 'not obj1.equals(obj2)'. Implementations of equals() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract: if (obj1.equals(obj2)) obj1.compare_to(obj2) == eq obj1.hash_code == obj2.hash_code else obj1.compare_to(obj2) != eq endIfNote that two "equal" objects *must* have the same hash code, but "unequal" objects may or may not have the same hash code. This default implementation returns true if the this object and the 'other' reference are the same object ('this is other').
Returns the hash code of this object, which some classes
(like HashTable) rely on. This default implementation
throws an UnsupportedMethodError.
to_String().StringHash codes are used to quickly test and see if two complex objects are NOT equal. The value returned has no intrinsic meaning, but should conform to the following rules: 1. Two objects that are equivalent should produce the same hash code. 2. If an object's state doesn't change, its hash code shouldn't change either. Internally, this precludes the hash code being based on an object's memory address since Slag doesn't guarantee that an object's address won't change over time. This has the following implications: If you override hash_code you should also override equals() and possibly compare_to() and ensure the following contract. Invariant:
if (obj1.hash_code != obj2.hash_code)
obj1.equals(obj2) == false
obj1.compare_to(obj2) != eq
endIf
Returns:
type_name().StringA String representation of this object. Most classes should override this method to summarize an object's state for convenience in testing and debugging.
Returns the true class name of this object. Implemented by
the runtime; you should not override this method.
Example: local Object obj = "Hello World" println( obj.type_name ) #prints: String |
Internal use.
| Class Methods |
|---|
|
create_duplicate( Object existing ).Object
This factory method initiates object duplication. The
compiler transforms the duplicate(obj) command into
Object.create_duplicate(obj).
Returns: 'null' if 'existing' is null. existing.create_duplicate otherwise |
| Object Variables |
|---|
|
next : PatternMatcher tag_group_index : Int32 |
| Object Methods |
|---|
|
chain_next( PatternMatcher _next ) compare_to( Object other ).Ternary
This method is used for ordering (quantitative) comparisons
between this object and another.
create_duplicate().ObjectReturns 'eq' if they're equivalent, 'lt' if this object is "less than" the other, or 'gt' if this object is "greater than" another. The compiler converts: 'obj1 < obj2' -> 'obj1.compare_to(obj2) == lt' 'obj1 > obj2' -> 'obj1.compare_to(obj2) == gt' 'obj1 <= obj2' -> 'obj1.compare_to(obj2) != gt' 'obj1 >= obj2' -> 'obj1.compare_to(obj2) != lt'Implementations of compare_to() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract:
if (obj1.compare_to(obj2) == eq)
obj1.equals(obj2) == true
obj1.hash_code == obj2.hash_code
else
obj1.equals(obj2) == false
endIf
Note that two "equal" objects *must* have the same hash code,
but "unequal" objects may or may not have the same hash code.
This default implementation throws an UnsupportedMethodError.
Should create a duplicate of this object such that
obj1.equals(obj1.create_duplicate) return true.
equals( Object other ).BooleanThe command duplicate(obj) is transformed by the compiler into Object.create_duplicate(obj), which then calls this method. For optimal performance (by removing an internal typecast in most situations), have your overridden create_duplicate have the same return type as the class it's defined in. For instance, Strings implementation is 'create_duplicate.String'. This default implementation throws an UnsupportedMethodError.
Returns true if this object is equivalant to another.
hash_code().Int32The compiler converts 'obj1 == obj2' into 'obj1.equals(obj2)' and 'obj1 != obj2' into 'not obj1.equals(obj2)'. Implementations of equals() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract: if (obj1.equals(obj2)) obj1.compare_to(obj2) == eq obj1.hash_code == obj2.hash_code else obj1.compare_to(obj2) != eq endIfNote that two "equal" objects *must* have the same hash code, but "unequal" objects may or may not have the same hash code. This default implementation returns true if the this object and the 'other' reference are the same object ('this is other').
Returns the hash code of this object, which some classes
(like HashTable) rely on. This default implementation
throws an UnsupportedMethodError.
init( Int32 tag_group_index )Hash codes are used to quickly test and see if two complex objects are NOT equal. The value returned has no intrinsic meaning, but should conform to the following rules: 1. Two objects that are equivalent should produce the same hash code. 2. If an object's state doesn't change, its hash code shouldn't change either. Internally, this precludes the hash code being based on an object's memory address since Slag doesn't guarantee that an object's address won't change over time. This has the following implications: If you override hash_code you should also override equals() and possibly compare_to() and ensure the following contract. Invariant:
if (obj1.hash_code != obj2.hash_code)
obj1.equals(obj2) == false
obj1.compare_to(obj2) != eq
endIf
match( PatternMatchInfo state ).Boolean match_next( PatternMatchInfo state ).Boolean matches_any().Boolean
Overridden in CharRangePatternMatcher
to_String().Stringtype_name().String
Returns the true class name of this object. Implemented by
the runtime; you should not override this method.
Example: local Object obj = "Hello World" println( obj.type_name ) #prints: String |
Allows integers of any size to be represented and manipulated. BigInt operations are significantly slower than operations on primitive Int32/Int64 types so BigInt objects should only be used when you require integers with more than 64 bits.
BigInt objects are immutable; operations produce new BigInteger objects as side effects instead of altering operands.
BigInt numbers are modeled using sign-magnitude; they are not 2's complement and the sign cannot be directly changed through a bitwise operation (only incidentally, as when a negative number is AND'd with zero to produce a zero result).
BigInt values are stored as a series of unsigned 16-bit Char values. Their total bit size (in multiples of 16) is only what's necessary to represent a number's magnitude; you cannot, for instance, specify that a number has "1000 zero bits".
Similar to Java's BigInteger class.
Examples:
println( BigInt(123456) ^ BigInt("1000101",2) )
println( "2^100 = $" (BigInt(2) ^ 100) )
| Class Variables |
|---|
|
last_modulo : BigInt one : BigInt ten : BigInt ten_e144 : BigInt ten_e18 : BigInt ten_e36 : BigInt ten_e72 : BigInt values : BigInt[] zero : BigInt |
| Class Methods |
|---|
|
create_duplicate( Object existing ).Object
This factory method initiates object duplication. The
compiler transforms the duplicate(obj) command into
Object.create_duplicate(obj).
init_class()Returns: 'null' if 'existing' is null. existing.create_duplicate otherwise promote( Int64 n ).BigInt
Creates a BigInt object out of an Int64 value. If
'n' is 0..15 then a pre-defined BigInt object will
be returned instead.
|
| Object Variables |
|---|
|
data : ArrayList<<Char>> sign_flag : Int32 |
| Object Methods |
|---|
|
compare_to( Object other ).Ternary compare_to( Int64 n ).Ternary compare_to( BigInt other ).Ternary create_duplicate().Object
Should create a duplicate of this object such that
obj1.equals(obj1.create_duplicate) return true.
equals( Int64 n ).BooleanThe command duplicate(obj) is transformed by the compiler into Object.create_duplicate(obj), which then calls this method. For optimal performance (by removing an internal typecast in most situations), have your overridden create_duplicate have the same return type as the class it's defined in. For instance, Strings implementation is 'create_duplicate.String'. This default implementation throws an UnsupportedMethodError. equals( Object other ).Boolean equals( BigInt other ).Boolean hash_code().Int32
Returns the hash code of this object, which some classes
(like HashTable) rely on. This default implementation
throws an UnsupportedMethodError.
init()Hash codes are used to quickly test and see if two complex objects are NOT equal. The value returned has no intrinsic meaning, but should conform to the following rules: 1. Two objects that are equivalent should produce the same hash code. 2. If an object's state doesn't change, its hash code shouldn't change either. Internally, this precludes the hash code being based on an object's memory address since Slag doesn't guarantee that an object's address won't change over time. This has the following implications: If you override hash_code you should also override equals() and possibly compare_to() and ensure the following contract. Invariant:
if (obj1.hash_code != obj2.hash_code)
obj1.equals(obj2) == false
obj1.compare_to(obj2) != eq
endIf
init( BigInt other ) init( Int32 value ) init( Int64 value ) init( String value, [Int32 base] )
Initializes this BigInt to a value specified as a string
of digits in a given base. 'base' can be 2, 10, or 16.
internal_to_Int64().Int64is_negative().Boolean is_valid_Int32().Boolean is_valid_Int64().Boolean is_zero().Boolean left_shifted( Int32 bits ).BigInt normalized().BigInt
Removes excess zero values on the most signficant end
and changes a negative zero to a positive zero.
op%( BigInt n ).BigIntop%( Int64 n ).BigInt op&( BigInt n ).BigInt op&( Int64 n ).BigInt op*( Int64 n ).BigInt op*( BigInt n ).BigInt op+( Int64 n ).BigInt op+( BigInt n ).BigInt op-( Int64 n ).BigInt op-().BigInt op-( BigInt n ).BigInt op/( Int64 n ).BigInt op/( BigInt n ).BigInt op^( BigInt n ).BigInt op^( Int64 n ).BigInt op|( BigInt n ).BigInt op|( Int64 n ).BigInt op~( BigInt n ).BigInt op~( Int64 n ).BigInt right_shifted( Int32 bits ).BigInt sign().Int32
Returns -1, 0, or 1.
to_Int32().Int32to_Int64().Int64 to_String( Int32 base ).String to_String().String type_name().String
Returns the true class name of this object. Implemented by
the runtime; you should not override this method.
Example: local Object obj = "Hello World" println( obj.type_name ) #prints: String |
Incorporate this aspect into enumerated types associated with Int32 values that define bit flags.
For example:
enum DIRECTION : BitFlags<<DIRECTION>>
CATEGORIES
north(1), east(2), south(4), west(8)
endEnum
...
local DIRECTION d = DIRECTION.north | DIRECTION.east
println( d == DIRECTION.north ) #prints: false
println( d.includes(DIRECTION.north) ) #prints: true
println( d ) #prints: north,east
println( d.flags ) #prints: 3
d &= !DIRECTION.north
println( d ) #prints: east
println( d == DIRECTION.east ) #prints: true
println( d.flags ) #prints: 2
| Class Variables |
|---|
|
default_next_flag : Int32 |
| Class Methods |
|---|
|
create_duplicate( Object existing ).Object
This factory method initiates object duplication. The
compiler transforms the duplicate(obj) command into
Object.create_duplicate(obj).
Returns: 'null' if 'existing' is null. existing.create_duplicate otherwise |
| Object Variables |
|---|
|
flags : Int32 |
| Object Methods |
|---|
|
compare_to( Object other ).Ternary
This method is used for ordering (quantitative) comparisons
between this object and another.
create_duplicate().ObjectReturns 'eq' if they're equivalent, 'lt' if this object is "less than" the other, or 'gt' if this object is "greater than" another. The compiler converts: 'obj1 < obj2' -> 'obj1.compare_to(obj2) == lt' 'obj1 > obj2' -> 'obj1.compare_to(obj2) == gt' 'obj1 <= obj2' -> 'obj1.compare_to(obj2) != gt' 'obj1 >= obj2' -> 'obj1.compare_to(obj2) != lt'Implementations of compare_to() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract:
if (obj1.compare_to(obj2) == eq)
obj1.equals(obj2) == true
obj1.hash_code == obj2.hash_code
else
obj1.equals(obj2) == false
endIf
Note that two "equal" objects *must* have the same hash code,
but "unequal" objects may or may not have the same hash code.
This default implementation throws an UnsupportedMethodError.
Should create a duplicate of this object such that
obj1.equals(obj1.create_duplicate) return true.
equals( Object other ).BooleanThe command duplicate(obj) is transformed by the compiler into Object.create_duplicate(obj), which then calls this method. For optimal performance (by removing an internal typecast in most situations), have your overridden create_duplicate have the same return type as the class it's defined in. For instance, Strings implementation is 'create_duplicate.String'. This default implementation throws an UnsupportedMethodError. equals( Int32 other_flags ).Boolean equals( EnumType other ).Boolean hash_code().Int32
Returns the hash code of this object, which some classes
(like HashTable) rely on. This default implementation
throws an UnsupportedMethodError.
includes( EnumType other ).BooleanHash codes are used to quickly test and see if two complex objects are NOT equal. The value returned has no intrinsic meaning, but should conform to the following rules: 1. Two objects that are equivalent should produce the same hash code. 2. If an object's state doesn't change, its hash code shouldn't change either. Internally, this precludes the hash code being based on an object's memory address since Slag doesn't guarantee that an object's address won't change over time. This has the following implications: If you override hash_code you should also override equals() and possibly compare_to() and ensure the following contract. Invariant:
if (obj1.hash_code != obj2.hash_code)
obj1.equals(obj2) == false
obj1.compare_to(obj2) != eq
endIf
Returns "true" if this category contains any of the
bitflags from the 'other' category.
includes( Int32 other_flags ).Boolean
Returns "true" if this category contains any of the
bitflags from 'other_flags'.
init()init( Int32 flags ) init( EnumType existing ) op!().EnumType
Returns a new category that contains the inverse
of this category's bitflags.
op&( Int32 other_flags ).EnumType
Returns a new category that contains the intersection
of bitflags from this category and 'other_flags'.
op&( EnumType other ).EnumType
Returns a new category that contains the intersection
of bitflags from this category and the 'other' category.
op|( Int32 other_flags ).EnumType
Returns a new category that includes all the bitflags
from this category and 'other_flags'.
op|( EnumType other ).EnumType
Returns a new category that includes all the bitflags
from this category and the 'other' category.
to_String().String
Returns a string containing the names of all comma-separated
categories included in this category's bitflags.
type_name().String
Returns the true class name of this object. Implemented by
the runtime; you should not override this method.
Example: local Object obj = "Hello World" println( obj.type_name ) #prints: String |
A BitReader wraps an existing Reader<<Char>> and is able to read in 1-bit to 32-bit values at a time under normal operations. There are special method variants capable of reading in 64-bit values.
| Class Methods |
|---|
|
create_duplicate( Object existing ).Object
This factory method initiates object duplication. The
compiler transforms the duplicate(obj) command into
Object.create_duplicate(obj).
Returns: 'null' if 'existing' is null. existing.create_duplicate otherwise |
| Object Variables |
|---|
|
bit_buffer : Int64
Internal use.
bit_count : Int32
Internal use.
src : Reader<<Char>>
The backing source of characters.
|
| Object Methods |
|---|
|
available().Int32
Returns the minimum number of additional values that can be
immediately read from this reader.
close()If the reader is exhausted or if it must block to peek or read next then the result will be 0. It is important to note that '0' does not necessarily mean the reader is exhausted. Many readers will report that they have 1 available even if there are thousands of values waiting to be read. The 'available' property should be used as an aide for buffer sizes and the like but should not be taken as an absolute size.
Closes this reader as a source of input. Useful for file
readers, but for most others this command does nothing.
compare_to( Object other ).Ternary
This method is used for ordering (quantitative) comparisons
between this object and another.
consume( DataType look_for ).BooleanReturns 'eq' if they're equivalent, 'lt' if this object is "less than" the other, or 'gt' if this object is "greater than" another. The compiler converts: 'obj1 < obj2' -> 'obj1.compare_to(obj2) == lt' 'obj1 > obj2' -> 'obj1.compare_to(obj2) == gt' 'obj1 <= obj2' -> 'obj1.compare_to(obj2) != gt' 'obj1 >= obj2' -> 'obj1.compare_to(obj2) != lt'Implementations of compare_to() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract:
if (obj1.compare_to(obj2) == eq)
obj1.equals(obj2) == true
obj1.hash_code == obj2.hash_code
else
obj1.equals(obj2) == false
endIf
Note that two "equal" objects *must* have the same hash code,
but "unequal" objects may or may not have the same hash code.
This default implementation throws an UnsupportedMethodError.
Attempts to match and discard the next value from this
reader, returning true, or else leaves the next value still
pending and returns false.
create_duplicate().ObjectReturns: "true" if old.peek == look_for "false" if old.peek != look_forInvariant: if (old.peek == look_for) old.skip
Should create a duplicate of this object such that
obj1.equals(obj1.create_duplicate) return true.
equals( Object other ).BooleanThe command duplicate(obj) is transformed by the compiler into Object.create_duplicate(obj), which then calls this method. For optimal performance (by removing an internal typecast in most situations), have your overridden create_duplicate have the same return type as the class it's defined in. For instance, Strings implementation is 'create_duplicate.String'. This default implementation throws an UnsupportedMethodError.
Returns true if this object is equivalant to another.
fill_buffer( Int32 to_n_bits )The compiler converts 'obj1 == obj2' into 'obj1.equals(obj2)' and 'obj1 != obj2' into 'not obj1.equals(obj2)'. Implementations of equals() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract: if (obj1.equals(obj2)) obj1.compare_to(obj2) == eq obj1.hash_code == obj2.hash_code else obj1.compare_to(obj2) != eq endIfNote that two "equal" objects *must* have the same hash code, but "unequal" objects may or may not have the same hash code. This default implementation returns true if the this object and the 'other' reference are the same object ('this is other').
Internal use.
has_another().Boolean
Returns true if there are at least 8 bits left to read.
has_another( Int32 n_bits ).BooleanSee also: has_another(Int32)
Returns true if there are at least 'n_bits' left to read. 'n_bits'
must be 1..32.
hash_code().Int32
Returns the hash code of this object, which some classes
(like HashTable) rely on. This default implementation
throws an UnsupportedMethodError.
init( Reader<<Char>> src )Hash codes are used to quickly test and see if two complex objects are NOT equal. The value returned has no intrinsic meaning, but should conform to the following rules: 1. Two objects that are equivalent should produce the same hash code. 2. If an object's state doesn't change, its hash code shouldn't change either. Internally, this precludes the hash code being based on an object's memory address since Slag doesn't guarantee that an object's address won't change over time. This has the following implications: If you override hash_code you should also override equals() and possibly compare_to() and ensure the following contract. Invariant:
if (obj1.hash_code != obj2.hash_code)
obj1.equals(obj2) == false
obj1.compare_to(obj2) != eq
endIf
Initializes this BitReader to read from the given character
reader.
init( Readable<<Char>> readable )
Initializes this BitReader to read from the given readable
character data.
is_exhausted().Boolean
Returns "true" if this reader does not have another value
or "false" if it does.
peek( Int32 n_bits ).Int32
Returns the next 'n_bits' value that will be returned by
read(n_bits).
peek().Char
Returns the next 8-bit value that will be returned by read().
peek_bit().Int32
Returns the bit of input that will be returned by read_bit.
position( Int32 new_position )
This optional property-write sets the zero-based read position
of this reader. When a reader is first created position()
returns 0. After a single read() it returns 1, and so on.
Readers that don't implement this property will throw an
UnsupportedMethodError when it's accessed.
position().Int32
This optional property-read returns the zero-based read
position of this reader. When a reader is first created
position() returns 0. After a single read() it returns 1,
and so on.
read( Int32 n_bits ).Int32Readers that don't implement this property will throw an UnsupportedMethodError when it's accessed.
Returns the next value of size 'n_bits', giving a value
between 0 and n_bits-1.
read().CharExample:
...
if (bits.peek == 0b01011000)
println( bits.read(3) ) # prints "2" (010)
println( bits.read(2) ) # prints "3" (11)
println( bits.read(3) ) # prints "0" (000)
endIf
Returns the next 8 bits as a Char.
read_Int64().Int64
Returns the next 64 bits as an Int64 assumed to be in
high-low byte order.
read_Int64_low_high().Int64
Returns the next 64 bits as an Int64 assumed to be in
low-high byte order.
read_bit().Int32
Returns the next bit of input.
read_line().String
Reads and returns the next line of characters up to the next
LF or CRLF. The CRLF characters are not part of
the return value and are discarded.
read_list( Int32 size ).DataType[]Only defined for Reader<<Char>>.
Reads the next 'size' number of values and returns them in a
list. Requires that there are at least 'size' number of
values remaining to be read.
read_low_high( Int32 n_bits ).Int32
Returns the next n_bits as a value. n_bits must be 16 or 32
bits. This method assumes that the first 8 bits to be read
are the least significant byte of the answer (bits 7:1) and
the last 8 bits are the most significant byte of the number
(e.g. bits 31:24).
remaining().Int32Requires: n_bits == 16 or n_bits == 32
This optional property returns how many values remain to be
read before the reader is exhausted. Not all readers
can implement this property; those that don't will throw
an UnsupportedMethodError when it's accessed.
rewind()
This optional method resets this reader so that the next
read() will return the first value of the series.
Readers that don't implement this property will throw an
UnsupportedMethodError when it's accessed.
skip( [Int32 skip_count] )
Discards exactly the next 'skip_count' number of values
rather than reading them. If there are not enough values
remaining then a NoNextValueError will be thrown from read().
to_List().DataType[]This program fragment: local var a = reader.read reader.read reader.read local var b = reader.readis equivalent to this: local var a = reader.read reader.skip(2) local var b = reader.read
Creates and returns a list of all the remaining values of
this reader.
to_String().String
Returns a string representation of this reader's values.
type_name().String
Returns the true class name of this object. Implemented by
the runtime; you should not override this method.
Example: local Object obj = "Hello World" println( obj.type_name ) #prints: String |
A BitWriter wraps an existing Writer<<Char>> and allows arbitrarily-sized values of 1-32 bits to be written. 64-bit values may also be written using a separate call.
The bits are buffered and groups of 8 at a time (single bytes) are written to the backing Char writer.
| Class Methods |
|---|
|
create_duplicate( Object existing ).Object
This factory method initiates object duplication. The
compiler transforms the duplicate(obj) command into
Object.create_duplicate(obj).
Returns: 'null' if 'existing' is null. existing.create_duplicate otherwise |
| Object Variables |
|---|
|
bit_buffer : Int64
Internal use.
bit_count : Int32
Internal use.
dest : Writer<<Char>>
The backing character writer that a BitWriter outputs to.
|
| Object Methods |
|---|
|
capacity().Int32
Returns the minimum number of additional values that can
written with this writer, or (-1) for "unlimited".
clean_up()
Closes the writer. Base aspect Writer does not incorporate
the RequiresCleanup interface, but types for writers that do
this method will be called when there are no more references
to the object.
close()
Flushes and closes this BitWriter.
compare_to( Object other ).Ternary
This method is used for ordering (quantitative) comparisons
between this object and another.
create_duplicate().ObjectReturns 'eq' if they're equivalent, 'lt' if this object is "less than" the other, or 'gt' if this object is "greater than" another. The compiler converts: 'obj1 < obj2' -> 'obj1.compare_to(obj2) == lt' 'obj1 > obj2' -> 'obj1.compare_to(obj2) == gt' 'obj1 <= obj2' -> 'obj1.compare_to(obj2) != gt' 'obj1 >= obj2' -> 'obj1.compare_to(obj2) != lt'Implementations of compare_to() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract:
if (obj1.compare_to(obj2) == eq)
obj1.equals(obj2) == true
obj1.hash_code == obj2.hash_code
else
obj1.equals(obj2) == false
endIf
Note that two "equal" objects *must* have the same hash code,
but "unequal" objects may or may not have the same hash code.
This default implementation throws an UnsupportedMethodError.
Should create a duplicate of this object such that
obj1.equals(obj1.create_duplicate) return true.
equals( Object other ).BooleanThe command duplicate(obj) is transformed by the compiler into Object.create_duplicate(obj), which then calls this method. For optimal performance (by removing an internal typecast in most situations), have your overridden create_duplicate have the same return type as the class it's defined in. For instance, Strings implementation is 'create_duplicate.String'. This default implementation throws an UnsupportedMethodError.
Returns true if this object is equivalant to another.
flush()The compiler converts 'obj1 == obj2' into 'obj1.equals(obj2)' and 'obj1 != obj2' into 'not obj1.equals(obj2)'. Implementations of equals() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract: if (obj1.equals(obj2)) obj1.compare_to(obj2) == eq obj1.hash_code == obj2.hash_code else obj1.compare_to(obj2) != eq endIfNote that two "equal" objects *must* have the same hash code, but "unequal" objects may or may not have the same hash code. This default implementation returns true if the this object and the 'other' reference are the same object ('this is other').
If there are any buffered bits that haven't been written
to the backing writer yet, flush() writes out enough zero
bits to make eight total and writes the resulting byte
of information.
hash_code().Int32
Returns the hash code of this object, which some classes
(like HashTable) rely on. This default implementation
throws an UnsupportedMethodError.
holds_has_another().BooleanHash codes are used to quickly test and see if two complex objects are NOT equal. The value returned has no intrinsic meaning, but should conform to the following rules: 1. Two objects that are equivalent should produce the same hash code. 2. If an object's state doesn't change, its hash code shouldn't change either. Internally, this precludes the hash code being based on an object's memory address since Slag doesn't guarantee that an object's address won't change over time. This has the following implications: If you override hash_code you should also override equals() and possibly compare_to() and ensure the following contract. Invariant:
if (obj1.hash_code != obj2.hash_code)
obj1.equals(obj2) == false
obj1.compare_to(obj2) != eq
endIf
Returns true if at least one more value can be written with
write().
init( Writer<<Char>> dest )
Initializes this BitWriter to output to the given writer.
init( Writable<<Char>> writable )
Initializes this BitWriter to output to the given writable
object.
position( Int32 new_pos )
This optional property-write sets the zero-based write
position. It is up to the implementation to define how
repositioning works with gaps and what happens to data at a
later spot after a reposition to an earlier spot.
position().Int32Not all writers implement this property; those that don't will throw an UnsupportedMethodError when it's accessed.
This optional property-read returns the zero-based write
position. This will be "0" before anything is written, "1"
after a single write(), and so on.
skip( Int32 skip_count )Not all writers implement this property; those that don't will throw an UnsupportedMethodError when it's accessed.
This optional method repositions the writer to be
'skip_count' values further along.
to_String().StringIf a writer does not implement the 'position' property then an UnsupportedMethodError will be generated when skip() is called.
Returns:
type_name().StringA String representation of this object. Most classes should override this method to summarize an object's state for convenience in testing and debugging.
Returns the true class name of this object. Implemented by
the runtime; you should not override this method.
write( DataType value )Example: local Object obj = "Hello World" println( obj.type_name ) #prints: String
Outputs 'value' in an implementation-specific way.
write( Int32 value, Int32 n_bits )Requires: holds_has_another == true
Writes 'value' in 'n_bits' using high-low byte order.
write( Char value )
Writes 'value' in 8 bits.
write_Int64( Int64 value )
Writes 'value' in 64 bits using high-low byte order.
write_Int64_low_high( Int64 value )
Writes 'value' in 64 bits using low-high byte order.
write_bit( Int32 b )
Writes 'b' (0 or 1) as a single bit.
write_low_high( Int32 value, Int32 n_bits )
Writes 'value' in 'n_bits' using low-high byte order.
'n_bits' must be 16 or 32. The least-significant byte
is written first and the most significant byte is written
last.
Requires: n_bits == 16 or n_bits == 32 |
Pixel data wrapper for examining and manipulating image data. Many native layer implementations load textures as Bitmap objects first and then convert them into hardware-accelerated Images.
| Class Methods |
|---|
|
create( String filename ).Bitmap
Creates a Bitmap containing the pixel data from the specified
file. Currently only png and jpg files are supported.
create_duplicate( Object existing ).Object
This factory method initiates object duplication. The
compiler transforms the duplicate(obj) command into
Object.create_duplicate(obj).
Returns: 'null' if 'existing' is null. existing.create_duplicate otherwise |
| Object Variables |
|---|
|
data : Array<<Color>>
Single-dimensional array of Color values. Values
data[0 ..< width] are the first row, data[width ..< width*2]
are the second row, and so on.
height : Int32
The height of this bitmap, in pixels.
width : Int32
The width of this bitmap, in pixels.
|
| Object Methods |
|---|
|
add_transparent_outline()
Adjusts this bitmap's data to include a 1-pixel transparent
black border on each edge.
clear( [Color color] )
Clears all the pixels of this bitmap to be the given color
or opaque black by default.
clear_channel( Color color, Int32 channel_mask )
Clears a certain channel of this bitmap to the given color.
column_transparent( Int32 x ).BooleanParameters:
color
The color to clear to. Only the bits of the AARRGGBB
'color' that correspond to the set bits in 'channel_mask'
are copied.
Returns "true" if column 'x' (where x is 0 ..< width)
contains completely transparent pixel values.
compare_to( Object other ).Ternary
This method is used for ordering (quantitative) comparisons
between this object and another.
create_duplicate().ObjectReturns 'eq' if they're equivalent, 'lt' if this object is "less than" the other, or 'gt' if this object is "greater than" another. The compiler converts: 'obj1 < obj2' -> 'obj1.compare_to(obj2) == lt' 'obj1 > obj2' -> 'obj1.compare_to(obj2) == gt' 'obj1 <= obj2' -> 'obj1.compare_to(obj2) != gt' 'obj1 >= obj2' -> 'obj1.compare_to(obj2) != lt'Implementations of compare_to() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract:
if (obj1.compare_to(obj2) == eq)
obj1.equals(obj2) == true
obj1.hash_code == obj2.hash_code
else
obj1.equals(obj2) == false
endIf
Note that two "equal" objects *must* have the same hash code,
but "unequal" objects may or may not have the same hash code.
This default implementation throws an UnsupportedMethodError.
Should create a duplicate of this object such that
obj1.equals(obj1.create_duplicate) return true.
draw( Int32 x, Int32 y )The command duplicate(obj) is transformed by the compiler into Object.create_duplicate(obj), which then calls this method. For optimal performance (by removing an internal typecast in most situations), have your overridden create_duplicate have the same return type as the class it's defined in. For instance, Strings implementation is 'create_duplicate.String'. This default implementation throws an UnsupportedMethodError.
For native layer debugging purposes. Performs a slow image
draw using a draw_point() call per pixel.
draw( Rect r, Color color, Boolean blend_alpha )
Draws the outline of the given rectangle in the given color,
optionally performing alpha-blending (default: true).
draw( Vector2 pos )
For native layer debugging purposes. See draw(Int32,Int32).
draw_channel_to( Bitmap dest, Int32 x, Int32 y, Int32 channel_mask )
Draws selected bits of this bitmap to the destination. No
alpha blending is performed.
draw_to( Bitmap dest, Vector2 pos, [Boolean blend_alpha] )Parameters:
dest
A bitmap to draw to. Edge clipping is performed.
Draws this bitmap to the given destination bitmap. This is
operation is performed in software and is not intended for
heavy per-frame use.
draw_to( Bitmap dest, Int32 x, Int32 y, [Boolean blend_alpha] )Parameters:
dest
A bitmap to draw to. Edge clipping is performed.
Draws this bitmap to the given destination bitmap. This is
operation is performed in software and is not intended for
heavy per-frame use.
equals( Object other ).BooleanParameters:
dest
A bitmap to draw to. Edge clipping is performed.
Returns true if this object is equivalant to another.
fill( Rect r, Color color, [Boolean blend_alpha] )The compiler converts 'obj1 == obj2' into 'obj1.equals(obj2)' and 'obj1 != obj2' into 'not obj1.equals(obj2)'. Implementations of equals() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract: if (obj1.equals(obj2)) obj1.compare_to(obj2) == eq obj1.hash_code == obj2.hash_code else obj1.compare_to(obj2) != eq endIfNote that two "equal" objects *must* have the same hash code, but "unequal" objects may or may not have the same hash code. This default implementation returns true if the this object and the 'other' reference are the same object ('this is other').
Fills the given rectangle with the given color, optionally
performing alpha-blending [default: false].
hash_code().Int32
Returns the hash code of this object, which some classes
(like HashTable) rely on. This default implementation
throws an UnsupportedMethodError.
init( Vector2 pixel_size )Hash codes are used to quickly test and see if two complex objects are NOT equal. The value returned has no intrinsic meaning, but should conform to the following rules: 1. Two objects that are equivalent should produce the same hash code. 2. If an object's state doesn't change, its hash code shouldn't change either. Internally, this precludes the hash code being based on an object's memory address since Slag doesn't guarantee that an object's address won't change over time. This has the following implications: If you override hash_code you should also override equals() and possibly compare_to() and ensure the following contract. Invariant:
if (obj1.hash_code != obj2.hash_code)
obj1.equals(obj2) == false
obj1.compare_to(obj2) != eq
endIf
Creates a transparent black bitmap of the given size.
init( Bitmap existing, Vector2 top_left, Vector2 new_size )
Creates a bitmap that's a given subset of an existing bitmap.
init( Bitmap existing, Rect rect )
Creates a bitmap that's a given subset of an existing bitmap.
init( Int32 width, Int32 height )
Creates a transparent black bitmap of the given width and
height.
init( Bitmap existing )
Creates a bitmap that's an exact duplicate of an existing bitmap.
init( String filename )
Creates a Bitmap containing image data from the given
png or jpeg file.
non_transparent_region().Rect
Returns a rectangle just large enough to enclose all pixels
that aren't completely transparent. If the area of the
resulting rectangle is zero then this bitmap is completely
transparent.
region().RectInvariant: result == intersection_of(old,result)
Returns the rectangular region occupied by this bitmap.
The 'position' of the resulting rectangle is (0,0).
row_transparent( Int32 y ).Boolean
Returns "true" if row 'y' (where y is 0 ..< height)
contains completely transparent pixel values.
set( Bitmap existing )
Sets this bitmap to reference the same data as another
existing bitmap. Note that the array of Color data is shared
rather than duplicated.
size().Vector2
Returns the two-dimensional size of this bitmap, in pixels.
split_into_tiles( Int32 tiles_wide, Int32 tiles_high ).Bitmap[]
Splits this Bitmap into an array of separate Bitmap tiles.
to_String().StringReturns a list of Bitmap objects where index 0 is the top-left tile, index[tiles_wide-1] is the top-right tile, and so on.
Returns:
type_name().StringA String representation of this object. Most classes should override this method to summarize an object's state for convenience in testing and debugging.
Returns the true class name of this object. Implemented by
the runtime; you should not override this method.
Example: local Object obj = "Hello World" println( obj.type_name ) #prints: String |
Wraps an existing Reader<<FromType>> and casts each value to ToType.
Example:
local Real64[] nums = { 3.0, 3.5, 3.9, 4.0 }
forEach (n in CastReader<<Real64,Int32>>(nums)) println(n)
# prints: 3 3 3 4
Example:
# Read "data.txt" into a byte buffer.
local Byte[] buffer = CastReader<<Char,Byte>>(File("data.txt").create_reader).to_List
| Class Methods |
|---|
|
create_duplicate( Object existing ).Object
This factory method initiates object duplication. The
compiler transforms the duplicate(obj) command into
Object.create_duplicate(obj).
Returns: 'null' if 'existing' is null. existing.create_duplicate otherwise |
| Object Variables |
|---|
|
has_next : Boolean
If "true" then 'next' is a valid value.
next : OutputDataType
The next data that will be returned by peek() or read().
src : Reader<<InputDataType>>
The backing source of values for this reader.
|
| Object Methods |
|---|
|
available().Int32
Returns the minimum number of additional values that can be
immediately read from this reader.
close()If the reader is exhausted or if it must block to peek or read next then the result will be 0. It is important to note that '0' does not necessarily mean the reader is exhausted. Many readers will report that they have 1 available even if there are thousands of values waiting to be read. The 'available' property should be used as an aide for buffer sizes and the like but should not be taken as an absolute size.
Closes this reader as a source of input. Useful for file
readers, but for most others this command does nothing.
compare_to( Object other ).Ternary
This method is used for ordering (quantitative) comparisons
between this object and another.
consume( DataType look_for ).BooleanReturns 'eq' if they're equivalent, 'lt' if this object is "less than" the other, or 'gt' if this object is "greater than" another. The compiler converts: 'obj1 < obj2' -> 'obj1.compare_to(obj2) == lt' 'obj1 > obj2' -> 'obj1.compare_to(obj2) == gt' 'obj1 <= obj2' -> 'obj1.compare_to(obj2) != gt' 'obj1 >= obj2' -> 'obj1.compare_to(obj2) != lt'Implementations of compare_to() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract:
if (obj1.compare_to(obj2) == eq)
obj1.equals(obj2) == true
obj1.hash_code == obj2.hash_code
else
obj1.equals(obj2) == false
endIf
Note that two "equal" objects *must* have the same hash code,
but "unequal" objects may or may not have the same hash code.
This default implementation throws an UnsupportedMethodError.
Attempts to match and discard the next value from this
reader, returning true, or else leaves the next value still
pending and returns false.
create_duplicate().ObjectReturns: "true" if old.peek == look_for "false" if old.peek != look_forInvariant: if (old.peek == look_for) old.skip
Should create a duplicate of this object such that
obj1.equals(obj1.create_duplicate) return true.
equals( Object other ).BooleanThe command duplicate(obj) is transformed by the compiler into Object.create_duplicate(obj), which then calls this method. For optimal performance (by removing an internal typecast in most situations), have your overridden create_duplicate have the same return type as the class it's defined in. For instance, Strings implementation is 'create_duplicate.String'. This default implementation throws an UnsupportedMethodError.
Returns true if this object is equivalant to another.
has_another().BooleanThe compiler converts 'obj1 == obj2' into 'obj1.equals(obj2)' and 'obj1 != obj2' into 'not obj1.equals(obj2)'. Implementations of equals() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract: if (obj1.equals(obj2)) obj1.compare_to(obj2) == eq obj1.hash_code == obj2.hash_code else obj1.compare_to(obj2) != eq endIfNote that two "equal" objects *must* have the same hash code, but "unequal" objects may or may not have the same hash code. This default implementation returns true if the this object and the 'other' reference are the same object ('this is other').
Returns "true" if this reader has another value that can
be previewed with peek() or read with read().
hash_code().Int32
Returns the hash code of this object, which some classes
(like HashTable) rely on. This default implementation
throws an UnsupportedMethodError.
init( Readable<<InputDataType>> readable )Hash codes are used to quickly test and see if two complex objects are NOT equal. The value returned has no intrinsic meaning, but should conform to the following rules: 1. Two objects that are equivalent should produce the same hash code. 2. If an object's state doesn't change, its hash code shouldn't change either. Internally, this precludes the hash code being based on an object's memory address since Slag doesn't guarantee that an object's address won't change over time. This has the following implications: If you override hash_code you should also override equals() and possibly compare_to() and ensure the following contract. Invariant:
if (obj1.hash_code != obj2.hash_code)
obj1.equals(obj2) == false
obj1.compare_to(obj2) != eq
endIf
Initializes this BitReader to read from the given reader.
init( Reader<<InputDataType>> src )
Initializes this BitReader to read from the given readable
data.
is_exhausted().Boolean
Returns "true" if this reader does not have another value
or "false" if it does.
peek().OutputDataType
Returns the next value that will be returned from read().
If there is no next value then a NoNextValueError is thrown.
position( Int32 new_position )
This optional property-write sets the zero-based read position
of this reader. When a reader is first created position()
returns 0. After a single read() it returns 1, and so on.
Readers that don't implement this property will throw an
UnsupportedMethodError when it's accessed.
position().Int32
This optional property-read returns the zero-based read
position of this reader. When a reader is first created
position() returns 0. After a single read() it returns 1,
and so on.
prep_next().BooleanReaders that don't implement this property will throw an UnsupportedMethodError when it's accessed. read().OutputDataType
Returns the next value from this reader. If (not has_another)
then a NoNextValueError is thrown.
read_line().String
Reads and returns the next line of characters up to the next
LF or CRLF. The CRLF characters are not part of
the return value and are discarded.
read_list( Int32 size ).DataType[]Only defined for Reader<<Char>>.
Reads the next 'size' number of values and returns them in a
list. Requires that there are at least 'size' number of
values remaining to be read.
remaining().Int32
This optional property returns how many values remain to be
read before the reader is exhausted. Not all readers
can implement this property; those that don't will throw
an UnsupportedMethodError when it's accessed.
rewind()
This optional method resets this reader so that the next
read() will return the first value of the series.
Readers that don't implement this property will throw an
UnsupportedMethodError when it's accessed.
skip( [Int32 skip_count] )
Discards exactly the next 'skip_count' number of values
rather than reading them. If there are not enough values
remaining then a NoNextValueError will be thrown from read().
to_List().DataType[]This program fragment: local var a = reader.read reader.read reader.read local var b = reader.readis equivalent to this: local var a = reader.read reader.skip(2) local var b = reader.read
Creates and returns a list of all the remaining values of
this reader.
to_String().String
Returns a string representation of this reader's values.
type_name().String
Returns the true class name of this object. Implemented by
the runtime; you should not override this method.
Example: local Object obj = "Hello World" println( obj.type_name ) #prints: String |
| Class Methods |
|---|
|
create_duplicate( Object existing ).Object
This factory method initiates object duplication. The
compiler transforms the duplicate(obj) command into
Object.create_duplicate(obj).
Returns: 'null' if 'existing' is null. existing.create_duplicate otherwise |
| Object Variables |
|---|
|
high_ch : Char low_ch : Char next : PatternMatcher |
| Object Methods |
|---|
|
chain_next( PatternMatcher _next ) compare_to( Object other ).Ternary
This method is used for ordering (quantitative) comparisons
between this object and another.
create_duplicate().ObjectReturns 'eq' if they're equivalent, 'lt' if this object is "less than" the other, or 'gt' if this object is "greater than" another. The compiler converts: 'obj1 < obj2' -> 'obj1.compare_to(obj2) == lt' 'obj1 > obj2' -> 'obj1.compare_to(obj2) == gt' 'obj1 <= obj2' -> 'obj1.compare_to(obj2) != gt' 'obj1 >= obj2' -> 'obj1.compare_to(obj2) != lt'Implementations of compare_to() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract:
if (obj1.compare_to(obj2) == eq)
obj1.equals(obj2) == true
obj1.hash_code == obj2.hash_code
else
obj1.equals(obj2) == false
endIf
Note that two "equal" objects *must* have the same hash code,
but "unequal" objects may or may not have the same hash code.
This default implementation throws an UnsupportedMethodError.
Should create a duplicate of this object such that
obj1.equals(obj1.create_duplicate) return true.
equals( Object other ).BooleanThe command duplicate(obj) is transformed by the compiler into Object.create_duplicate(obj), which then calls this method. For optimal performance (by removing an internal typecast in most situations), have your overridden create_duplicate have the same return type as the class it's defined in. For instance, Strings implementation is 'create_duplicate.String'. This default implementation throws an UnsupportedMethodError.
Returns true if this object is equivalant to another.
hash_code().Int32The compiler converts 'obj1 == obj2' into 'obj1.equals(obj2)' and 'obj1 != obj2' into 'not obj1.equals(obj2)'. Implementations of equals() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract: if (obj1.equals(obj2)) obj1.compare_to(obj2) == eq obj1.hash_code == obj2.hash_code else obj1.compare_to(obj2) != eq endIfNote that two "equal" objects *must* have the same hash code, but "unequal" objects may or may not have the same hash code. This default implementation returns true if the this object and the 'other' reference are the same object ('this is other').
Returns the hash code of this object, which some classes
(like HashTable) rely on. This default implementation
throws an UnsupportedMethodError.
init( Char low_ch, Char high_ch )Hash codes are used to quickly test and see if two complex objects are NOT equal. The value returned has no intrinsic meaning, but should conform to the following rules: 1. Two objects that are equivalent should produce the same hash code. 2. If an object's state doesn't change, its hash code shouldn't change either. Internally, this precludes the hash code being based on an object's memory address since Slag doesn't guarantee that an object's address won't change over time. This has the following implications: If you override hash_code you should also override equals() and possibly compare_to() and ensure the following contract. Invariant:
if (obj1.hash_code != obj2.hash_code)
obj1.equals(obj2) == false
obj1.compare_to(obj2) != eq
endIf
init( Char low_ch ) match( PatternMatchInfo state ).Boolean match_next( PatternMatchInfo state ).Boolean matches_any().Boolean to_String().String type_name().String
Returns the true class name of this object. Implemented by
the runtime; you should not override this method.
Example: local Object obj = "Hello World" println( obj.type_name ) #prints: String |
Defines an abstract circle as 'position' and 'radius'. Note: Circle drawing requires many operations!
Circle-related methods in class Global
enclose( Circle circle ).Rect
intersect( Line line, Circle circle ).Boolean
print( Circle circle )
println( Circle circle )
surround( Rect rect ).Circle
surround( Line line ).Circle
to_String( Circle circle ).String
x1_of( Circle circle ).Real64
x2_of( Circle circle ).Real64
y1_of( Circle circle ).Real64
y2_of( Circle circle ).Real64
| Composite Elements |
|---|
|
position : Vector2 radius : Real64 |
Defines a 32-bit color using integer red, green, blue, and alpha color components, each 0-255.
The order of the color components is designed so that the underlying memory lists them in ARGB order.
Color-related methods in class Global
as_Int32( Color color ).Int32
clear_display( [Color color] )
draw( Quad q, Color color )
draw( Rect r, Color color )
draw( Line line, Color color )
fill( Rect r, Color color )
fill( Quad q, Color color )
new_HSV( Color color ).HSV
print( Color c )
println( Color c )
random_Color().Color
to_String( Color c ).String
| Composite Elements |
|---|
|
blue : Byte green : Byte red : Byte alpha : Byte |
Convenience class that stores the four corner colors of a color gradient and can draw the gradient in a rectangular area.
| Class Methods |
|---|
|
create_duplicate( Object existing ).Object
This factory method initiates object duplication. The
compiler transforms the duplicate(obj) command into
Object.create_duplicate(obj).
Returns: 'null' if 'existing' is null. existing.create_duplicate otherwise |
| Object Variables |
|---|
|
bottom_left_color : Color bottom_right_color : Color top_left_color : Color top_right_color : Color |
| Object Methods |
|---|
|
compare_to( Object other ).Ternary
This method is used for ordering (quantitative) comparisons
between this object and another.
create_duplicate().ObjectReturns 'eq' if they're equivalent, 'lt' if this object is "less than" the other, or 'gt' if this object is "greater than" another. The compiler converts: 'obj1 < obj2' -> 'obj1.compare_to(obj2) == lt' 'obj1 > obj2' -> 'obj1.compare_to(obj2) == gt' 'obj1 <= obj2' -> 'obj1.compare_to(obj2) != gt' 'obj1 >= obj2' -> 'obj1.compare_to(obj2) != lt'Implementations of compare_to() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract:
if (obj1.compare_to(obj2) == eq)
obj1.equals(obj2) == true
obj1.hash_code == obj2.hash_code
else
obj1.equals(obj2) == false
endIf
Note that two "equal" objects *must* have the same hash code,
but "unequal" objects may or may not have the same hash code.
This default implementation throws an UnsupportedMethodError.
Should create a duplicate of this object such that
obj1.equals(obj1.create_duplicate) return true.
draw( Real64 x, Real64 y, Real64 w, Real64 h )The command duplicate(obj) is transformed by the compiler into Object.create_duplicate(obj), which then calls this method. For optimal performance (by removing an internal typecast in most situations), have your overridden create_duplicate have the same return type as the class it's defined in. For instance, Strings implementation is 'create_duplicate.String'. This default implementation throws an UnsupportedMethodError.
Draws this color gradient in the given rectangular area.
draw( Rect r )
Draws this color gradient in the given rectangular area.
equals( Object other ).Boolean
Returns true if this object is equivalant to another.
hash_code().Int32The compiler converts 'obj1 == obj2' into 'obj1.equals(obj2)' and 'obj1 != obj2' into 'not obj1.equals(obj2)'. Implementations of equals() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract: if (obj1.equals(obj2)) obj1.compare_to(obj2) == eq obj1.hash_code == obj2.hash_code else obj1.compare_to(obj2) != eq endIfNote that two "equal" objects *must* have the same hash code, but "unequal" objects may or may not have the same hash code. This default implementation returns true if the this object and the 'other' reference are the same object ('this is other').
Returns the hash code of this object, which some classes
(like HashTable) rely on. This default implementation
throws an UnsupportedMethodError.
init( Color top_left_color, Color top_right_color, Color bottom_right_color, Color bottom_left_color )Hash codes are used to quickly test and see if two complex objects are NOT equal. The value returned has no intrinsic meaning, but should conform to the following rules: 1. Two objects that are equivalent should produce the same hash code. 2. If an object's state doesn't change, its hash code shouldn't change either. Internally, this precludes the hash code being based on an object's memory address since Slag doesn't guarantee that an object's address won't change over time. This has the following implications: If you override hash_code you should also override equals() and possibly compare_to() and ensure the following contract. Invariant:
if (obj1.hash_code != obj2.hash_code)
obj1.equals(obj2) == false
obj1.compare_to(obj2) != eq
endIf
Creates a color gradient with the specified corner colors.
init( Int32 c1, Int32 c2, Int32 c3, Int32 c4 )
Creates a color gradient with the specified corner colors (given as 0xAARRGGBB integers).
to_String().String
Returns:
type_name().StringA String representation of this object. Most classes should override this method to summarize an object's state for convenience in testing and debugging.
Returns the true class name of this object. Implemented by
the runtime; you should not override this method.
Example: local Object obj = "Hello World" println( obj.type_name ) #prints: String |
A composite image is designed for loading and displaying large splash screens and other background graphics. Upon initialization it loads a given image and then breaks it up into 256x256-pixel chunks - which are then redrawn pieced together as a whole.
| Class Variables |
|---|
|
color_policy : Color
Specifies the initial value for the 'color' property of
new Image objects. Opaque white by default.
handle_policy : Vector2
Specifies the initial value for the 'handle' property of
new Image objects. (0,0) (HANDLE.top_left) by default.
render_flags_policy : Int32
Specifies the initial value for the 'render_flags' property of
new Image objects. Default: no flags are set.
|
| Class Methods |
|---|
|
create_duplicate( Object existing ).Object
This factory method initiates object duplication. The
compiler transforms the duplicate(obj) command into
Object.create_duplicate(obj).
Returns: 'null' if 'existing' is null. existing.create_duplicate otherwise |
| Object Variables |
|---|
|
angle : Radians
The angle property variable. This may be set to a new
Radians or Degrees value.
color : ColorNote: CompositeImage objects currently ignore this property.
The multiplier for each pixel in this image as it's drawn.
The default color of new_Color(255,255,255,255) ensures that
the image will appear "normal". A color of
new_Color(255,255,0) would not draw any of the blue channel,
making a grey-scale image appear to be tinted yellow. A color
of new_Color(255,255,255,128) would draw the image halfway
transparent.
handle : Vector2
Specifies the drawing and rotation origin of this image.
This can be set to a pixel value relative to the upper-left
of the image (0,0) or a HANDLE category such as
"HANDLE.center" or "HANDLE.bottom_center".
hflip : Boolean
Specifies that an image should be flipped horizontally when
drawn. This mirroring is applied before the image is rotated
and does not affect the spatial positioning.
parts : GenericImage[]Note: CompositeImage objects currently ignore this property.
All of the image sub-parts that comprise this composite image.
render_flags : Int32
Any combination of RENDER constants, or 0 for no special
rendering options.
scale : Vector2Example: ghost.render_flags = (RENDER.overexpose | RENDER.fixed_color)
The size multiplier for rendering, (1.0,1.0) by default.
Setting "scale = Vector2(2.0,0.5)" would cause the image to
render at twice the width and half the height. Change
'size' instead if you want to achieve particular pixel
dimensions.
size : Vector2
The nominal size of the given image, in pixels. Change
'size' if you want the image's standard size to be a
given number of pixels or change 'scale' if you want the
image to be proportionally larger or smaller.
vflip : Boolean
Specifies that an image should be flipped vertically when
drawn. This mirroring is applied before the image is rotated
and does not affect the spatial positioning.
Note: CompositeImage objects currently ignore this property. |
| Object Methods |
|---|
|
add( GenericImage img, Vector2 offset )
Adds 'img' to this composite image - 'img' may be an Image or
a CompositeImage object. It will be drawn with its handle
at 'offset' relative to the top-left corner of this image.
alpha( Int32 new_alpha )
Alpha property-set method - sets the alpha component
of this image's color multiplier.
alpha().Int32
Alpha property-get method - returns the alpha component
(0-255) of the current color multiplier.
angle( Radians new_angle )
Angle property-set.
angle( Degrees deg )Note: CompositeImage objects currently ignore this property.
Angle property-set.
compare_to( Object other ).TernaryNote: CompositeImage objects currently ignore this property.
This method is used for ordering (quantitative) comparisons
between this object and another.
create_duplicate().ObjectReturns 'eq' if they're equivalent, 'lt' if this object is "less than" the other, or 'gt' if this object is "greater than" another. The compiler converts: 'obj1 < obj2' -> 'obj1.compare_to(obj2) == lt' 'obj1 > obj2' -> 'obj1.compare_to(obj2) == gt' 'obj1 <= obj2' -> 'obj1.compare_to(obj2) != gt' 'obj1 >= obj2' -> 'obj1.compare_to(obj2) != lt'Implementations of compare_to() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract:
if (obj1.compare_to(obj2) == eq)
obj1.equals(obj2) == true
obj1.hash_code == obj2.hash_code
else
obj1.equals(obj2) == false
endIf
Note that two "equal" objects *must* have the same hash code,
but "unequal" objects may or may not have the same hash code.
This default implementation throws an UnsupportedMethodError.
Should create a duplicate of this object such that
obj1.equals(obj1.create_duplicate) return true.
draw( Vector2 pos )The command duplicate(obj) is transformed by the compiler into Object.create_duplicate(obj), which then calls this method. For optimal performance (by removing an internal typecast in most situations), have your overridden create_duplicate have the same return type as the class it's defined in. For instance, Strings implementation is 'create_duplicate.String'. This default implementation throws an UnsupportedMethodError.
draw() method.
draw( Real64 x, Real64 y )
Draws this image with its handle (origin) at (x,y).
equals( Object other ).Boolean
Returns true if this object is equivalant to another.
fixed_color().BooleanThe compiler converts 'obj1 == obj2' into 'obj1.equals(obj2)' and 'obj1 != obj2' into 'not obj1.equals(obj2)'. Implementations of equals() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract: if (obj1.equals(obj2)) obj1.compare_to(obj2) == eq obj1.hash_code == obj2.hash_code else obj1.compare_to(obj2) != eq endIfNote that two "equal" objects *must* have the same hash code, but "unequal" objects may or may not have the same hash code. This default implementation returns true if the this object and the 'other' reference are the same object ('this is other').
Returns "true" if "fixed_color" is set in the render flags.
fixed_color( Boolean setting )
Turns fixed-color drawing on or off in the render flags.
handle( Vector2 new_handle )
Handle property-set.
handle( HANDLE h )
Handle property-set.
hash_code().Int32
Returns the hash code of this object, which some classes
(like HashTable) rely on. This default implementation
throws an UnsupportedMethodError.
init( String filename )Hash codes are used to quickly test and see if two complex objects are NOT equal. The value returned has no intrinsic meaning, but should conform to the following rules: 1. Two objects that are equivalent should produce the same hash code. 2. If an object's state doesn't change, its hash code shouldn't change either. Internally, this precludes the hash code being based on an object's memory address since Slag doesn't guarantee that an object's address won't change over time. This has the following implications: If you override hash_code you should also override equals() and possibly compare_to() and ensure the following contract. Invariant:
if (obj1.hash_code != obj2.hash_code)
obj1.equals(obj2) == false
obj1.compare_to(obj2) != eq
endIf
Initializes this CompositeImage to draw the given image.
init( Vector2 size )
Initializes this object to an empty image of the given size.
Additional image subparts may be added with the add() method.
init( Bitmap bmp )
Initializes this CompositeImage to draw the given bitmap.
overexpose().Boolean
Returns "true" if "overexpose" is set in the render flags.
overexpose( Boolean setting )
Turns overexposure on or off in the render flags.
point_filter( Boolean setting )
Turns point filtering on or off in the render flags. "on"
selects nearest-neighbor point filtering; "off" selects
linear filtering (the Image default).
point_filter().Boolean
Returns "true" if "point_filter" is set in the render flags.
region().Rect
Returns the rectangular region nominally occupied by this
image at its size and scale. The 'position' of the
resulting rectangle is (0,0).
release()
Calls release() on each of this CompositeImage object's
constituent parts.
scale( Real64 uniform_scale )
Scale property-set.
scale( Vector2 new_scale )
Scale property-set.
size( Vector2 new_size )
Size property-set.
texture_wrap().Boolean
Returns "true" if "texture_wrap" is set in the render flags.
texture_wrap( Boolean setting )
Turns texture wrapping on or off in the render flags.
to_String().String
Returns:
type_name().StringA String representation of this object. Most classes should override this method to summarize an object's state for convenience in testing and debugging.
Returns the true class name of this object. Implemented by
the runtime; you should not override this method.
Example: local Object obj = "Hello World" println( obj.type_name ) #prints: String |
A range made up of ranges - each next value is obtained indirectly from a list of ranges. For example, {1..3,7..9} creates a CompositeRange object whose reader would return the values {1,2,3,7,8,9}.
This is relied on by the compiler internally; most programmers will not need to use it directly.
| Class Methods |
|---|
|
create_duplicate( Object existing ).Object
This factory method initiates object duplication. The
compiler transforms the duplicate(obj) command into
Object.create_duplicate(obj).
Returns: 'null' if 'existing' is null. existing.create_duplicate otherwise |
| Object Variables |
|---|
|
ranges : Range<<DataType>>[] |
| Object Methods |
|---|
|
compare_to( Object other ).Ternary
This method is used for ordering (quantitative) comparisons
between this object and another.
create_duplicate().ObjectReturns 'eq' if they're equivalent, 'lt' if this object is "less than" the other, or 'gt' if this object is "greater than" another. The compiler converts: 'obj1 < obj2' -> 'obj1.compare_to(obj2) == lt' 'obj1 > obj2' -> 'obj1.compare_to(obj2) == gt' 'obj1 <= obj2' -> 'obj1.compare_to(obj2) != gt' 'obj1 >= obj2' -> 'obj1.compare_to(obj2) != lt'Implementations of compare_to() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract:
if (obj1.compare_to(obj2) == eq)
obj1.equals(obj2) == true
obj1.hash_code == obj2.hash_code
else
obj1.equals(obj2) == false
endIf
Note that two "equal" objects *must* have the same hash code,
but "unequal" objects may or may not have the same hash code.
This default implementation throws an UnsupportedMethodError.
Should create a duplicate of this object such that
obj1.equals(obj1.create_duplicate) return true.
create_reader().Reader<<DataType>>The command duplicate(obj) is transformed by the compiler into Object.create_duplicate(obj), which then calls this method. For optimal performance (by removing an internal typecast in most situations), have your overridden create_duplicate have the same return type as the class it's defined in. For instance, Strings implementation is 'create_duplicate.String'. This default implementation throws an UnsupportedMethodError.
Returns a reader that can be used to read() this data one
element at a time.
equals( Object other ).Boolean
Returns true if this object is equivalant to another.
hash_code().Int32The compiler converts 'obj1 == obj2' into 'obj1.equals(obj2)' and 'obj1 != obj2' into 'not obj1.equals(obj2)'. Implementations of equals() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract: if (obj1.equals(obj2)) obj1.compare_to(obj2) == eq obj1.hash_code == obj2.hash_code else obj1.compare_to(obj2) != eq endIfNote that two "equal" objects *must* have the same hash code, but "unequal" objects may or may not have the same hash code. This default implementation returns true if the this object and the 'other' reference are the same object ('this is other').
Returns the hash code of this object, which some classes
(like HashTable) rely on. This default implementation
throws an UnsupportedMethodError.
init( Range<<DataType>>[] ranges )Hash codes are used to quickly test and see if two complex objects are NOT equal. The value returned has no intrinsic meaning, but should conform to the following rules: 1. Two objects that are equivalent should produce the same hash code. 2. If an object's state doesn't change, its hash code shouldn't change either. Internally, this precludes the hash code being based on an object's memory address since Slag doesn't guarantee that an object's address won't change over time. This has the following implications: If you override hash_code you should also override equals() and possibly compare_to() and ensure the following contract. Invariant:
if (obj1.hash_code != obj2.hash_code)
obj1.equals(obj2) == false
obj1.compare_to(obj2) != eq
endIf
to_List().DataType[]
Converts this data into a list.
to_String().String
Returns a string representation of this CompositeRange.
type_name().String
Returns the true class name of this object. Implemented by
the runtime; you should not override this method.
Example: local Object obj = "Hello World" println( obj.type_name ) #prints: String |
Reader for a CompositeRange. Utilized by the Slag compiler; most programmers will not need to use this directly.
| Class Methods |
|---|
|
create_duplicate( Object existing ).Object
This factory method initiates object duplication. The
compiler transforms the duplicate(obj) command into
Object.create_duplicate(obj).
Returns: 'null' if 'existing' is null. existing.create_duplicate otherwise |
| Object Variables |
|---|
|
cur_range : Reader<<DataType>> range_reader : Reader<<Range<<DataType>>>> |
| Object Methods |
|---|
|
available().Int32
Returns the minimum number of additional values that can be
immediately read from this reader.
close()If the reader is exhausted or if it must block to peek or read next then the result will be 0. It is important to note that '0' does not necessarily mean the reader is exhausted. Many readers will report that they have 1 available even if there are thousands of values waiting to be read. The 'available' property should be used as an aide for buffer sizes and the like but should not be taken as an absolute size.
Closes this reader as a source of input. Useful for file
readers, but for most others this command does nothing.
compare_to( Object other ).Ternary
This method is used for ordering (quantitative) comparisons
between this object and another.
consume( DataType look_for ).BooleanReturns 'eq' if they're equivalent, 'lt' if this object is "less than" the other, or 'gt' if this object is "greater than" another. The compiler converts: 'obj1 < obj2' -> 'obj1.compare_to(obj2) == lt' 'obj1 > obj2' -> 'obj1.compare_to(obj2) == gt' 'obj1 <= obj2' -> 'obj1.compare_to(obj2) != gt' 'obj1 >= obj2' -> 'obj1.compare_to(obj2) != lt'Implementations of compare_to() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract:
if (obj1.compare_to(obj2) == eq)
obj1.equals(obj2) == true
obj1.hash_code == obj2.hash_code
else
obj1.equals(obj2) == false
endIf
Note that two "equal" objects *must* have the same hash code,
but "unequal" objects may or may not have the same hash code.
This default implementation throws an UnsupportedMethodError.
Attempts to match and discard the next value from this
reader, returning true, or else leaves the next value still
pending and returns false.
create_duplicate().CompositeRangeReader<<DataType>>Returns: "true" if old.peek == look_for "false" if old.peek != look_forInvariant: if (old.peek == look_for) old.skip
Handles duplicating this iterator when "duplicate(iterator_obj)" is called.
equals( Object other ).Boolean
Returns true if this object is equivalant to another.
has_another().BooleanThe compiler converts 'obj1 == obj2' into 'obj1.equals(obj2)' and 'obj1 != obj2' into 'not obj1.equals(obj2)'. Implementations of equals() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract: if (obj1.equals(obj2)) obj1.compare_to(obj2) == eq obj1.hash_code == obj2.hash_code else obj1.compare_to(obj2) != eq endIfNote that two "equal" objects *must* have the same hash code, but "unequal" objects may or may not have the same hash code. This default implementation returns true if the this object and the 'other' reference are the same object ('this is other').
Returns "true" if this reader has another value that can
be previewed with peek() or read with read().
hash_code().Int32
Returns the hash code of this object, which some classes
(like HashTable) rely on. This default implementation
throws an UnsupportedMethodError.
init( Reader<<DataType>> cur_range, Reader<<Range<<DataType>>>> range_reader )Hash codes are used to quickly test and see if two complex objects are NOT equal. The value returned has no intrinsic meaning, but should conform to the following rules: 1. Two objects that are equivalent should produce the same hash code. 2. If an object's state doesn't change, its hash code shouldn't change either. Internally, this precludes the hash code being based on an object's memory address since Slag doesn't guarantee that an object's address won't change over time. This has the following implications: If you override hash_code you should also override equals() and possibly compare_to() and ensure the following contract. Invariant:
if (obj1.hash_code != obj2.hash_code)
obj1.equals(obj2) == false
obj1.compare_to(obj2) != eq
endIf
init( Reader<<Range<<DataType>>>> range_reader ) is_exhausted().Boolean
Returns "true" if this reader does not have another value
or "false" if it does.
peek().DataType
Returns the next value that will be returned from read().
If there is no next value then a NoNextValueError is thrown.
position( Int32 new_position )
This optional property-write sets the zero-based read position
of this reader. When a reader is first created position()
returns 0. After a single read() it returns 1, and so on.
Readers that don't implement this property will throw an
UnsupportedMethodError when it's accessed.
position().Int32
This optional property-read returns the zero-based read
position of this reader. When a reader is first created
position() returns 0. After a single read() it returns 1,
and so on.
prep_next()Readers that don't implement this property will throw an UnsupportedMethodError when it's accessed.
Prepares the next value that will be used by peek() and
read(). As a composite range reader, this involves advancing
to the next range reader if the current range reader is
empty.
read().DataType
Returns the next value from this reader. If (not has_another)
then a NoNextValueError is thrown.
read_line().String
Reads and returns the next line of characters up to the next
LF or CRLF. The CRLF characters are not part of
the return value and are discarded.
read_list( Int32 size ).DataType[]Only defined for Reader<<Char>>.
Reads the next 'size' number of values and returns them in a
list. Requires that there are at least 'size' number of
values remaining to be read.
remaining().Int32
This optional property returns how many values remain to be
read before the reader is exhausted. Not all readers
can implement this property; those that don't will throw
an UnsupportedMethodError when it's accessed.
rewind()
This optional method resets this reader so that the next
read() will return the first value of the series.
Readers that don't implement this property will throw an
UnsupportedMethodError when it's accessed.
skip( [Int32 skip_count] )
Discards exactly the next 'skip_count' number of values
rather than reading them. If there are not enough values
remaining then a NoNextValueError will be thrown from read().
to_List().DataType[]This program fragment: local var a = reader.read reader.read reader.read local var b = reader.readis equivalent to this: local var a = reader.read reader.skip(2) local var b = reader.read
Creates and returns a list of all the remaining values of
this reader.
to_String().String
Returns a string representation of this reader's values.
type_name().String
Returns the true class name of this object. Implemented by
the runtime; you should not override this method.
Example: local Object obj = "Hello World" println( obj.type_name ) #prints: String |
Thrown when a reader detects that other code has modified a list between one read and the next.
| Class Methods |
|---|
|
create_duplicate( Object existing ).Object
This factory method initiates object duplication. The
compiler transforms the duplicate(obj) command into
Object.create_duplicate(obj).
Returns: 'null' if 'existing' is null. existing.create_duplicate otherwise |
| Object Variables |
|---|
|
ip : Int64
The execution ip at the time of the exception. If generated
by Slag code this is "manually" calculated (as in
'Global.excecution_ip(-2)') or by the runtime environment
if generated by the VM or runtime.
message : String
The error message.
|
| Object Methods |
|---|
|
compare_to( Object other ).Ternary
This method is used for ordering (quantitative) comparisons
between this object and another.
create_duplicate().ObjectReturns 'eq' if they're equivalent, 'lt' if this object is "less than" the other, or 'gt' if this object is "greater than" another. The compiler converts: 'obj1 < obj2' -> 'obj1.compare_to(obj2) == lt' 'obj1 > obj2' -> 'obj1.compare_to(obj2) == gt' 'obj1 <= obj2' -> 'obj1.compare_to(obj2) != gt' 'obj1 >= obj2' -> 'obj1.compare_to(obj2) != lt'Implementations of compare_to() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract:
if (obj1.compare_to(obj2) == eq)
obj1.equals(obj2) == true
obj1.hash_code == obj2.hash_code
else
obj1.equals(obj2) == false
endIf
Note that two "equal" objects *must* have the same hash code,
but "unequal" objects may or may not have the same hash code.
This default implementation throws an UnsupportedMethodError.
Should create a duplicate of this object such that
obj1.equals(obj1.create_duplicate) return true.
equals( Object other ).BooleanThe command duplicate(obj) is transformed by the compiler into Object.create_duplicate(obj), which then calls this method. For optimal performance (by removing an internal typecast in most situations), have your overridden create_duplicate have the same return type as the class it's defined in. For instance, Strings implementation is 'create_duplicate.String'. This default implementation throws an UnsupportedMethodError.
Returns true if this object is equivalant to another.
hash_code().Int32The compiler converts 'obj1 == obj2' into 'obj1.equals(obj2)' and 'obj1 != obj2' into 'not obj1.equals(obj2)'. Implementations of equals() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract: if (obj1.equals(obj2)) obj1.compare_to(obj2) == eq obj1.hash_code == obj2.hash_code else obj1.compare_to(obj2) != eq endIfNote that two "equal" objects *must* have the same hash code, but "unequal" objects may or may not have the same hash code. This default implementation returns true if the this object and the 'other' reference are the same object ('this is other').
Returns the hash code of this object, which some classes
(like HashTable) rely on. This default implementation
throws an UnsupportedMethodError.
init( String message )Hash codes are used to quickly test and see if two complex objects are NOT equal. The value returned has no intrinsic meaning, but should conform to the following rules: 1. Two objects that are equivalent should produce the same hash code. 2. If an object's state doesn't change, its hash code shouldn't change either. Internally, this precludes the hash code being based on an object's memory address since Slag doesn't guarantee that an object's address won't change over time. This has the following implications: If you override hash_code you should also override equals() and possibly compare_to() and ensure the following contract. Invariant:
if (obj1.hash_code != obj2.hash_code)
obj1.equals(obj2) == false
obj1.compare_to(obj2) != eq
endIf
Stores the given error message.
init()
Default initializer.
to_String().String
Returns a description of the execution IP at the time
the error was thrown along with the error message.
type_name().String
Returns the true class name of this object. Implemented by
the runtime; you should not override this method.
Example: local Object obj = "Hello World" println( obj.type_name ) #prints: String |
Compound consisting of two corners. Exists as a means to create a rectangle from two corners rather than a corner and a size.
Corners-related methods in class Global
get_uv( Int32 image_index ).Corners
new_Rect( Corners c ).Rect
print( Corners c )
println( Corners c )
set_uv( Int32 image_index, Corners corners )
size_of( Corners c ).Vector2
to_String( Corners c ).String
x1_of( Corners c ).Real64
x2_of( Corners c ).Real64
y1_of( Corners c ).Real64
y2_of( Corners c ).Real64
| Composite Elements |
|---|
|
top_left : Vector2 bottom_right : Vector2 |
A generator that returns the next value in the sequence with every read.
| Class Methods |
|---|
|
create_duplicate( Object existing ).Object
This factory method initiates object duplication. The
compiler transforms the duplicate(obj) command into
Object.create_duplicate(obj).
Returns: 'null' if 'existing' is null. existing.create_duplicate otherwise |
| Object Variables |
|---|
|
next : DataType
The next number that will be returned from read().
step_size : DataType
The step size between consecutive numbers.
|
| Object Methods |
|---|
|
available().Int32
Returns the minimum number of additional values that can be
immediately read from this reader.
close()If the reader is exhausted or if it must block to peek or read next then the result will be 0. It is important to note that '0' does not necessarily mean the reader is exhausted. Many readers will report that they have 1 available even if there are thousands of values waiting to be read. The 'available' property should be used as an aide for buffer sizes and the like but should not be taken as an absolute size.
Closes this reader as a source of input. Useful for file
readers, but for most others this command does nothing.
compare_to( Object other ).Ternary
This method is used for ordering (quantitative) comparisons
between this object and another.
consume( DataType look_for ).BooleanReturns 'eq' if they're equivalent, 'lt' if this object is "less than" the other, or 'gt' if this object is "greater than" another. The compiler converts: 'obj1 < obj2' -> 'obj1.compare_to(obj2) == lt' 'obj1 > obj2' -> 'obj1.compare_to(obj2) == gt' 'obj1 <= obj2' -> 'obj1.compare_to(obj2) != gt' 'obj1 >= obj2' -> 'obj1.compare_to(obj2) != lt'Implementations of compare_to() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract:
if (obj1.compare_to(obj2) == eq)
obj1.equals(obj2) == true
obj1.hash_code == obj2.hash_code
else
obj1.equals(obj2) == false
endIf
Note that two "equal" objects *must* have the same hash code,
but "unequal" objects may or may not have the same hash code.
This default implementation throws an UnsupportedMethodError.
Attempts to match and discard the next value from this
reader, returning true, or else leaves the next value still
pending and returns false.
create_duplicate().Counter<<DataType>>Returns: "true" if old.peek == look_for "false" if old.peek != look_forInvariant: if (old.peek == look_for) old.skip
Handles duplicating this iterator when "duplicate(iterator_obj)" is called.
equals( Object other ).Boolean
Returns true if this object is equivalant to another.
has_another().BooleanThe compiler converts 'obj1 == obj2' into 'obj1.equals(obj2)' and 'obj1 != obj2' into 'not obj1.equals(obj2)'. Implementations of equals() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract: if (obj1.equals(obj2)) obj1.compare_to(obj2) == eq obj1.hash_code == obj2.hash_code else obj1.compare_to(obj2) != eq endIfNote that two "equal" objects *must* have the same hash code, but "unequal" objects may or may not have the same hash code. This default implementation returns true if the this object and the 'other' reference are the same object ('this is other').
Returns true - standard generators always have another value.
hash_code().Int32
Returns the hash code of this object, which some classes
(like HashTable) rely on. This default implementation
throws an UnsupportedMethodError.
init( [DataType next], [DataType step_size] )Hash codes are used to quickly test and see if two complex objects are NOT equal. The value returned has no intrinsic meaning, but should conform to the following rules: 1. Two objects that are equivalent should produce the same hash code. 2. If an object's state doesn't change, its hash code shouldn't change either. Internally, this precludes the hash code being based on an object's memory address since Slag doesn't guarantee that an object's address won't change over time. This has the following implications: If you override hash_code you should also override equals() and possibly compare_to() and ensure the following contract. Invariant:
if (obj1.hash_code != obj2.hash_code)
obj1.equals(obj2) == false
obj1.compare_to(obj2) != eq
endIf
is_exhausted().Boolean
Returns "true" if this reader does not have another value
or "false" if it does.
peek().DataType
Returns the next value that will be returned from read().
If there is no next value then a NoNextValueError is thrown.
position( Int32 new_position )
This optional property-write sets the zero-based read position
of this reader. When a reader is first created position()
returns 0. After a single read() it returns 1, and so on.
Readers that don't implement this property will throw an
UnsupportedMethodError when it's accessed.
position().Int32
This optional property-read returns the zero-based read
position of this reader. When a reader is first created
position() returns 0. After a single read() it returns 1,
and so on.
read().DataTypeReaders that don't implement this property will throw an UnsupportedMethodError when it's accessed.
Returns the next number and advances the counter.
read_line().String
Reads and returns the next line of characters up to the next
LF or CRLF. The CRLF characters are not part of
the return value and are discarded.
read_list( Int32 size ).DataType[]Only defined for Reader<<Char>>.
Reads the next 'size' number of values and returns them in a
list. Requires that there are at least 'size' number of
values remaining to be read.
remaining().Int32
This optional property returns how many values remain to be
read before the reader is exhausted. Not all readers
can implement this property; those that don't will throw
an UnsupportedMethodError when it's accessed.
rewind()
This optional method resets this reader so that the next
read() will return the first value of the series.
Readers that don't implement this property will throw an
UnsupportedMethodError when it's accessed.
skip( Int32 skip_count )
Discards 'skip_count' number of values that would otherwise
be returned from this generator.
to_List().DataType[]
Throws an UnsupportedMethodError.
to_String().String
Returns a string representation of this reader's values.
type_name().String
Returns the true class name of this object. Implemented by
the runtime; you should not override this method.
Example: local Object obj = "Hello World" println( obj.type_name ) #prints: String |
Real64 wrapper compound that specifies an angle in degrees.
Degrees compounds may be used in trig operations such as sin() and cos().
Degrees-related methods in class Global
cos( Degrees deg ).Real64
degrees_of( Vector2 v ).Degrees
new_Radians( Degrees deg ).Radians
new_Vector2( Real64 magnitude, Degrees angle ).Vector2
op*( Real64 factor, Degrees deg ).Degrees
op+( Radians rad, Degrees deg ).Radians
op-( Radians rad, Degrees deg ).Radians
op-( Degrees deg1 ).Degrees
op/( Real64 factor, Degrees deg ).Degrees
point_at( Circle circle, Degrees angle ).Vector2
print( Degrees deg )
println( Degrees deg )
random_Degrees().Degrees
rotate( Vector2 v, Degrees deg ).Vector2
sin( Degrees deg ).Real64
tan( Degrees deg ).Real64
to_Radians( Degrees deg ).Radians
to_String( Degrees deg ).String
| Composite Elements |
|---|
|
value : Real64 |
| Class Methods |
|---|
|
create_duplicate( Object existing ).Object
This factory method initiates object duplication. The
compiler transforms the duplicate(obj) command into
Object.create_duplicate(obj).
Returns: 'null' if 'existing' is null. existing.create_duplicate otherwise |
| Object Methods |
|---|
|
compare_to( Object other ).Ternary
This method is used for ordering (quantitative) comparisons
between this object and another.
create_duplicate().ObjectReturns 'eq' if they're equivalent, 'lt' if this object is "less than" the other, or 'gt' if this object is "greater than" another. The compiler converts: 'obj1 < obj2' -> 'obj1.compare_to(obj2) == lt' 'obj1 > obj2' -> 'obj1.compare_to(obj2) == gt' 'obj1 <= obj2' -> 'obj1.compare_to(obj2) != gt' 'obj1 >= obj2' -> 'obj1.compare_to(obj2) != lt'Implementations of compare_to() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract:
if (obj1.compare_to(obj2) == eq)
obj1.equals(obj2) == true
obj1.hash_code == obj2.hash_code
else
obj1.equals(obj2) == false
endIf
Note that two "equal" objects *must* have the same hash code,
but "unequal" objects may or may not have the same hash code.
This default implementation throws an UnsupportedMethodError.
Should create a duplicate of this object such that
obj1.equals(obj1.create_duplicate) return true.
equals( Object other ).BooleanThe command duplicate(obj) is transformed by the compiler into Object.create_duplicate(obj), which then calls this method. For optimal performance (by removing an internal typecast in most situations), have your overridden create_duplicate have the same return type as the class it's defined in. For instance, Strings implementation is 'create_duplicate.String'. This default implementation throws an UnsupportedMethodError.
Returns true if this object is equivalant to another.
hash_code().Int32The compiler converts 'obj1 == obj2' into 'obj1.equals(obj2)' and 'obj1 != obj2' into 'not obj1.equals(obj2)'. Implementations of equals() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract: if (obj1.equals(obj2)) obj1.compare_to(obj2) == eq obj1.hash_code == obj2.hash_code else obj1.compare_to(obj2) != eq endIfNote that two "equal" objects *must* have the same hash code, but "unequal" objects may or may not have the same hash code. This default implementation returns true if the this object and the 'other' reference are the same object ('this is other').
Returns the hash code of this object, which some classes
(like HashTable) rely on. This default implementation
throws an UnsupportedMethodError.
to_String().StringHash codes are used to quickly test and see if two complex objects are NOT equal. The value returned has no intrinsic meaning, but should conform to the following rules: 1. Two objects that are equivalent should produce the same hash code. 2. If an object's state doesn't change, its hash code shouldn't change either. Internally, this precludes the hash code being based on an object's memory address since Slag doesn't guarantee that an object's address won't change over time. This has the following implications: If you override hash_code you should also override equals() and possibly compare_to() and ensure the following contract. Invariant:
if (obj1.hash_code != obj2.hash_code)
obj1.equals(obj2) == false
obj1.compare_to(obj2) != eq
endIf
Returns:
type_name().StringA String representation of this object. Most classes should override this method to summarize an object's state for convenience in testing and debugging.
Returns the true class name of this object. Implemented by
the runtime; you should not override this method.
Example: local Object obj = "Hello World" println( obj.type_name ) #prints: String |
| Class Methods |
|---|
|
create_duplicate( Object existing ).Object
This factory method initiates object duplication. The
compiler transforms the duplicate(obj) command into
Object.create_duplicate(obj).
Returns: 'null' if 'existing' is null. existing.create_duplicate otherwise |
| Object Variables |
|---|
|
ip : Int64
The execution ip at the time of the exception. If generated
by Slag code this is "manually" calculated (as in
'Global.excecution_ip(-2)') or by the runtime environment
if generated by the VM or runtime.
message : String
The error message.
|
| Object Methods |
|---|
|
compare_to( Object other ).Ternary
This method is used for ordering (quantitative) comparisons
between this object and another.
create_duplicate().ObjectReturns 'eq' if they're equivalent, 'lt' if this object is "less than" the other, or 'gt' if this object is "greater than" another. The compiler converts: 'obj1 < obj2' -> 'obj1.compare_to(obj2) == lt' 'obj1 > obj2' -> 'obj1.compare_to(obj2) == gt' 'obj1 <= obj2' -> 'obj1.compare_to(obj2) != gt' 'obj1 >= obj2' -> 'obj1.compare_to(obj2) != lt'Implementations of compare_to() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract:
if (obj1.compare_to(obj2) == eq)
obj1.equals(obj2) == true
obj1.hash_code == obj2.hash_code
else
obj1.equals(obj2) == false
endIf
Note that two "equal" objects *must* have the same hash code,
but "unequal" objects may or may not have the same hash code.
This default implementation throws an UnsupportedMethodError.
Should create a duplicate of this object such that
obj1.equals(obj1.create_duplicate) return true.
equals( Object other ).BooleanThe command duplicate(obj) is transformed by the compiler into Object.create_duplicate(obj), which then calls this method. For optimal performance (by removing an internal typecast in most situations), have your overridden create_duplicate have the same return type as the class it's defined in. For instance, Strings implementation is 'create_duplicate.String'. This default implementation throws an UnsupportedMethodError.
Returns true if this object is equivalant to another.
hash_code().Int32The compiler converts 'obj1 == obj2' into 'obj1.equals(obj2)' and 'obj1 != obj2' into 'not obj1.equals(obj2)'. Implementations of equals() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract: if (obj1.equals(obj2)) obj1.compare_to(obj2) == eq obj1.hash_code == obj2.hash_code else obj1.compare_to(obj2) != eq endIfNote that two "equal" objects *must* have the same hash code, but "unequal" objects may or may not have the same hash code. This default implementation returns true if the this object and the 'other' reference are the same object ('this is other').
Returns the hash code of this object, which some classes
(like HashTable) rely on. This default implementation
throws an UnsupportedMethodError.
init( String message )Hash codes are used to quickly test and see if two complex objects are NOT equal. The value returned has no intrinsic meaning, but should conform to the following rules: 1. Two objects that are equivalent should produce the same hash code. 2. If an object's state doesn't change, its hash code shouldn't change either. Internally, this precludes the hash code being based on an object's memory address since Slag doesn't guarantee that an object's address won't change over time. This has the following implications: If you override hash_code you should also override equals() and possibly compare_to() and ensure the following contract. Invariant:
if (obj1.hash_code != obj2.hash_code)
obj1.equals(obj2) == false
obj1.compare_to(obj2) != eq
endIf
Initializes this Error with the given message.
init()to_String().String
Returns a description of the execution IP at the time
the error was thrown along with the error message.
type_name().String
Returns the true class name of this object. Implemented by
the runtime; you should not override this method.
Example: local Object obj = "Hello World" println( obj.type_name ) #prints: String |
Internal use.
| Class Methods |
|---|
|
create_duplicate( Object existing ).Object
This factory method initiates object duplication. The
compiler transforms the duplicate(obj) command into
Object.create_duplicate(obj).
Returns: 'null' if 'existing' is null. existing.create_duplicate otherwise |
| Object Variables |
|---|
|
next : PatternMatcher tag_group_index : Int32 |
| Object Methods |
|---|
|
chain_next( PatternMatcher _next ) compare_to( Object other ).Ternary
This method is used for ordering (quantitative) comparisons
between this object and another.
create_duplicate().ObjectReturns 'eq' if they're equivalent, 'lt' if this object is "less than" the other, or 'gt' if this object is "greater than" another. The compiler converts: 'obj1 < obj2' -> 'obj1.compare_to(obj2) == lt' 'obj1 > obj2' -> 'obj1.compare_to(obj2) == gt' 'obj1 <= obj2' -> 'obj1.compare_to(obj2) != gt' 'obj1 >= obj2' -> 'obj1.compare_to(obj2) != lt'Implementations of compare_to() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract:
if (obj1.compare_to(obj2) == eq)
obj1.equals(obj2) == true
obj1.hash_code == obj2.hash_code
else
obj1.equals(obj2) == false
endIf
Note that two "equal" objects *must* have the same hash code,
but "unequal" objects may or may not have the same hash code.
This default implementation throws an UnsupportedMethodError.
Should create a duplicate of this object such that
obj1.equals(obj1.create_duplicate) return true.
equals( Object other ).BooleanThe command duplicate(obj) is transformed by the compiler into Object.create_duplicate(obj), which then calls this method. For optimal performance (by removing an internal typecast in most situations), have your overridden create_duplicate have the same return type as the class it's defined in. For instance, Strings implementation is 'create_duplicate.String'. This default implementation throws an UnsupportedMethodError.
Returns true if this object is equivalant to another.
hash_code().Int32The compiler converts 'obj1 == obj2' into 'obj1.equals(obj2)' and 'obj1 != obj2' into 'not obj1.equals(obj2)'. Implementations of equals() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract: if (obj1.equals(obj2)) obj1.compare_to(obj2) == eq obj1.hash_code == obj2.hash_code else obj1.compare_to(obj2) != eq endIfNote that two "equal" objects *must* have the same hash code, but "unequal" objects may or may not have the same hash code. This default implementation returns true if the this object and the 'other' reference are the same object ('this is other').
Returns the hash code of this object, which some classes
(like HashTable) rely on. This default implementation
throws an UnsupportedMethodError.
init( Int32 tag_group_index )Hash codes are used to quickly test and see if two complex objects are NOT equal. The value returned has no intrinsic meaning, but should conform to the following rules: 1. Two objects that are equivalent should produce the same hash code. 2. If an object's state doesn't change, its hash code shouldn't change either. Internally, this precludes the hash code being based on an object's memory address since Slag doesn't guarantee that an object's address won't change over time. This has the following implications: If you override hash_code you should also override equals() and possibly compare_to() and ensure the following contract. Invariant:
if (obj1.hash_code != obj2.hash_code)
obj1.equals(obj2) == false
obj1.compare_to(obj2) != eq
endIf
match( PatternMatchInfo state ).Boolean match_next( PatternMatchInfo state ).Boolean matches_any().Boolean
Overridden in CharRangePatternMatcher
to_String().Stringtype_name().String
Returns the true class name of this object. Implemented by
the runtime; you should not override this method.
Example: local Object obj = "Hello World" println( obj.type_name ) #prints: String |
A reader that steps through the enumeration categories between a start and an end value.
Created by Range<<DataType>> objects with an enumeration DataType.
| Class Methods |
|---|
|
create_duplicate( Object existing ).Object
This factory method initiates object duplication. The
compiler transforms the duplicate(obj) command into
Object.create_duplicate(obj).
Returns: 'null' if 'existing' is null. existing.create_duplicate otherwise |
| Object Variables |
|---|
|
last_value : DataType next_value : DataType |
| Object Methods |
|---|
|
compare_to( Object other ).Ternary
This method is used for ordering (quantitative) comparisons
between this object and another.
create_duplicate().EnumIterator<<DataType>>Returns 'eq' if they're equivalent, 'lt' if this object is "less than" the other, or 'gt' if this object is "greater than" another. The compiler converts: 'obj1 < obj2' -> 'obj1.compare_to(obj2) == lt' 'obj1 > obj2' -> 'obj1.compare_to(obj2) == gt' 'obj1 <= obj2' -> 'obj1.compare_to(obj2) != gt' 'obj1 >= obj2' -> 'obj1.compare_to(obj2) != lt'Implementations of compare_to() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract:
if (obj1.compare_to(obj2) == eq)
obj1.equals(obj2) == true
obj1.hash_code == obj2.hash_code
else
obj1.equals(obj2) == false
endIf
Note that two "equal" objects *must* have the same hash code,
but "unequal" objects may or may not have the same hash code.
This default implementation throws an UnsupportedMethodError.
Handles duplicating this iterator when "duplicate(iterator_obj)" is called.
equals( Object other ).Boolean
Returns true if this object is equivalant to another.
has_another().BooleanThe compiler converts 'obj1 == obj2' into 'obj1.equals(obj2)' and 'obj1 != obj2' into 'not obj1.equals(obj2)'. Implementations of equals() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract: if (obj1.equals(obj2)) obj1.compare_to(obj2) == eq obj1.hash_code == obj2.hash_code else obj1.compare_to(obj2) != eq endIfNote that two "equal" objects *must* have the same hash code, but "unequal" objects may or may not have the same hash code. This default implementation returns true if the this object and the 'other' reference are the same object ('this is other').
Returns "true" if this reader has another value that can
be previewed with peek() or read with read().
hash_code().Int32
Returns the hash code of this object, which some classes
(like HashTable) rely on. This default implementation
throws an UnsupportedMethodError.
init( DataType first_value, DataType last_value )Hash codes are used to quickly test and see if two complex objects are NOT equal. The value returned has no intrinsic meaning, but should conform to the following rules: 1. Two objects that are equivalent should produce the same hash code. 2. If an object's state doesn't change, its hash code shouldn't change either. Internally, this precludes the hash code being based on an object's memory address since Slag doesn't guarantee that an object's address won't change over time. This has the following implications: If you override hash_code you should also override equals() and possibly compare_to() and ensure the following contract. Invariant:
if (obj1.hash_code != obj2.hash_code)
obj1.equals(obj2) == false
obj1.compare_to(obj2) != eq
endIf
peek().DataType
Returns the next value that will be returned from read().
If there is no next value then a NoNextValueError is thrown.
read().DataType
Returns the next value from this reader. If (not has_another)
then a NoNextValueError is thrown.
to_String().String
Returns:
type_name().StringA String representation of this object. Most classes should override this method to summarize an object's state for convenience in testing and debugging.
Returns the true class name of this object. Implemented by
the runtime; you should not override this method.
Example: local Object obj = "Hello World" println( obj.type_name ) #prints: String |
Base class for any 'enum'. See also "BitFlags"
NOTES The compiler converts:
enum FRUIT
CATEGORIES
apple, orange
...
endEnum
into:
class FRUIT : EnumeratedType<<FRUIT>>
CLASS_PROPERTIES
apple = set_up_def( FRUIT(), "apple" ) : FRUIT
orange = set_up_def( FRUIT(), "orange" ) : FRUIT
...
endClass
| Class Variables |
|---|
|
definitions : HashTable<<String,EnumType>>
Internal use - hashtable of names->categories.
values : EnumType[]
Internal use - a list of the category objects in this
enumeration.
|
| Class Methods |
|---|
|
by_name( String name ).EnumType
Returns the category object corresponding to the given string
name.
by_ordinal( Int32 ordinal ).EnumTypeContract:
FRUIT.by_name("banana") == FRUIT.banana
Returns the category object corresponding to the given
ordinal position.
create_duplicate( Object existing ).ObjectContract:
if (FRUIT.banana.ordinal == 2)
FRUIT.by_ordinal(2) == FRUIT.banana
endIf
This factory method initiates object duplication. The
compiler transforms the duplicate(obj) command into
Object.create_duplicate(obj).
includes( String name ).BooleanReturns: 'null' if 'existing' is null. existing.create_duplicate otherwise
Returns "true" if the given name is a category of this
enumeration.
set_up_def( EnumType enum_def, String name ).EnumTypeExample:
FRUIT.includes("carrot") -> false
Internal use.
|
| Object Variables |
|---|
|
name : String
The name of this category. This is a string with the
the same as the enum categery.
ordinal : Int32Suit.spades.name == "spades"
The positional index value of this enumeration category,
corresponding to the order that the categories were
declared in (starting at zero).
enum Suit
CATEGORIES
spades, hearts, clubs, diamonds
endEnum
... Suit.spades.ordinal == 0 Suit.diamonds.ordinal == 3 |
| Object Methods |
|---|
|
compare_to( Object other ).Ternary
This method is used for ordering (quantitative) comparisons
between this object and another.
compare_to( EnumType other ).TernaryReturns 'eq' if they're equivalent, 'lt' if this object is "less than" the other, or 'gt' if this object is "greater than" another. The compiler converts: 'obj1 < obj2' -> 'obj1.compare_to(obj2) == lt' 'obj1 > obj2' -> 'obj1.compare_to(obj2) == gt' 'obj1 <= obj2' -> 'obj1.compare_to(obj2) != gt' 'obj1 >= obj2' -> 'obj1.compare_to(obj2) != lt'Implementations of compare_to() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract:
if (obj1.compare_to(obj2) == eq)
obj1.equals(obj2) == true
obj1.hash_code == obj2.hash_code
else
obj1.equals(obj2) == false
endIf
Note that two "equal" objects *must* have the same hash code,
but "unequal" objects may or may not have the same hash code.
This default implementation throws an UnsupportedMethodError.
Returns the relative ordering (lt, eq, gt) of this enum's
ordinal versus the ordinal of the given enum.
create_duplicate().Object
Should create a duplicate of this object such that
obj1.equals(obj1.create_duplicate) return true.
equals( Object other ).BooleanThe command duplicate(obj) is transformed by the compiler into Object.create_duplicate(obj), which then calls this method. For optimal performance (by removing an internal typecast in most situations), have your overridden create_duplicate have the same return type as the class it's defined in. For instance, Strings implementation is 'create_duplicate.String'. This default implementation throws an UnsupportedMethodError.
Returns true if this object is equivalant to another.
hash_code().Int32The compiler converts 'obj1 == obj2' into 'obj1.equals(obj2)' and 'obj1 != obj2' into 'not obj1.equals(obj2)'. Implementations of equals() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract: if (obj1.equals(obj2)) obj1.compare_to(obj2) == eq obj1.hash_code == obj2.hash_code else obj1.compare_to(obj2) != eq endIfNote that two "equal" objects *must* have the same hash code, but "unequal" objects may or may not have the same hash code. This default implementation returns true if the this object and the 'other' reference are the same object ('this is other').
Returns the hash code of this object, which some classes
(like HashTable) rely on. This default implementation
throws an UnsupportedMethodError.
init()Hash codes are used to quickly test and see if two complex objects are NOT equal. The value returned has no intrinsic meaning, but should conform to the following rules: 1. Two objects that are equivalent should produce the same hash code. 2. If an object's state doesn't change, its hash code shouldn't change either. Internally, this precludes the hash code being based on an object's memory address since Slag doesn't guarantee that an object's address won't change over time. This has the following implications: If you override hash_code you should also override equals() and possibly compare_to() and ensure the following contract. Invariant:
if (obj1.hash_code != obj2.hash_code)
obj1.equals(obj2) == false
obj1.compare_to(obj2) != eq
endIf
Default initializer.
next().EnumType
Returns the category that was defined after this one.
next_in_cycle().EnumTypeExample: Suit.spades.next == Suit.hearts Suit.diamonds.next is null
Like 'next' but wraps around from the last to the first.
previous().EnumTypeExample: Suit.spades.next_in_cycle == Suit.hearts Suit.diamonds.next_in_cycle == Suit.spades
Returns the category that was defined before this one.
previous_in_cycle().EnumTypeExample: Suit.spades.previous is null Suit.diamonds.previous == Suit.clubs
Like 'previous' but wraps around from the last to the first.
to_String().StringExample: Suit.spades.previous_in_cycle == Suit.diamonds Suit.diamonds.previous_in_cycle == Suit.clubs
Returns 'name'
type_name().String
Returns the true class name of this object. Implemented by
the runtime; you should not override this method.
Example: local Object obj = "Hello World" println( obj.type_name ) #prints: String |
All built-in exceptions are extended from this Error class.
| Class Methods |
|---|
|
create_duplicate( Object existing ).Object
This factory method initiates object duplication. The
compiler transforms the duplicate(obj) command into
Object.create_duplicate(obj).
Returns: 'null' if 'existing' is null. existing.create_duplicate otherwise |
| Object Variables |
|---|
|
ip : Int64
The execution ip at the time of the exception. If generated
by Slag code this is "manually" calculated (as in
'Global.excecution_ip(-2)') or by the runtime environment
if generated by the VM or runtime.
message : String
The error message.
|
| Object Methods |
|---|
|
compare_to( Object other ).Ternary
This method is used for ordering (quantitative) comparisons
between this object and another.
create_duplicate().ObjectReturns 'eq' if they're equivalent, 'lt' if this object is "less than" the other, or 'gt' if this object is "greater than" another. The compiler converts: 'obj1 < obj2' -> 'obj1.compare_to(obj2) == lt' 'obj1 > obj2' -> 'obj1.compare_to(obj2) == gt' 'obj1 <= obj2' -> 'obj1.compare_to(obj2) != gt' 'obj1 >= obj2' -> 'obj1.compare_to(obj2) != lt'Implementations of compare_to() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract:
if (obj1.compare_to(obj2) == eq)
obj1.equals(obj2) == true
obj1.hash_code == obj2.hash_code
else
obj1.equals(obj2) == false
endIf
Note that two "equal" objects *must* have the same hash code,
but "unequal" objects may or may not have the same hash code.
This default implementation throws an UnsupportedMethodError.
Should create a duplicate of this object such that
obj1.equals(obj1.create_duplicate) return true.
equals( Object other ).BooleanThe command duplicate(obj) is transformed by the compiler into Object.create_duplicate(obj), which then calls this method. For optimal performance (by removing an internal typecast in most situations), have your overridden create_duplicate have the same return type as the class it's defined in. For instance, Strings implementation is 'create_duplicate.String'. This default implementation throws an UnsupportedMethodError.
Returns true if this object is equivalant to another.
hash_code().Int32The compiler converts 'obj1 == obj2' into 'obj1.equals(obj2)' and 'obj1 != obj2' into 'not obj1.equals(obj2)'. Implementations of equals() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract: if (obj1.equals(obj2)) obj1.compare_to(obj2) == eq obj1.hash_code == obj2.hash_code else obj1.compare_to(obj2) != eq endIfNote that two "equal" objects *must* have the same hash code, but "unequal" objects may or may not have the same hash code. This default implementation returns true if the this object and the 'other' reference are the same object ('this is other').
Returns the hash code of this object, which some classes
(like HashTable) rely on. This default implementation
throws an UnsupportedMethodError.
init( String message )Hash codes are used to quickly test and see if two complex objects are NOT equal. The value returned has no intrinsic meaning, but should conform to the following rules: 1. Two objects that are equivalent should produce the same hash code. 2. If an object's state doesn't change, its hash code shouldn't change either. Internally, this precludes the hash code being based on an object's memory address since Slag doesn't guarantee that an object's address won't change over time. This has the following implications: If you override hash_code you should also override equals() and possibly compare_to() and ensure the following contract. Invariant:
if (obj1.hash_code != obj2.hash_code)
obj1.equals(obj2) == false
obj1.compare_to(obj2) != eq
endIf
Stores the given error message.
init()
Sets the error message to an empty string.
to_String().String
Returns a description of the execution IP at the time
the error was thrown along with the error message.
type_name().String
Returns the true class name of this object. Implemented by
the runtime; you should not override this method.
Example: local Object obj = "Hello World" println( obj.type_name ) #prints: String |
The base class of all Error messages. An 'Exception' in Slag is equivalent to a RuntimeException in Java; there are no "checked exceptions" that *require* a try/catch block or a 'throws' clause. Most subclasses of Exception are derived from child class 'Error'.
| Class Methods |
|---|
|
create_duplicate( Object existing ).Object
This factory method initiates object duplication. The
compiler transforms the duplicate(obj) command into
Object.create_duplicate(obj).
Returns: 'null' if 'existing' is null. existing.create_duplicate otherwise |
| Object Variables |
|---|
|
ip : Int64
The execution ip at the time of the exception. If generated
by Slag code this is "manually" calculated (as in
'Global.excecution_ip(-2)') or by the runtime environment
if generated by the VM or runtime.
message : String
The error message.
|
| Object Methods |
|---|
|
compare_to( Object other ).Ternary
This method is used for ordering (quantitative) comparisons
between this object and another.
create_duplicate().ObjectReturns 'eq' if they're equivalent, 'lt' if this object is "less than" the other, or 'gt' if this object is "greater than" another. The compiler converts: 'obj1 < obj2' -> 'obj1.compare_to(obj2) == lt' 'obj1 > obj2' -> 'obj1.compare_to(obj2) == gt' 'obj1 <= obj2' -> 'obj1.compare_to(obj2) != gt' 'obj1 >= obj2' -> 'obj1.compare_to(obj2) != lt'Implementations of compare_to() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract:
if (obj1.compare_to(obj2) == eq)
obj1.equals(obj2) == true
obj1.hash_code == obj2.hash_code
else
obj1.equals(obj2) == false
endIf
Note that two "equal" objects *must* have the same hash code,
but "unequal" objects may or may not have the same hash code.
This default implementation throws an UnsupportedMethodError.
Should create a duplicate of this object such that
obj1.equals(obj1.create_duplicate) return true.
equals( Object other ).BooleanThe command duplicate(obj) is transformed by the compiler into Object.create_duplicate(obj), which then calls this method. For optimal performance (by removing an internal typecast in most situations), have your overridden create_duplicate have the same return type as the class it's defined in. For instance, Strings implementation is 'create_duplicate.String'. This default implementation throws an UnsupportedMethodError.
Returns true if this object is equivalant to another.
hash_code().Int32The compiler converts 'obj1 == obj2' into 'obj1.equals(obj2)' and 'obj1 != obj2' into 'not obj1.equals(obj2)'. Implementations of equals() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract: if (obj1.equals(obj2)) obj1.compare_to(obj2) == eq obj1.hash_code == obj2.hash_code else obj1.compare_to(obj2) != eq endIfNote that two "equal" objects *must* have the same hash code, but "unequal" objects may or may not have the same hash code. This default implementation returns true if the this object and the 'other' reference are the same object ('this is other').
Returns the hash code of this object, which some classes
(like HashTable) rely on. This default implementation
throws an UnsupportedMethodError.
init( String message )Hash codes are used to quickly test and see if two complex objects are NOT equal. The value returned has no intrinsic meaning, but should conform to the following rules: 1. Two objects that are equivalent should produce the same hash code. 2. If an object's state doesn't change, its hash code shouldn't change either. Internally, this precludes the hash code being based on an object's memory address since Slag doesn't guarantee that an object's address won't change over time. This has the following implications: If you override hash_code you should also override equals() and possibly compare_to() and ensure the following contract. Invariant:
if (obj1.hash_code != obj2.hash_code)
obj1.equals(obj2) == false
obj1.compare_to(obj2) != eq
endIf
Stores the given error message.
init()
Sets the error message to an empty string.
to_String().String
Returns a description of the execution IP at the time
the error was thrown along with the error message.
type_name().String
Returns the true class name of this object. Implemented by
the runtime; you should not override this method.
Example: local Object obj = "Hello World" println( obj.type_name ) #prints: String |
Used to specify different font styles when loading. The following styles are available:
fixed_width
Each character in a font strip is the same number of pixels
wide.
proportional
Each character in a font strip can have a different pixel
width.
linear_filter
Peforms linear filtering on each letter as it's drawn.
point_filter
Draws nearest-neighbor pixels. If this flag is omitted
then linear filtering is used.
snug
Adjusts the logical widths of all characters by -1 pixel
after loading; often appropriate for fonts with black
outlines. Without snug letters, two capital "M" characters
in a black-outline font might have two columns of black
pixels in-between them. With snug letters there would only
be one column.
Example:
high_score_font( "somefont.png",
FONT_STYLE.fixed_width | FONT_STYLE.snug ) : Font
| Categories |
|---|
|
fixed_width linear_filter point_filter proportional snug |
| Class Variables |
|---|
|
default_next_flag : Int32 definitions : HashTable<<String,EnumType>>
Internal use - hashtable of names->categories.
values : EnumType[]
Internal use - a list of the category objects in this
enumeration.
|
| Class Methods |
|---|
|
by_name( String name ).EnumType
Returns the category object corresponding to the given string
name.
by_ordinal( Int32 ordinal ).EnumTypeContract:
FRUIT.by_name("banana") == FRUIT.banana
Returns the category object corresponding to the given
ordinal position.
create_duplicate( Object existing ).ObjectContract:
if (FRUIT.banana.ordinal == 2)
FRUIT.by_ordinal(2) == FRUIT.banana
endIf
This factory method initiates object duplication. The
compiler transforms the duplicate(obj) command into
Object.create_duplicate(obj).
includes( String name ).BooleanReturns: 'null' if 'existing' is null. existing.create_duplicate otherwise
Returns "true" if the given name is a category of this
enumeration.
set_up_def( EnumType enum_def, String name ).EnumTypeExample:
FRUIT.includes("carrot") -> false
Internal use.
|
| Object Variables |
|---|
|
flags : Int32 name : String
The name of this category. This is a string with the
the same as the enum categery.
ordinal : Int32Suit.spades.name == "spades"
The positional index value of this enumeration category,
corresponding to the order that the categories were
declared in (starting at zero).
enum Suit
CATEGORIES
spades, hearts, clubs, diamonds
endEnum
... Suit.spades.ordinal == 0 Suit.diamonds.ordinal == 3 |
| Object Methods |
|---|
|
compare_to( EnumType other ).Ternary
Returns the relative ordering (lt, eq, gt) of this enum's
ordinal versus the ordinal of the given enum.
compare_to( Object other ).Ternary
This method is used for ordering (quantitative) comparisons
between this object and another.
create_duplicate().ObjectReturns 'eq' if they're equivalent, 'lt' if this object is "less than" the other, or 'gt' if this object is "greater than" another. The compiler converts: 'obj1 < obj2' -> 'obj1.compare_to(obj2) == lt' 'obj1 > obj2' -> 'obj1.compare_to(obj2) == gt' 'obj1 <= obj2' -> 'obj1.compare_to(obj2) != gt' 'obj1 >= obj2' -> 'obj1.compare_to(obj2) != lt'Implementations of compare_to() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract:
if (obj1.compare_to(obj2) == eq)
obj1.equals(obj2) == true
obj1.hash_code == obj2.hash_code
else
obj1.equals(obj2) == false
endIf
Note that two "equal" objects *must* have the same hash code,
but "unequal" objects may or may not have the same hash code.
This default implementation throws an UnsupportedMethodError.
Should create a duplicate of this object such that
obj1.equals(obj1.create_duplicate) return true.
equals( EnumType other ).BooleanThe command duplicate(obj) is transformed by the compiler into Object.create_duplicate(obj), which then calls this method. For optimal performance (by removing an internal typecast in most situations), have your overridden create_duplicate have the same return type as the class it's defined in. For instance, Strings implementation is 'create_duplicate.String'. This default implementation throws an UnsupportedMethodError. equals( Object other ).Boolean equals( Int32 other_flags ).Boolean hash_code().Int32
Returns the hash code of this object, which some classes
(like HashTable) rely on. This default implementation
throws an UnsupportedMethodError.
includes( EnumType other ).BooleanHash codes are used to quickly test and see if two complex objects are NOT equal. The value returned has no intrinsic meaning, but should conform to the following rules: 1. Two objects that are equivalent should produce the same hash code. 2. If an object's state doesn't change, its hash code shouldn't change either. Internally, this precludes the hash code being based on an object's memory address since Slag doesn't guarantee that an object's address won't change over time. This has the following implications: If you override hash_code you should also override equals() and possibly compare_to() and ensure the following contract. Invariant:
if (obj1.hash_code != obj2.hash_code)
obj1.equals(obj2) == false
obj1.compare_to(obj2) != eq
endIf
Returns "true" if this category contains any of the
bitflags from the 'other' category.
includes( Int32 other_flags ).Boolean
Returns "true" if this category contains any of the
bitflags from 'other_flags'.
init( EnumType existing )init( Int32 flags ) init() next().EnumType
Returns the category that was defined after this one.
next_in_cycle().EnumTypeExample: Suit.spades.next == Suit.hearts Suit.diamonds.next is null
Like 'next' but wraps around from the last to the first.
op!().EnumTypeExample: Suit.spades.next_in_cycle == Suit.hearts Suit.diamonds.next_in_cycle == Suit.spades
Returns a new category that contains the inverse
of this category's bitflags.
op&( Int32 other_flags ).EnumType
Returns a new category that contains the intersection
of bitflags from this category and 'other_flags'.
op&( EnumType other ).EnumType
Returns a new category that contains the intersection
of bitflags from this category and the 'other' category.
op|( Int32 other_flags ).EnumType
Returns a new category that includes all the bitflags
from this category and 'other_flags'.
op|( EnumType other ).EnumType
Returns a new category that includes all the bitflags
from this category and the 'other' category.
previous().EnumType
Returns the category that was defined before this one.
previous_in_cycle().EnumTypeExample: Suit.spades.previous is null Suit.diamonds.previous == Suit.clubs
Like 'previous' but wraps around from the last to the first.
to_String().StringExample: Suit.spades.previous_in_cycle == Suit.diamonds Suit.diamonds.previous_in_cycle == Suit.clubs
Returns a string containing the names of all comma-separated
categories included in this category's bitflags.
type_name().String
Returns the true class name of this object. Implemented by
the runtime; you should not override this method.
Example: local Object obj = "Hello World" println( obj.type_name ) #prints: String |
Represents a potential file in the operating system. A File object is created with a filepath; a file of that name may or may not exist yet.
A file object is both Readable and Writable as an input and output for characters.
Class File uses the following terminology:
filename
The name of a file without any location information.
path
The directory location where the file is stored.
filepath
A filename with path information.
Example:
# print every character in a file "test.txt"
forEach (ch in File("test.txt")) print( ch )
Example:
class RecursiveDirectoryListing
METHODS
method init:
# Recursively lists files starting in the current directory
list( "." )
method list( String filepath ):
local File file(filepath)
file.filepath = file.absolute_filepath
println( file.filepath )
if (file.is_directory)
forEach (entry in file.directory_listing)
list("$/$" (file.filepath,entry))
endForEach
endIf
endClass
| Class Methods |
|---|
|
create_duplicate( Object existing ).Object
This factory method initiates object duplication. The
compiler transforms the duplicate(obj) command into
Object.create_duplicate(obj).
native_absolute_filepath( String filepath ).StringReturns: 'null' if 'existing' is null. existing.create_duplicate otherwise
Internal use.
native_directory_listing( String path, String[] contents )
Internal use.
native_is_directory( String filepath ).Boolean
Internal use.
|
| Object Variables |
|---|
|
filepath : String
The filepath of this file.
|
| Object Methods |
|---|
|
absolute_filepath().String
Returns the absolute filepath (path + file) of this file.
absolute_path().StringNote: If a filepath doesn't exist it will still be fleshed out with the current full path to allow this method to work with non-existent output files that will be created.
Returns the absolute path denoted by this File object.
compare_to( Object other ).Ternary
This method is used for ordering (quantitative) comparisons
between this object and another.
create_duplicate().ObjectReturns 'eq' if they're equivalent, 'lt' if this object is "less than" the other, or 'gt' if this object is "greater than" another. The compiler converts: 'obj1 < obj2' -> 'obj1.compare_to(obj2) == lt' 'obj1 > obj2' -> 'obj1.compare_to(obj2) == gt' 'obj1 <= obj2' -> 'obj1.compare_to(obj2) != gt' 'obj1 >= obj2' -> 'obj1.compare_to(obj2) != lt'Implementations of compare_to() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract:
if (obj1.compare_to(obj2) == eq)
obj1.equals(obj2) == true
obj1.hash_code == obj2.hash_code
else
obj1.equals(obj2) == false
endIf
Note that two "equal" objects *must* have the same hash code,
but "unequal" objects may or may not have the same hash code.
This default implementation throws an UnsupportedMethodError.
Should create a duplicate of this object such that
obj1.equals(obj1.create_duplicate) return true.
create_reader().FileReaderThe command duplicate(obj) is transformed by the compiler into Object.create_duplicate(obj), which then calls this method. For optimal performance (by removing an internal typecast in most situations), have your overridden create_duplicate have the same return type as the class it's defined in. For instance, Strings implementation is 'create_duplicate.String'. This default implementation throws an UnsupportedMethodError.
Creates and returns a character reader for this file which
opens the corresponding file in the operating system for
reading.
create_writer().PrintWriterIf the file doesn't exist or if there's some other error then a FileError exception is thrown.
Creates and returns a character writer for this file which
opens the corresponding file in the operating system for
writing.
directory_listing().String[]If an error occurs then a FileError exception is thrown.
Returns a list of filenames and directory names contained
within the directory represented by this File object. Throws
a FileError if this file does not denote a valid directory.
equals( Object other ).BooleanNote: the list of entries returned will not contain the current directory "." or the parent directory "..".
Returns true if this object is equivalant to another.
exists().BooleanThe compiler converts 'obj1 == obj2' into 'obj1.equals(obj2)' and 'obj1 != obj2' into 'not obj1.equals(obj2)'. Implementations of equals() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract: if (obj1.equals(obj2)) obj1.compare_to(obj2) == eq obj1.hash_code == obj2.hash_code else obj1.compare_to(obj2) != eq endIfNote that two "equal" objects *must* have the same hash code, but "unequal" objects may or may not have the same hash code. This default implementation returns true if the this object and the 'other' reference are the same object ('this is other').
Returns whether or not this file already exists within the
operating system.
filename().String
Returns the filename (without path information) denoted by
this File.
hash_code().Int32
Returns the hash code of this object, which some classes
(like HashTable) rely on. This default implementation
throws an UnsupportedMethodError.
init( String filepath )Hash codes are used to quickly test and see if two complex objects are NOT equal. The value returned has no intrinsic meaning, but should conform to the following rules: 1. Two objects that are equivalent should produce the same hash code. 2. If an object's state doesn't change, its hash code shouldn't change either. Internally, this precludes the hash code being based on an object's memory address since Slag doesn't guarantee that an object's address won't change over time. This has the following implications: If you override hash_code you should also override equals() and possibly compare_to() and ensure the following contract. Invariant:
if (obj1.hash_code != obj2.hash_code)
obj1.equals(obj2) == false
obj1.compare_to(obj2) != eq
endIf
Initializes this file object with the given filepath. No
operating system files are actually opened or created yet.
is_directory().Boolean
Returns "true" if the path of this file specifies a directory.
path().String
Returns the path denoted by this File object. This may be relative
or absolute depending on the string passed into the initializer.
At a minimum, the relative path "." will be returned.
to_List().DataType[]
Converts this Readable data into a list. Creates a reader
and fowards the call to it.
to_String().String
Returns the original filepath of this File object.
type_name().String
Returns the true class name of this object. Implemented by
the runtime; you should not override this method.
Example: local Object obj = "Hello World" println( obj.type_name ) #prints: String |
| Class Methods |
|---|
|
create_duplicate( Object existing ).Object
This factory method initiates object duplication. The
compiler transforms the duplicate(obj) command into
Object.create_duplicate(obj).
Returns: 'null' if 'existing' is null. existing.create_duplicate otherwise |
| Object Variables |
|---|
|
ip : Int64
The execution ip at the time of the exception. If generated
by Slag code this is "manually" calculated (as in
'Global.excecution_ip(-2)') or by the runtime environment
if generated by the VM or runtime.
message : String
The error message.
|
| Object Methods |
|---|
|
compare_to( Object other ).Ternary
This method is used for ordering (quantitative) comparisons
between this object and another.
create_duplicate().ObjectReturns 'eq' if they're equivalent, 'lt' if this object is "less than" the other, or 'gt' if this object is "greater than" another. The compiler converts: 'obj1 < obj2' -> 'obj1.compare_to(obj2) == lt' 'obj1 > obj2' -> 'obj1.compare_to(obj2) == gt' 'obj1 <= obj2' -> 'obj1.compare_to(obj2) != gt' 'obj1 >= obj2' -> 'obj1.compare_to(obj2) != lt'Implementations of compare_to() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract:
if (obj1.compare_to(obj2) == eq)
obj1.equals(obj2) == true
obj1.hash_code == obj2.hash_code
else
obj1.equals(obj2) == false
endIf
Note that two "equal" objects *must* have the same hash code,
but "unequal" objects may or may not have the same hash code.
This default implementation throws an UnsupportedMethodError.
Should create a duplicate of this object such that
obj1.equals(obj1.create_duplicate) return true.
equals( Object other ).BooleanThe command duplicate(obj) is transformed by the compiler into Object.create_duplicate(obj), which then calls this method. For optimal performance (by removing an internal typecast in most situations), have your overridden create_duplicate have the same return type as the class it's defined in. For instance, Strings implementation is 'create_duplicate.String'. This default implementation throws an UnsupportedMethodError.
Returns true if this object is equivalant to another.
hash_code().Int32The compiler converts 'obj1 == obj2' into 'obj1.equals(obj2)' and 'obj1 != obj2' into 'not obj1.equals(obj2)'. Implementations of equals() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract: if (obj1.equals(obj2)) obj1.compare_to(obj2) == eq obj1.hash_code == obj2.hash_code else obj1.compare_to(obj2) != eq endIfNote that two "equal" objects *must* have the same hash code, but "unequal" objects may or may not have the same hash code. This default implementation returns true if the this object and the 'other' reference are the same object ('this is other').
Returns the hash code of this object, which some classes
(like HashTable) rely on. This default implementation
throws an UnsupportedMethodError.
init( [String message] )Hash codes are used to quickly test and see if two complex objects are NOT equal. The value returned has no intrinsic meaning, but should conform to the following rules: 1. Two objects that are equivalent should produce the same hash code. 2. If an object's state doesn't change, its hash code shouldn't change either. Internally, this precludes the hash code being based on an object's memory address since Slag doesn't guarantee that an object's address won't change over time. This has the following implications: If you override hash_code you should also override equals() and possibly compare_to() and ensure the following contract. Invariant:
if (obj1.hash_code != obj2.hash_code)
obj1.equals(obj2) == false
obj1.compare_to(obj2) != eq
endIf
Initializes this FileError with the given error message.
init()
Sets the error message to an empty string.
to_String().String
Returns a description of the execution IP at the time
the error was thrown along with the error message.
type_name().String
Returns the true class name of this object. Implemented by
the runtime; you should not override this method.
Example: local Object obj = "Hello World" println( obj.type_name ) #prints: String |
Reads one character at a time from a file.
| Class Methods |
|---|
|
create_duplicate( Object existing ).Object
This factory method initiates object duplication. The
compiler transforms the duplicate(obj) command into
Object.create_duplicate(obj).
native_close( Int32 handle )Returns: 'null' if 'existing' is null. existing.create_duplicate otherwise
Internal use.
native_file_size( Int32 handle ).Int32
Internal use.
native_open( String filename ).Int32
Internal use.
native_read( Int32 handle ).Int32
Internal use.
native_skip( Int32 handle, Int32 amount )
Internal use.
|
| Object Variables |
|---|
|
file_handle : Int32
The integer that the native layer uses to track this file.
next : Char
The next character that will be returned from read().
pos : Int32
Counts the number of characters that have been read.
total_size : Int32
The total number of characters in the file.
|
| Object Methods |
|---|
|
available().Int32
Returns the remaining number of characters in this file
since file readers don't block.
clean_up()
Called when there are no more references to this object;
closes the file.
close()
Closes this file; no more data may be read from this reader.
compare_to( Object other ).Ternary
This method is used for ordering (quantitative) comparisons
between this object and another.
consume( DataType look_for ).BooleanReturns 'eq' if they're equivalent, 'lt' if this object is "less than" the other, or 'gt' if this object is "greater than" another. The compiler converts: 'obj1 < obj2' -> 'obj1.compare_to(obj2) == lt' 'obj1 > obj2' -> 'obj1.compare_to(obj2) == gt' 'obj1 <= obj2' -> 'obj1.compare_to(obj2) != gt' 'obj1 >= obj2' -> 'obj1.compare_to(obj2) != lt'Implementations of compare_to() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract:
if (obj1.compare_to(obj2) == eq)
obj1.equals(obj2) == true
obj1.hash_code == obj2.hash_code
else
obj1.equals(obj2) == false
endIf
Note that two "equal" objects *must* have the same hash code,
but "unequal" objects may or may not have the same hash code.
This default implementation throws an UnsupportedMethodError.
Attempts to match and discard the next value from this
reader, returning true, or else leaves the next value still
pending and returns false.
create_duplicate().ObjectReturns: "true" if old.peek == look_for "false" if old.peek != look_forInvariant: if (old.peek == look_for) old.skip
Should create a duplicate of this object such that
obj1.equals(obj1.create_duplicate) return true.
equals( Object other ).BooleanThe command duplicate(obj) is transformed by the compiler into Object.create_duplicate(obj), which then calls this method. For optimal performance (by removing an internal typecast in most situations), have your overridden create_duplicate have the same return type as the class it's defined in. For instance, Strings implementation is 'create_duplicate.String'. This default implementation throws an UnsupportedMethodError.
Returns true if this object is equivalant to another.
has_another().BooleanThe compiler converts 'obj1 == obj2' into 'obj1.equals(obj2)' and 'obj1 != obj2' into 'not obj1.equals(obj2)'. Implementations of equals() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract: if (obj1.equals(obj2)) obj1.compare_to(obj2) == eq obj1.hash_code == obj2.hash_code else obj1.compare_to(obj2) != eq endIfNote that two "equal" objects *must* have the same hash code, but "unequal" objects may or may not have the same hash code. This default implementation returns true if the this object and the 'other' reference are the same object ('this is other').
Returns "true" if this reader has another value that can
be previewed with peek() or read with read().
hash_code().Int32
Returns the hash code of this object, which some classes
(like HashTable) rely on. This default implementation
throws an UnsupportedMethodError.
init( String filename )Hash codes are used to quickly test and see if two complex objects are NOT equal. The value returned has no intrinsic meaning, but should conform to the following rules: 1. Two objects that are equivalent should produce the same hash code. 2. If an object's state doesn't change, its hash code shouldn't change either. Internally, this precludes the hash code being based on an object's memory address since Slag doesn't guarantee that an object's address won't change over time. This has the following implications: If you override hash_code you should also override equals() and possibly compare_to() and ensure the following contract. Invariant:
if (obj1.hash_code != obj2.hash_code)
obj1.equals(obj2) == false
obj1.compare_to(obj2) != eq
endIf
Opens the given file and preps this reader to read it.
is_exhausted().BooleanIf the file doesn't exist or if there are other problems then a FileError will be thrown.
Returns "true" if this reader does not have another value
or "false" if it does.
peek().Char
Returns the next value that will be returned from read().
If there is no next value then a NoNextValueError is thrown.
position( Int32 new_position )
Sets this position of this file. File readers can only be
repositioned further on in the file.
position().Int32
Returns the position of this file - equivalent to the
number of characters read so far.
read().Char
Returns the next character from the associated file.
read_line().String
Reads and returns the next line of characters up to the next
LF or CRLF. The CRLF characters are not part of
the return value and are discarded.
read_list( Int32 size ).DataType[]Only defined for Reader<<Char>>.
Reads the next 'size' number of values and returns them in a
list. Requires that there are at least 'size' number of
values remaining to be read.
remaining().Int32
Returns the remaining number of characters in this file.
rewind()
This optional method resets this reader so that the next
read() will return the first value of the series.
Readers that don't implement this property will throw an
UnsupportedMethodError when it's accessed.
skip( [Int32 skip_count] )
Discards exactly the next 'skip_count' number of values
rather than reading them. If there are not enough values
remaining then a NoNextValueError will be thrown from read().
to_List().DataType[]This program fragment: local var a = reader.read reader.read reader.read local var b = reader.readis equivalent to this: local var a = reader.read reader.skip(2) local var b = reader.read
Creates and returns a list of all the remaining values of
this reader.
to_String().String
Returns a string representation of this reader's values.
type_name().String
Returns the true class name of this object. Implemented by
the runtime; you should not override this method.
Example: local Object obj = "Hello World" println( obj.type_name ) #prints: String |
Subclass of PrintWriter that prints to a file. Created by a call to File::create_writer.
| Class Methods |
|---|
|
create_duplicate( Object existing ).Object
This factory method initiates object duplication. The
compiler transforms the duplicate(obj) command into
Object.create_duplicate(obj).
native_close( Int32 handle )Returns: 'null' if 'existing' is null. existing.create_duplicate otherwise
Internal use.
native_open( String filename ).Int32
Internal use.
native_write( Int32 handle, Int32 datum )
Internal use.
|
| Object Variables |
|---|
|
file_handle : Int32
Internal use.
pos : Int32
Equivalent to the number of characters that have been written.
|
| Object Methods |
|---|
|
capacity().Int32
Returns the minimum number of additional values that can
written with this writer, or (-1) for "unlimited".
clean_up()
Closes the writer. Base aspect Writer does not incorporate
the RequiresCleanup interface, but types for writers that do
this method will be called when there are no more references
to the object.
close()
Closes the file. This should be called after all desired
data has been written to the file.
compare_to( Object other ).Ternary
This method is used for ordering (quantitative) comparisons
between this object and another.
create_duplicate().ObjectReturns 'eq' if they're equivalent, 'lt' if this object is "less than" the other, or 'gt' if this object is "greater than" another. The compiler converts: 'obj1 < obj2' -> 'obj1.compare_to(obj2) == lt' 'obj1 > obj2' -> 'obj1.compare_to(obj2) == gt' 'obj1 <= obj2' -> 'obj1.compare_to(obj2) != gt' 'obj1 >= obj2' -> 'obj1.compare_to(obj2) != lt'Implementations of compare_to() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract:
if (obj1.compare_to(obj2) == eq)
obj1.equals(obj2) == true
obj1.hash_code == obj2.hash_code
else
obj1.equals(obj2) == false
endIf
Note that two "equal" objects *must* have the same hash code,
but "unequal" objects may or may not have the same hash code.
This default implementation throws an UnsupportedMethodError.
Should create a duplicate of this object such that
obj1.equals(obj1.create_duplicate) return true.
equals( Object other ).BooleanThe command duplicate(obj) is transformed by the compiler into Object.create_duplicate(obj), which then calls this method. For optimal performance (by removing an internal typecast in most situations), have your overridden create_duplicate have the same return type as the class it's defined in. For instance, Strings implementation is 'create_duplicate.String'. This default implementation throws an UnsupportedMethodError.
Returns true if this object is equivalant to another.
flush()The compiler converts 'obj1 == obj2' into 'obj1.equals(obj2)' and 'obj1 != obj2' into 'not obj1.equals(obj2)'. Implementations of equals() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract: if (obj1.equals(obj2)) obj1.compare_to(obj2) == eq obj1.hash_code == obj2.hash_code else obj1.compare_to(obj2) != eq endIfNote that two "equal" objects *must* have the same hash code, but "unequal" objects may or may not have the same hash code. This default implementation returns true if the this object and the 'other' reference are the same object ('this is other').
Orders the writer to write out any buffered data in
preparations for closing the writer.
hash_code().Int32Invariant: close() should always call flush() first.
Returns the hash code of this object, which some classes
(like HashTable) rely on. This default implementation
throws an UnsupportedMethodError.
holds_has_another().BooleanHash codes are used to quickly test and see if two complex objects are NOT equal. The value returned has no intrinsic meaning, but should conform to the following rules: 1. Two objects that are equivalent should produce the same hash code. 2. If an object's state doesn't change, its hash code shouldn't change either. Internally, this precludes the hash code being based on an object's memory address since Slag doesn't guarantee that an object's address won't change over time. This has the following implications: If you override hash_code you should also override equals() and possibly compare_to() and ensure the following contract. Invariant:
if (obj1.hash_code != obj2.hash_code)
obj1.equals(obj2) == false
obj1.compare_to(obj2) != eq
endIf
Returns "true".
init( String filename )
Initializes this writer to write to the specified file.
The file is opened for writing; close() should be called
when finished.
position( Int32 new_pos )If there's an error opening the file then a FileError() is thrown.
This optional property-write sets the zero-based write
position. It is up to the implementation to define how
repositioning works with gaps and what happens to data at a
later spot after a reposition to an earlier spot.
position().Int32Not all writers implement this property; those that don't will throw an UnsupportedMethodError when it's accessed.
This property-read returns the position of the file,
equivalent to the number of characters that have been written
thus far.
print( Int64 n )
Prints the given Int64 in text form.
print( Degrees deg )
Prints out the given degrees value.
print( Boolean n )
Prints the given Boolean in text form as "true" or "false".
print( Char ch )
Prints the given Char. The symbol corresponding
to the Unicode value of 'n' will be displayed.
print( Real32 n )
Prints the given Real32 in text form.
print( Vector2 v )
Prints 'v' in text form.
print( Byte n )
Prints the given Byte in text form.
print( Color c )
Prints 'c' in text form.
print( RealColor argb )
Prints 'argb' in text form.
print( HSV hsv )
Prints 'hsv' in text form.
print( Real64 n )
Prints the given Real64 in text form.
print( Quad q )
Prints 'q' in text form.
print( ParsePos p )
Prints the given ParsePos in text form.
print( Object obj )
Prints the to_String representation of the given object, or
else the world "null" if the 'obj' reference is null.
print( Line line )
Prints 'line' in text form.
print( Readable<<Char>> readable )
Prints out every character in the Readable data.
print( Corners c )
Prints 'v' in text form.
print( String st )
Prints the given String.
print( Rect r )
Prints 'r' in text form.
print( Ternary n )
Prints the given Ternary in text form as "yes", "no", or
"void".
print( Radians rad )
Prints out the given radians value.
print( Circle circle )
Prints 'circle in text form.
print( Reader<<Char>> reader )
Prints out every character that can be obtained from the
reader.
println( Object obj )
Prints the given object's to_String value and advances
the cursor to the next line.
println( RealColor argb )
Prints 'argb' in text form and advances the cursor to the next
line.
println( Readable<<Char>> readable )
Prints out every character in the Readable data and advances
the cursor to the next line.
println( Real64 n )
Prints the given Real64 value and advances the cursor to the
next line.
println( Ternary n )
Prints the given Ternary value and advances the cursor to the
next line.
println( Radians rad )
Prints out the given radians value and advances the cursor
to the next line.
println( Byte n )
Prints the given Byte value and advances the cursor to the
next line.
println( String st )
Prints the given String value and advances the cursor to the
next line.
println( Boolean n )
Prints the given Boolean value and advances the cursor to the
next line.
println( Degrees deg )
Prints out the given degrees value and advances the cursor
to the next line.
println( Quad q )
Prints 'q' in text form and advances the cursor to the next
line.
println( Corners c )
Prints 'v' in text form and advances the cursor to the next
line.
println( Vector2 v )
Prints 'v' in text form and advances the cursor to the next
line.
println( Int64 n )
Prints the given Int64 value and advances the cursor to the
next line.
println( Rect r )
Prints 'r' in text form and advances the cursor to the next
line.
println( Line line )
Prints 'line' in text form and advances the cursor to the
next line of text output.
println( Circle circle )
Prints 'circle' in text form and advances the cursor to the
next circle of text output.
println( Color c )
Prints 'c' in text form and advances the cursor to the next
line.
println( Char n )
Prints the given Char value and advances the cursor to the
next line.
println()
Advances the cursor to the next line.
println( ParsePos p )
Prints the given ParsePos in text form and advances the
cursor to the next line.
println( Reader<<Char>> reader )
Prints out every character that can be obtained from the
reader and advances the cursor to the next line.
println( HSV hsv )
Prints 'hsv' in text form and advances the cursor to the next
line.
skip( Int32 skip_count )
This optional method repositions the writer to be
'skip_count' values further along.
to_String().StringIf a writer does not implement the 'position' property then an UnsupportedMethodError will be generated when skip() is called.
Returns:
type_name().StringA String representation of this object. Most classes should override this method to summarize an object's state for convenience in testing and debugging.
Returns the true class name of this object. Implemented by
the runtime; you should not override this method.
write( Char value )Example: local Object obj = "Hello World" println( obj.type_name ) #prints: String
Writes 'value' in 8 bits.
write( DataType value )
Outputs 'value' in an implementation-specific way.
Requires: holds_has_another == true |
Manages a bitmapped font. A font loads png or jpeg images containing font strips, breaks up the letters, arranges them onto square textures, and draws the images piece by piece as needed.
Fonts can be loaded as proportional or non-proportional. All letters in a font must have the same height (though parts of that area can be blank/transparent). The drawing origin of every character is the top-left corner.
The image width of a non-proportional font is divided by the number of characters in it to determine the character width.
A proportional font has a single-pixel-high band of alternating colors in the topmost row. The length of any contiguous patch of the same color determines the width of the character underneath. The actual color used does not matter.
Since font strips tend to be images that are too long for texture hardware to support, every font is automatically broken up and laid out on square textures up to 256x256 in size. Any empty pixels around each letter are removed before laying out the letter on a texture.
Either point filtering or linear filtering can be selected for a font. If linear filtering is chosen, an extra outline of padding is added around each letter before it is laid out to avoid color bleeding.
Copy and paste the following letter strip in Photoshop or another paint program to get started on a font strip. Notice the first character is a space; if you accidentally leave it out then all your letters will be one position off.
!"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~
| Class Methods |
|---|
|
create_duplicate( Object existing ).Object
This factory method initiates object duplication. The
compiler transforms the duplicate(obj) command into
Object.create_duplicate(obj).
Returns: 'null' if 'existing' is null. existing.create_duplicate otherwise |
| Object Variables |
|---|
|
characters : HashTable<<Char,FontCharacter>> color : Color
The multiplier for each pixel in this font as it's drawn.
The default color of new_Color(255,255,255,255) ensures that
the font will appear "normal". A color of
new_Color(255,255,0) would not draw any of the blue channel,
making a grey-scale letter appear to be tinted yellow. A color
of new_Color(255,255,255,128) would draw the letters halfway
transparent.
height : Int32
The original pixel height of each character in the font.
scale : Vector2
The size multiplier for rendering, (1.0,1.0) by default.
Setting "scale = Vector2(2.0,0.5)" would cause the font to
render at twice the width and half the height.
|
| Object Methods |
|---|
|
adjust_character_widths( Int32 amount )
Adjusts the logical widths of all the characters in this
font. A positive value will space characters further apart
while a negative value will scoot them closer together.
compare_to( Object other ).Ternary
This method is used for ordering (quantitative) comparisons
between this object and another.
create_duplicate().ObjectReturns 'eq' if they're equivalent, 'lt' if this object is "less than" the other, or 'gt' if this object is "greater than" another. The compiler converts: 'obj1 < obj2' -> 'obj1.compare_to(obj2) == lt' 'obj1 > obj2' -> 'obj1.compare_to(obj2) == gt' 'obj1 <= obj2' -> 'obj1.compare_to(obj2) != gt' 'obj1 >= obj2' -> 'obj1.compare_to(obj2) != lt'Implementations of compare_to() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract:
if (obj1.compare_to(obj2) == eq)
obj1.equals(obj2) == true
obj1.hash_code == obj2.hash_code
else
obj1.equals(obj2) == false
endIf
Note that two "equal" objects *must* have the same hash code,
but "unequal" objects may or may not have the same hash code.
This default implementation throws an UnsupportedMethodError.
Should create a duplicate of this object such that
obj1.equals(obj1.create_duplicate) return true.
draw( Char ch, Vector2 pos ).Real64The command duplicate(obj) is transformed by the compiler into Object.create_duplicate(obj), which then calls this method. For optimal performance (by removing an internal typecast in most situations), have your overridden create_duplicate have the same return type as the class it's defined in. For instance, Strings implementation is 'create_duplicate.String'. This default implementation throws an UnsupportedMethodError.
Draws the given character with its top-left corner at the
specified position.
draw( String st, Vector2 pos )Returns the pixel width of the drawn character.
Draws the given string of characters to the screen with the
top-left corner of the first character at the given position.
draw_center( String st, Vector2 pos, Real64 field_width )
Draws the given string centered in the given
field width. 'pos' is the top-left corner of the field.
draw_center( String st, Vector2 pos )
Draws the given string to the screen with the
top-center of all the characters at the given position.
draw_line( String st, Vector2 pos )
Internal use. Draws a single line of text with its top-left
corner at position 'pos'.
draw_right( String st, Vector2 pos )
Draws the given string right-justified with its right
edge at 'pos'.
draw_right( String st, Vector2 pos, Real64 field_width )
Draws the given string right-justified in a field with the
given top-left 'pos' and width.
equals( Object other ).Boolean
Returns true if this object is equivalant to another.
hash_code().Int32The compiler converts 'obj1 == obj2' into 'obj1.equals(obj2)' and 'obj1 != obj2' into 'not obj1.equals(obj2)'. Implementations of equals() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract: if (obj1.equals(obj2)) obj1.compare_to(obj2) == eq obj1.hash_code == obj2.hash_code else obj1.compare_to(obj2) != eq endIfNote that two "equal" objects *must* have the same hash code, but "unequal" objects may or may not have the same hash code. This default implementation returns true if the this object and the 'other' reference are the same object ('this is other').
Returns the hash code of this object, which some classes
(like HashTable) rely on. This default implementation
throws an UnsupportedMethodError.
height().Real64Hash codes are used to quickly test and see if two complex objects are NOT equal. The value returned has no intrinsic meaning, but should conform to the following rules: 1. Two objects that are equivalent should produce the same hash code. 2. If an object's state doesn't change, its hash code shouldn't change either. Internally, this precludes the hash code being based on an object's memory address since Slag doesn't guarantee that an object's address won't change over time. This has the following implications: If you override hash_code you should also override equals() and possibly compare_to() and ensure the following contract. Invariant:
if (obj1.hash_code != obj2.hash_code)
obj1.equals(obj2) == false
obj1.compare_to(obj2) != eq
endIf
Height property-get. Returns the original pixel height
times the y-scale value.
init( HashTable<<Char,FontCharacter>> characters, Int32 height )
Initializes this font with an existing lookup table of
Char->FontCharacter mappings and a font height.
init( String filename, [FONT_STYLE style], [String mapping] )
Intializes this font from characters in the given font strip.
scale( Vector2 new_scale )Parameters:
filename
A png or jpeg file containing a strip of characters.
If you want to create a single font out of several different
font strips, use a FontBuilder instead.
Scale property-set.
scale( Real64 uniform_scale )
Scale property-set.
text_width_of( Char ch ).Real64
Returns the render width of 'ch' in pixels, taking the
current scale into account.
text_width_of( String text ).Real64
Returns the render width of 'text' in pixels, taking the
current scale into account.
to_String().String
Returns:
type_name().StringA String representation of this object. Most classes should override this method to summarize an object's state for convenience in testing and debugging.
Returns the true class name of this object. Implemented by
the runtime; you should not override this method.
Example: local Object obj = "Hello World" println( obj.type_name ) #prints: String |
Utility class used to load fonts; used by class Font for loading fonts with single font-strip images. To load a font with a series of font-strip images you can use this class directly.
Example:
Say that "letters.png" contains 26 fixed-width letter images and "numbers.png" contains 10 fixed-with number images.PROPERTIES my_font : Font ... local FontBuilder builder() builder.load( "letters.png", String('A'..'Z') ) builder.load( "numbers.png", String('0'..'9') ) my_font = builder.to_Font
| Class Methods |
|---|
|
create_duplicate( Object existing ).Object
This factory method initiates object duplication. The
compiler transforms the duplicate(obj) command into
Object.create_duplicate(obj).
Returns: 'null' if 'existing' is null. existing.create_duplicate otherwise |
| Object Variables |
|---|
|
font_height : Int32 handles : HashTable<<Char,Vector2>> letter_widths : HashTable<<Char,Int32>> letters : HashTable<<Char,Bitmap>> style : FONT_STYLE |
| Object Methods |
|---|
|
adjust_edges( Char ch, Bitmap letter_bmp ).Vector2
Internal use.
compare_to( Object other ).Ternary
This method is used for ordering (quantitative) comparisons
between this object and another.
create_duplicate().ObjectReturns 'eq' if they're equivalent, 'lt' if this object is "less than" the other, or 'gt' if this object is "greater than" another. The compiler converts: 'obj1 < obj2' -> 'obj1.compare_to(obj2) == lt' 'obj1 > obj2' -> 'obj1.compare_to(obj2) == gt' 'obj1 <= obj2' -> 'obj1.compare_to(obj2) != gt' 'obj1 >= obj2' -> 'obj1.compare_to(obj2) != lt'Implementations of compare_to() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract:
if (obj1.compare_to(obj2) == eq)
obj1.equals(obj2) == true
obj1.hash_code == obj2.hash_code
else
obj1.equals(obj2) == false
endIf
Note that two "equal" objects *must* have the same hash code,
but "unequal" objects may or may not have the same hash code.
This default implementation throws an UnsupportedMethodError.
Should create a duplicate of this object such that
obj1.equals(obj1.create_duplicate) return true.
create_letter_map().HashTable<<Char,FontCharacter>>The command duplicate(obj) is transformed by the compiler into Object.create_duplicate(obj), which then calls this method. For optimal performance (by removing an internal typecast in most situations), have your overridden create_duplicate have the same return type as the class it's defined in. For instance, Strings implementation is 'create_duplicate.String'. This default implementation throws an UnsupportedMethodError.
Internal use.
equals( Object other ).Boolean
Returns true if this object is equivalant to another.
find_letter_width( Bitmap bmp, Int32 letter_start_x ).Int32The compiler converts 'obj1 == obj2' into 'obj1.equals(obj2)' and 'obj1 != obj2' into 'not obj1.equals(obj2)'. Implementations of equals() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract: if (obj1.equals(obj2)) obj1.compare_to(obj2) == eq obj1.hash_code == obj2.hash_code else obj1.compare_to(obj2) != eq endIfNote that two "equal" objects *must* have the same hash code, but "unequal" objects may or may not have the same hash code. This default implementation returns true if the this object and the 'other' reference are the same object ('this is other').
Internal use.
hash_code().Int32
Returns the hash code of this object, which some classes
(like HashTable) rely on. This default implementation
throws an UnsupportedMethodError.
init( [FONT_STYLE style] )Hash codes are used to quickly test and see if two complex objects are NOT equal. The value returned has no intrinsic meaning, but should conform to the following rules: 1. Two objects that are equivalent should produce the same hash code. 2. If an object's state doesn't change, its hash code shouldn't change either. Internally, this precludes the hash code being based on an object's memory address since Slag doesn't guarantee that an object's address won't change over time. This has the following implications: If you override hash_code you should also override equals() and possibly compare_to() and ensure the following contract. Invariant:
if (obj1.hash_code != obj2.hash_code)
obj1.equals(obj2) == false
obj1.compare_to(obj2) != eq
endIf
Initializes an empty FontBuilder with the specified font style
applying to future load() calls.
init( String filename, [FONT_STYLE style], [String mapping] )
Initializes the FontBuilder to load the given font strip as
its initial contents.
load( String filename, [String mapping] )
Adds the characters from the given font strip to this font.
load( Bitmap src, String mapping )
Adds the characters from the given font strip to this font.
to_Font().Font
Returns a Font containing all the characters that have been
loaded by this FontBuilder.
to_String().String
Returns:
type_name().StringA String representation of this object. Most classes should override this method to summarize an object's state for convenience in testing and debugging.
Returns the true class name of this object. Implemented by
the runtime; you should not override this method.
Example: local Object obj = "Hello World" println( obj.type_name ) #prints: String |
Internal use. Specifies information about a single font character.
| Class Methods |
|---|
|
create_duplicate( Object existing ).Object
This factory method initiates object duplication. The
compiler transforms the duplicate(obj) command into
Object.create_duplicate(obj).
Returns: 'null' if 'existing' is null. existing.create_duplicate otherwise |
| Object Variables |
|---|
|
image : Image width : Int32 |
| Object Methods |
|---|
|
compare_to( Object other ).Ternary
This method is used for ordering (quantitative) comparisons
between this object and another.
create_duplicate().ObjectReturns 'eq' if they're equivalent, 'lt' if this object is "less than" the other, or 'gt' if this object is "greater than" another. The compiler converts: 'obj1 < obj2' -> 'obj1.compare_to(obj2) == lt' 'obj1 > obj2' -> 'obj1.compare_to(obj2) == gt' 'obj1 <= obj2' -> 'obj1.compare_to(obj2) != gt' 'obj1 >= obj2' -> 'obj1.compare_to(obj2) != lt'Implementations of compare_to() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract:
if (obj1.compare_to(obj2) == eq)
obj1.equals(obj2) == true
obj1.hash_code == obj2.hash_code
else
obj1.equals(obj2) == false
endIf
Note that two "equal" objects *must* have the same hash code,
but "unequal" objects may or may not have the same hash code.
This default implementation throws an UnsupportedMethodError.
Should create a duplicate of this object such that
obj1.equals(obj1.create_duplicate) return true.
equals( Object other ).BooleanThe command duplicate(obj) is transformed by the compiler into Object.create_duplicate(obj), which then calls this method. For optimal performance (by removing an internal typecast in most situations), have your overridden create_duplicate have the same return type as the class it's defined in. For instance, Strings implementation is 'create_duplicate.String'. This default implementation throws an UnsupportedMethodError.
Returns true if this object is equivalant to another.
hash_code().Int32The compiler converts 'obj1 == obj2' into 'obj1.equals(obj2)' and 'obj1 != obj2' into 'not obj1.equals(obj2)'. Implementations of equals() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract: if (obj1.equals(obj2)) obj1.compare_to(obj2) == eq obj1.hash_code == obj2.hash_code else obj1.compare_to(obj2) != eq endIfNote that two "equal" objects *must* have the same hash code, but "unequal" objects may or may not have the same hash code. This default implementation returns true if the this object and the 'other' reference are the same object ('this is other').
Returns the hash code of this object, which some classes
(like HashTable) rely on. This default implementation
throws an UnsupportedMethodError.
init( Image image, Int32 width )Hash codes are used to quickly test and see if two complex objects are NOT equal. The value returned has no intrinsic meaning, but should conform to the following rules: 1. Two objects that are equivalent should produce the same hash code. 2. If an object's state doesn't change, its hash code shouldn't change either. Internally, this precludes the hash code being based on an object's memory address since Slag doesn't guarantee that an object's address won't change over time. This has the following implications: If you override hash_code you should also override equals() and possibly compare_to() and ensure the following contract. Invariant:
if (obj1.hash_code != obj2.hash_code)
obj1.equals(obj2) == false
obj1.compare_to(obj2) != eq
endIf
to_String().String
Returns:
type_name().StringA String representation of this object. Most classes should override this method to summarize an object's state for convenience in testing and debugging.
Returns the true class name of this object. Implemented by
the runtime; you should not override this method.
Example: local Object obj = "Hello World" println( obj.type_name ) #prints: String |
Base type for a Reader that's specialized as a generator. Generators always have another number, can skip() a number of values ahead (through repeated reads), and don't support the to_List operation.
| Class Methods |
|---|
|
create_duplicate( Object existing ).Object
This factory method initiates object duplication. The
compiler transforms the duplicate(obj) command into
Object.create_duplicate(obj).
Returns: 'null' if 'existing' is null. existing.create_duplicate otherwise |
| Object Methods |
|---|
|
available().Int32
Returns the minimum number of additional values that can be
immediately read from this reader.
close()If the reader is exhausted or if it must block to peek or read next then the result will be 0. It is important to note that '0' does not necessarily mean the reader is exhausted. Many readers will report that they have 1 available even if there are thousands of values waiting to be read. The 'available' property should be used as an aide for buffer sizes and the like but should not be taken as an absolute size.
Closes this reader as a source of input. Useful for file
readers, but for most others this command does nothing.
compare_to( Object other ).Ternary
This method is used for ordering (quantitative) comparisons
between this object and another.
consume( DataType look_for ).BooleanReturns 'eq' if they're equivalent, 'lt' if this object is "less than" the other, or 'gt' if this object is "greater than" another. The compiler converts: 'obj1 < obj2' -> 'obj1.compare_to(obj2) == lt' 'obj1 > obj2' -> 'obj1.compare_to(obj2) == gt' 'obj1 <= obj2' -> 'obj1.compare_to(obj2) != gt' 'obj1 >= obj2' -> 'obj1.compare_to(obj2) != lt'Implementations of compare_to() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract:
if (obj1.compare_to(obj2) == eq)
obj1.equals(obj2) == true
obj1.hash_code == obj2.hash_code
else
obj1.equals(obj2) == false
endIf
Note that two "equal" objects *must* have the same hash code,
but "unequal" objects may or may not have the same hash code.
This default implementation throws an UnsupportedMethodError.
Attempts to match and discard the next value from this
reader, returning true, or else leaves the next value still
pending and returns false.
create_duplicate().ObjectReturns: "true" if old.peek == look_for "false" if old.peek != look_forInvariant: if (old.peek == look_for) old.skip
Should create a duplicate of this object such that
obj1.equals(obj1.create_duplicate) return true.
equals( Object other ).BooleanThe command duplicate(obj) is transformed by the compiler into Object.create_duplicate(obj), which then calls this method. For optimal performance (by removing an internal typecast in most situations), have your overridden create_duplicate have the same return type as the class it's defined in. For instance, Strings implementation is 'create_duplicate.String'. This default implementation throws an UnsupportedMethodError.
Returns true if this object is equivalant to another.
has_another().BooleanThe compiler converts 'obj1 == obj2' into 'obj1.equals(obj2)' and 'obj1 != obj2' into 'not obj1.equals(obj2)'. Implementations of equals() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract: if (obj1.equals(obj2)) obj1.compare_to(obj2) == eq obj1.hash_code == obj2.hash_code else obj1.compare_to(obj2) != eq endIfNote that two "equal" objects *must* have the same hash code, but "unequal" objects may or may not have the same hash code. This default implementation returns true if the this object and the 'other' reference are the same object ('this is other').
Returns true - standard generators always have another value.
hash_code().Int32
Returns the hash code of this object, which some classes
(like HashTable) rely on. This default implementation
throws an UnsupportedMethodError.
is_exhausted().BooleanHash codes are used to quickly test and see if two complex objects are NOT equal. The value returned has no intrinsic meaning, but should conform to the following rules: 1. Two objects that are equivalent should produce the same hash code. 2. If an object's state doesn't change, its hash code shouldn't change either. Internally, this precludes the hash code being based on an object's memory address since Slag doesn't guarantee that an object's address won't change over time. This has the following implications: If you override hash_code you should also override equals() and possibly compare_to() and ensure the following contract. Invariant:
if (obj1.hash_code != obj2.hash_code)
obj1.equals(obj2) == false
obj1.compare_to(obj2) != eq
endIf
Returns "true" if this reader does not have another value
or "false" if it does.
peek().DataType
Returns the next value that will be returned from read().
If there is no next value then a NoNextValueError is thrown.
position( Int32 new_position )
This optional property-write sets the zero-based read position
of this reader. When a reader is first created position()
returns 0. After a single read() it returns 1, and so on.
Readers that don't implement this property will throw an
UnsupportedMethodError when it's accessed.
position().Int32
This optional property-read returns the zero-based read
position of this reader. When a reader is first created
position() returns 0. After a single read() it returns 1,
and so on.
read().DataTypeReaders that don't implement this property will throw an UnsupportedMethodError when it's accessed.
Returns the next value from this reader. If (not has_another)
then a NoNextValueError is thrown.
read_line().String
Reads and returns the next line of characters up to the next
LF or CRLF. The CRLF characters are not part of
the return value and are discarded.
read_list( Int32 size ).DataType[]Only defined for Reader<<Char>>.
Reads the next 'size' number of values and returns them in a
list. Requires that there are at least 'size' number of
values remaining to be read.
remaining().Int32
This optional property returns how many values remain to be
read before the reader is exhausted. Not all readers
can implement this property; those that don't will throw
an UnsupportedMethodError when it's accessed.
rewind()
This optional method resets this reader so that the next
read() will return the first value of the series.
Readers that don't implement this property will throw an
UnsupportedMethodError when it's accessed.
skip( Int32 skip_count )
Discards 'skip_count' number of values that would otherwise
be returned from this generator.
to_List().DataType[]
Throws an UnsupportedMethodError.
to_String().String
Returns a string representation of this reader's values.
type_name().String
Returns the true class name of this object. Implemented by
the runtime; you should not override this method.
Example: local Object obj = "Hello World" println( obj.type_name ) #prints: String |
| Class Methods |
|---|
|
create_duplicate( Object existing ).Object
This factory method initiates object duplication. The
compiler transforms the duplicate(obj) command into
Object.create_duplicate(obj).
Returns: 'null' if 'existing' is null. existing.create_duplicate otherwise |
| Object Methods |
|---|
|
compare_to( Object other ).Ternary
This method is used for ordering (quantitative) comparisons
between this object and another.
create_duplicate().ObjectReturns 'eq' if they're equivalent, 'lt' if this object is "less than" the other, or 'gt' if this object is "greater than" another. The compiler converts: 'obj1 < obj2' -> 'obj1.compare_to(obj2) == lt' 'obj1 > obj2' -> 'obj1.compare_to(obj2) == gt' 'obj1 <= obj2' -> 'obj1.compare_to(obj2) != gt' 'obj1 >= obj2' -> 'obj1.compare_to(obj2) != lt'Implementations of compare_to() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract:
if (obj1.compare_to(obj2) == eq)
obj1.equals(obj2) == true
obj1.hash_code == obj2.hash_code
else
obj1.equals(obj2) == false
endIf
Note that two "equal" objects *must* have the same hash code,
but "unequal" objects may or may not have the same hash code.
This default implementation throws an UnsupportedMethodError.
Should create a duplicate of this object such that
obj1.equals(obj1.create_duplicate) return true.
equals( Object other ).BooleanThe command duplicate(obj) is transformed by the compiler into Object.create_duplicate(obj), which then calls this method. For optimal performance (by removing an internal typecast in most situations), have your overridden create_duplicate have the same return type as the class it's defined in. For instance, Strings implementation is 'create_duplicate.String'. This default implementation throws an UnsupportedMethodError.
Returns true if this object is equivalant to another.
hash_code().Int32The compiler converts 'obj1 == obj2' into 'obj1.equals(obj2)' and 'obj1 != obj2' into 'not obj1.equals(obj2)'. Implementations of equals() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract: if (obj1.equals(obj2)) obj1.compare_to(obj2) == eq obj1.hash_code == obj2.hash_code else obj1.compare_to(obj2) != eq endIfNote that two "equal" objects *must* have the same hash code, but "unequal" objects may or may not have the same hash code. This default implementation returns true if the this object and the 'other' reference are the same object ('this is other').
Returns the hash code of this object, which some classes
(like HashTable) rely on. This default implementation
throws an UnsupportedMethodError.
to_String().StringHash codes are used to quickly test and see if two complex objects are NOT equal. The value returned has no intrinsic meaning, but should conform to the following rules: 1. Two objects that are equivalent should produce the same hash code. 2. If an object's state doesn't change, its hash code shouldn't change either. Internally, this precludes the hash code being based on an object's memory address since Slag doesn't guarantee that an object's address won't change over time. This has the following implications: If you override hash_code you should also override equals() and possibly compare_to() and ensure the following contract. Invariant:
if (obj1.hash_code != obj2.hash_code)
obj1.equals(obj2) == false
obj1.compare_to(obj2) != eq
endIf
Returns:
type_name().StringA String representation of this object. Most classes should override this method to summarize an object's state for convenience in testing and debugging.
Returns the true class name of this object. Implemented by
the runtime; you should not override this method.
Example: local Object obj = "Hello World" println( obj.type_name ) #prints: String |
Base class of both Image and CompositeImage.
| Class Variables |
|---|
|
color_policy : Color
Specifies the initial value for the 'color' property of
new Image objects. Opaque white by default.
handle_policy : Vector2
Specifies the initial value for the 'handle' property of
new Image objects. (0,0) (HANDLE.top_left) by default.
render_flags_policy : Int32
Specifies the initial value for the 'render_flags' property of
new Image objects. Default: no flags are set.
|
| Class Methods |
|---|
|
create_duplicate( Object existing ).Object
This factory method initiates object duplication. The
compiler transforms the duplicate(obj) command into
Object.create_duplicate(obj).
Returns: 'null' if 'existing' is null. existing.create_duplicate otherwise |
| Object Variables |
|---|
|
angle : Radians
The angle property variable. This may be set to a new
Radians or Degrees value.
color : ColorNote: CompositeImage objects currently ignore this property.
The multiplier for each pixel in this image as it's drawn.
The default color of new_Color(255,255,255,255) ensures that
the image will appear "normal". A color of
new_Color(255,255,0) would not draw any of the blue channel,
making a grey-scale image appear to be tinted yellow. A color
of new_Color(255,255,255,128) would draw the image halfway
transparent.
handle : Vector2
Specifies the drawing and rotation origin of this image.
This can be set to a pixel value relative to the upper-left
of the image (0,0) or a HANDLE category such as
"HANDLE.center" or "HANDLE.bottom_center".
hflip : Boolean
Specifies that an image should be flipped horizontally when
drawn. This mirroring is applied before the image is rotated
and does not affect the spatial positioning.
render_flags : Int32Note: CompositeImage objects currently ignore this property.
Any combination of RENDER constants, or 0 for no special
rendering options.
scale : Vector2Example: ghost.render_flags = (RENDER.overexpose | RENDER.fixed_color)
The size multiplier for rendering, (1.0,1.0) by default.
Setting "scale = Vector2(2.0,0.5)" would cause the image to
render at twice the width and half the height. Change
'size' instead if you want to achieve particular pixel
dimensions.
size : Vector2
The nominal size of the given image, in pixels. Change
'size' if you want the image's standard size to be a
given number of pixels or change 'scale' if you want the
image to be proportionally larger or smaller.
vflip : Boolean
Specifies that an image should be flipped vertically when
drawn. This mirroring is applied before the image is rotated
and does not affect the spatial positioning.
Note: CompositeImage objects currently ignore this property. |
| Object Methods |
|---|
|
alpha( Int32 new_alpha )
Alpha property-set method - sets the alpha component
of this image's color multiplier.
alpha().Int32
Alpha property-get method - returns the alpha component
(0-255) of the current color multiplier.
angle( Radians new_angle )
Angle property-set.
angle( Degrees deg )Note: CompositeImage objects currently ignore this property.
Angle property-set.
compare_to( Object other ).TernaryNote: CompositeImage objects currently ignore this property.
This method is used for ordering (quantitative) comparisons
between this object and another.
create_duplicate().ObjectReturns 'eq' if they're equivalent, 'lt' if this object is "less than" the other, or 'gt' if this object is "greater than" another. The compiler converts: 'obj1 < obj2' -> 'obj1.compare_to(obj2) == lt' 'obj1 > obj2' -> 'obj1.compare_to(obj2) == gt' 'obj1 <= obj2' -> 'obj1.compare_to(obj2) != gt' 'obj1 >= obj2' -> 'obj1.compare_to(obj2) != lt'Implementations of compare_to() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract:
if (obj1.compare_to(obj2) == eq)
obj1.equals(obj2) == true
obj1.hash_code == obj2.hash_code
else
obj1.equals(obj2) == false
endIf
Note that two "equal" objects *must* have the same hash code,
but "unequal" objects may or may not have the same hash code.
This default implementation throws an UnsupportedMethodError.
Should create a duplicate of this object such that
obj1.equals(obj1.create_duplicate) return true.
draw( Real64 x, Real64 y )The command duplicate(obj) is transformed by the compiler into Object.create_duplicate(obj), which then calls this method. For optimal performance (by removing an internal typecast in most situations), have your overridden create_duplicate have the same return type as the class it's defined in. For instance, Strings implementation is 'create_duplicate.String'. This default implementation throws an UnsupportedMethodError.
Draws this image with its handle (origin) at (x,y).
draw( Vector2 pos )
Draws this image at the given position.
equals( Object other ).Boolean
Returns true if this object is equivalant to another.
fixed_color().BooleanThe compiler converts 'obj1 == obj2' into 'obj1.equals(obj2)' and 'obj1 != obj2' into 'not obj1.equals(obj2)'. Implementations of equals() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract: if (obj1.equals(obj2)) obj1.compare_to(obj2) == eq obj1.hash_code == obj2.hash_code else obj1.compare_to(obj2) != eq endIfNote that two "equal" objects *must* have the same hash code, but "unequal" objects may or may not have the same hash code. This default implementation returns true if the this object and the 'other' reference are the same object ('this is other').
Returns "true" if "fixed_color" is set in the render flags.
fixed_color( Boolean setting )
Turns fixed-color drawing on or off in the render flags.
handle( Vector2 new_handle )
Handle property-set.
handle( HANDLE h )
Handle property-set.
hash_code().Int32
Returns the hash code of this object, which some classes
(like HashTable) rely on. This default implementation
throws an UnsupportedMethodError.
overexpose().BooleanHash codes are used to quickly test and see if two complex objects are NOT equal. The value returned has no intrinsic meaning, but should conform to the following rules: 1. Two objects that are equivalent should produce the same hash code. 2. If an object's state doesn't change, its hash code shouldn't change either. Internally, this precludes the hash code being based on an object's memory address since Slag doesn't guarantee that an object's address won't change over time. This has the following implications: If you override hash_code you should also override equals() and possibly compare_to() and ensure the following contract. Invariant:
if (obj1.hash_code != obj2.hash_code)
obj1.equals(obj2) == false
obj1.compare_to(obj2) != eq
endIf
Returns "true" if "overexpose" is set in the render flags.
overexpose( Boolean setting )
Turns overexposure on or off in the render flags.
point_filter().Boolean
Returns "true" if "point_filter" is set in the render flags.
point_filter( Boolean setting )
Turns point filtering on or off in the render flags. "on"
selects nearest-neighbor point filtering; "off" selects
linear filtering (the Image default).
region().Rect
Returns the rectangular region nominally occupied by this
image at its size and scale. The 'position' of the
resulting rectangle is (0,0).
release()
Releases the hardware resources associated with this image.
This will be called automatically at some point when the image
is no longer referenced.
scale( Real64 uniform_scale )
Scale property-set.
scale( Vector2 new_scale )
Scale property-set.
texture_wrap().Boolean
Returns "true" if "texture_wrap" is set in the render flags.
texture_wrap( Boolean setting )
Turns texture wrapping on or off in the render flags.
to_String().String
Returns:
type_name().StringA String representation of this object. Most classes should override this method to summarize an object's state for convenience in testing and debugging.
Returns the true class name of this object. Implemented by
the runtime; you should not override this method.
Example: local Object obj = "Hello World" println( obj.type_name ) #prints: String |
Defines the global methods and variables that form the core of Slag's API.
| Class Variables |
|---|
|
clipping_region : Rect
The current viewport - parts of graphics that lie outside
this region are clipped and not drawn.
command_line_args : String[]
Java-style command line arguments. If a slag program
"echo.slag" is compiled to an ETC file and run like this:
display_size : Vector2slag echo hello worldor compiled to an exe and run like this: echo hello worldThen command_line_args[0] will contain "hello" and command_line_args[1] will contain "world".
The nominal display size in pixels. This is 1024x768 by
default and may be changed in the settings.txt configuration
file. The actual window size (or screen size) may be bigger
than display_size, but the clipping area in draw() is set to
be 'display_size' by default.
fullscreen : Boolean
The abstract variable enabling the "fullscreen" get/set
methods to act as a property.
input : NativeInput
The source of application input.
last_trace_activity_ms : Int64
The time of the last new trace message.
logfile : PrintWriter
Writes a copy of all trace() and log() messages to "log.txt".
origin : Vector2
A drawing-origin translation. This is set by the system while
drawing black borders when the window or screen aspect ratio
is different than the display ratio. It may be adjusted, but
keep in mind that it may not start out at (0,0).
pi : Radians
Defines the constant "pi". If cos(pi) = -1.0, then
acos(-1.0) = pi.
random_gen : RandomReal64Generator
This random number generator that is seeded with the current
time when the program is run.
stdin : Reader<<Char>>
A Reader<<Char>> that reads characters from the standard
input. This is typically configured to be the keyboard.
stdout : PrintWriter
A Writer<<Char>> that writes characters to the standard
output. This is typically configured to be the console
window.
system_font : Font
A monospaced, 17 pixel-high font.
trace_messages : String[]
The list of active trace messages.
window_size : Vector2
Represents the window size (or screen size) of the
application. This can be equal to or greater than
display_size.
|
| Class Methods |
|---|
|
abs( Int32 n ).Int32
Returns the absolute value of 'n'.
abs( Int64 n ).Int64
Returns the absolute value of 'n'.
abs( BigInt n ).BigIntabs( Real64 n ).Real64
Returns the absolute value of 'n'.
abs( Vector2 v ).Vector2
Returns the vector containing the absolute value of each
component of 'v'.
acos( Real64 xp ).Radians
Returns the arccosine (or "cos^-1") of 'xp'. This is the
angle that a vector would have to be at to have a
proportional length 'xp' along the x axis.
all( Readable<<Boolean>> values ).Boolean
Returns true if all of the given values are "true".
all( Boolean b ).BooleanExample:
local Int32 n = input_Int32
if (all(n % {2, 3..sqrt(n) step 2} != 0))
println( "$ is a prime number!" (n) )
else
println( "$ is not prime." (n) )
endIf
Returns true if 'b' is true. This method is supplied so
that all(a==b) may be called in a template without knowing
whether 'a==b' results in a single boolean or a list of
booleans.
any( Readable<<Boolean>> values ).Boolean
Returns true if any of the given values are "true".
any( Boolean b ).Boolean
Returns true if 'b' is true. This method is supplied so
that any(a==b) may be called in a template without knowing
whether 'a==b' results in a single boolean or a list of
booleans.
area_of( Rect r ).Real64
Returns the area of 'r' (width * height).
as_Color( Int32 argb ).Color
Reinterprets the memory used by 'argb' as a Color compound.
as_Int32( Color color ).Int32
Reinterprets the memory used by 'color' as a 32-bit integer.
as_Int32( Real32 n ).Int32
Reinterprets the 32 bits that compose 'n' as an Int32.
as_Int64( Real64 n ).Int64
Reinterprets the 64 bits that compose 'n' as an Int64.
as_Int64( Object obj ).Int64Example: # show the bit pattern corresponding to pi: println( "Pi: $" (pi.as_Int64) )
Returns the memory location that 'obj' is referencing for
debugging purposes.
as_Real32( Int32 n ).Real32
Reinterprets the 32 bits that compose 'n' as a Real32.
as_Real64( Int64 n ).Real64
Reinterprets the 64 bits that compose 'n' as a Real64.
asin( Real64 yp ).Radians
Returns the arcsine (or "sin^-1") of 'yp'. This is the
angle that a vector would have to be at to have a
proportional length 'yp' along the y axis.
atan( Real64 slope ).Radians
Returns the arctangent (or "tan^-1") of 'slope'. This is
the angle of the vector that has the given y/x 'slope'.
atan2( Real64 y, Real64 x ).RadiansNote: slopes do not have a direction associated with them like vectors do; therefore "atan(1.0/1.0)" is the same as "atan(-1.0/-1.0)". Use atan2(Real64,Real64) to take direction into account.
Returns the arctangent (or "tan^-1") of slope 'y'/'x'. This
is the angle of the vector that has that slope.
bottom_left_of( Rect r ).Vector2Unlike atan(Real64), this method takes the direction into account - atan2(1.0,1.0) will give a different answer than atan2(-1.0,-1.0).
Returns the bottom-left coordinate of 'r'.
bottom_right_of( Rect r ).Vector2
Returns the bottom-right coordinate of 'r'.
ceiling( Real64 n ).Real64
Rounds "n" up to the nearest value.
ceiling( Vector2 v ).Vector2Examples: ceiling( 3.0 ) is 3 ceiling( 3.1 ) is 4
Returns the vector containing the ceiling of each
component of 'v'.
center_of( Rect r ).Vector2
Returns the center point of 'r'.
center_of( Line line ).Vector2
Returns the center point of the given line.
clamp( Int32 num, Int32 low, Int32 high ).Int32
Returns:
clamp( Real64 num, Real64 low, Real64 high ).Real64'low' if num < low 'high' if num > high 'num' otherwise
Returns:
clamp( Int64 num, Int64 low, Int64 high ).Int64'low' if num < low 'high' if num > high 'num' otherwise
Returns:
clamp_to_line( Vector2 v, Line line ).Vector2'low' if num < low 'high' if num > high 'num' otherwise
Returns the point along the given line segment that is closest
to 'v'.
clear_display( [Color color] )
Clears the display area by drawing a rectangle over it -
opaque black by default. Note: as of Slag Plasmacore v0.08,
the native layer automatically clears the entire window to
black before calling the application's draw() - clear_display
is unneccesary if you're happy with black.
clipping_region( Rect new_clip )
This property-set adjust the clipping region of the screen.
Anything part of any graphics that lie outside the clipping
region won't be drawn.
component_along_axis( Vector2 v, Vector2 axis ).Vector2
Returns the component of 'v' that lies along the axis defined
by the second parameter. Note that "v - project_onto_axis(v,axis)"
gives the component of v that is perpendicular to the axis.
contains( Rect r, Vector2 pt ).Boolean
Returns "true" if 'r' contains the given point.
contract( Rect r, Vector2 amount ).Rect
Returns a rectangle that is smaller on the left and right
sides by "amount.x" and is smaller on the top and bottom
sides by "amount.y".
contract( Rect r, Real64 per_side ).Rect
Returns a rectangle that is 'per_side' units smaller on every
side.
cos( Radians rad ).Real64
Returns the cosine value of angle 'rad'.
cos( Degrees deg ).Real64Given a vector of angle 'rad', the cosine value tells us what proportion of that line lies along the x axis.
Returns the cosine value of angle 'deg'.
create_duplicate( Object existing ).ObjectGiven a vector of angle 'deg', the cosine value tells us what proportion of that line lies along the x axis.
This factory method initiates object duplication. The
compiler transforms the duplicate(obj) command into
Object.create_duplicate(obj).
create_image( Bitmap bitmap, [Int32 pixel_format] ).Int32Returns: 'null' if 'existing' is null. existing.create_duplicate otherwise
Creates a hardware-accelerated image from the given software
Bitmap.
create_image( Int32 src_index, Int32 x, Int32 y, Int32 w, Int32 h ).Int32'pixel_format' is one of the flag values defined in PIXEL_FORMAT. Returns: The index the native layer uses to track the image. The value "0" indicates that an error occurred.
Defines an image that's a subset of an existing image from
top-left corner (x,y) and (w,h) pixels in size. Does not use
any additional texture memory.
cross( Vector2 v1, Vector2 v2 ).Real64
Returns the cross product of 'v1' and 'v2':
degrees_of( Vector2 v ).Degreesv1.x*v2.y - v1.y*v2.x
Returns the angle of the given vector in degrees.
distance_between( Vector2 v1, Vector2 v2 ).Real64
Returns the straight-line distance between v1 and v2.
dot( Vector2 v1, Vector2 v2 ).Real64
Returns the dot product of 'v1' and 'v2'. Returns
draw( Quad q, Color color )v1.x*v2.x + v1.y*v2.y
Draws an outline of 'q' to the screen in the given color.
draw( Circle circle, Color color, [Real64 segments] )
Draws the given circle to the screen in the given color.
draw( Rect r, Color color )Parameters:
circle
The circle to draw, centered at "circle.position" and with
pixel radius "circle.radius".
Draws an outline of 'r' to the screen in the given color.
draw( Line line, Color color )
Draws the given line to the screen in the given color.
draw_image( Int32 image_index, Vector2 pt1, Vector2 pt2, Vector2 pt3, Vector2 pt4, Color color1, Color color2, Color color3, Color color4, Int32 render_flags )
Draws an image.
draw_line( Vector2 pt1, Vector2 pt2, Color color, [Int32 render_flags] )
Draws a line.
draw_point( Vector2 pt, Color color, [Int32 render_flags] )
Draws a single-pixel point.
enclose( Rect r, Vector2 pt ).Rect
Returns a rectangle just big enough to contain the given
rectangle and the given point.
enclose( Vector2 pt1, Vector2 pt2 ).Rect
Returns a rectangle just big enough to contain both given
points.
enclose( Rect r1, Rect r2 ).Rect
Returns a rectangle just big enough to contain both given
rectangles.
enclose( Line line ).Rect
Returns a rectangle just big enough to contain the given
line.
enclose( Circle circle ).Rect
Returns a rectangle just big enough to contain the given circle.
expand( Rect r, Real64 per_side ).Rect
Returns a rectangle that is 'per_side' units larger on every
side.
expand( Rect r, Vector2 amount ).Rect
Returns a rectangle that is "amount.x" units larger on the
left and right sides and "amount.y" units larger on the top
and bottom.
fill( Quad q, Color color1, Color color2, Color color3, Color color4 )
Draws 'q' to the screen as a gradient fill. The four colors
are assigned clockwise starting with the top-left corner.
fill( Rect r, Color color )Parameters: q - The quadrangle. color1 - The color of the top-left corner. color2 - The color of the top-right corner. color3 - The color of the bottom-right corner. color4 - The color of the bottom-left corner.
Draws 'r' to the screen filled with the given color.
fill( Rect r, Color color1, Color color2, Color color3, Color color4 )
Draws 'r' to the screen as a gradient fill. The four colors
are assigned clockwise starting with the top-left corner.
fill( Quad q, Color color )Parameters: r - The rectangle. color1 - The color of the top-left corner. color2 - The color of the top-right corner. color3 - The color of the bottom-right corner. color4 - The color of the bottom-left corner.
Draws 'q' to the screen filled with the given color.
fill_quad( Vector2 pt1, Vector2 pt2, Vector2 pt3, Vector2 pt4, Color color1, Color color2, Color color3, Color color4, [Int32 render_flags] )
Draws a filled quadrangle.
floor( Vector2 v ).Vector2
Returns the vector containing the floor of each
component of 'v'.
floor( Real64 n ).Real64
Returns the value of 'n' rounded down.
format_string( Line line, Int32 whole_digits, Int32 decimal_digits, [Char fill_char] ).Stringprintln( floor(3.9) ) #prints: 3 println( floor(-3.9) ) #prints: -4
Returns a formatted string representation of 'line'.
format_string( Byte num, Int32 whole_digits, Int32 decimal_digits, [Char fill_char] ).String
Returns a formatted string representation of 'num'.
format_string( String st, Int32 whole_digits, Int32 decimal_digits, [Char fill_char] ).String
Returns a formatted string representation of 'num'.
format_string( Object obj, Int32 whole_digits, Int32 decimal_digits, [Char fill_char] ).String
Returns a formatted string representation of 'obj'.
format_string( Ternary num, Int32 whole_digits, Int32 decimal_digits, [Char fill_char] ).String
Returns a formatted string representation of 'num'.
format_string( Real64 num, Int32 whole_digits, Int32 decimal_digits, [Char fill_char] ).String
Returns a formatted string representation of 'num'.
format_string( Char num, Int32 whole_digits, Int32 decimal_digits, [Char fill_char] ).String
Returns a formatted string representation of 'num'.
format_string( Vector2 v, Int32 whole_digits, Int32 decimal_digits, [Char fill_char] ).String
Returns a formatted string representation of 'v'.
format_string( Int64 num, Int32 whole_digits, Int32 decimal_digits, [Char fill_char] ).String
Returns a formatted string representation of 'num'.
format_string( Circle circle, Int32 whole_digits, Int32 decimal_digits, [Char fill_char] ).String
Returns a formatted string representation of 'circle'.
format_string( Radians rad, Int32 whole_digits, Int32 decimal_digits, [Char fill_char] ).String
Returns a formatted string representation of 'rad'.
format_string( Degrees deg, Int32 whole_digits, Int32 decimal_digits, [Char fill_char] ).String
Returns a formatted string representation of 'deg'.
format_string( Corners c, Int32 whole_digits, Int32 decimal_digits, [Char fill_char] ).String
Returns a formatted string representation of 'c'.
format_string( Boolean num, Int32 whole_digits, Int32 decimal_digits, [Char fill_char] ).String
Returns a formatted string representation of 'num'.
format_string( ParsePos p, Int32 whole_digits, Int32 decimal_digits, [Char fill_char] ).String
Returns a formatted string representation of the given
ParsePos.
format_string( Rect r, Int32 whole_digits, Int32 decimal_digits, [Char fill_char] ).String
Returns a formatted string representation of 'r'.
format_string( Quad q, Int32 whole_digits, Int32 decimal_digits, [Char fill_char] ).String
Returns a formatted string representation of 'q'.
format_string( Int32 num, Int32 whole_digits, Int32 decimal_digits, [Char fill_char] ).String
Returns a formatted string representation of 'num'.
fractional_part( Real64 n ).Real64
Returns the fractional part of the given value.
get_image_height( Int32 image_index ).Int32Example: println( fractional_part(3.9) ) #prints: 0.9
Internal use.
get_image_width( Int32 image_index ).Int32Returns the nominal pixel height (texel height) of the given image.
Internal use.
get_uv( Int32 image_index ).CornersReturns the nominal pixel width (texel width) of the given image.
Internal use.
hash_code( Ternary n ).Int32Returns the (u,v) coordinate pairs for the top-left and bottom right of the given image.
Returns a hash code for primitive 'n'.
hash_code( Boolean n ).Int32
Returns a hash code for primitive 'n'.
hash_code( Object obj ).Int32
Returns "null" if the object is null or else the result of
obj.hash_code.
hash_code( Real32 n ).Int32
Returns a hash code for primitive 'n'.
hash_code( Real64 n ).Int32
Returns a hash code for primitive 'n'.
hash_code( Int64 n ).Int32
Returns a hash code for primitive 'n'.
hash_code( Int32 n ).Int32
Returns a hash code for primitive 'n'.
height_of( Rect r ).Real64
Returns the height of 'r'.
init_class()
Internal use.
input_Int32( [String prompt] ).Int32
Displays the given prompt and calls read_Int32 to read
and return a number.
input_Int64( [String prompt] ).Int64
Displays the given prompt and calls read_Int64 to read
and return a number.
input_String( [String prompt] ).String
Displays the given prompt and calls read_line to read
and return a number.
intersect( Line line, Circle circle ).Boolean
Returns true if 'line' and 'circle' intersect.
intersect( Line line1, Line line2 ).Boolean
Returns true if line segments 'line1' and 'line2' intersect.
Use 'intersection_of' to determine the point of intersection.
intersect( Circle c1, Circle c2 ).Boolean
Returns "true" if c1 and c2 intersect.
intersect( Circle circle, Line line ).Boolean
Returns true if 'line' and 'circle' intersect.
intersect( Rect r1, Rect r2 ).Boolean
Returns "true" if rectangles r1 and r2 intersect at all.
intersection_of( Line line1, Line line2 ).Vector2
Returns the point of intersection between line1 and line 2
or Vector2(NaN,NaN) if there is no intersection.
intersection_of( Rect r1, Rect r2 ).Rect
Returns the rectangle defining the area that is common to both
'r1' and 'r2'. If the result's size is zero then the
rectangles do not overlap.
is_NaN( Real32 n ).Boolean
"Not a number" (NaN) values can't be compared normally; for example
(NaN == NaN) is false. The Slag compiler detects comparisons against
literal "NaN" and calls this method. This method can also be called
when comparing against a variable that may or may not be a NaN value.
is_NaN( Real64 n ).Boolean
"Not a number" (NaN) values can't be compared normally; for example
(NaN == NaN) is false. The Slag compiler detects comparisons against
literal "NaN" and calls this method. This method can also be called
when comparing against a variable that may or may not be a NaN value.
is_alphanumeric( Char ch ).Boolean
Returns "true" if 'ch' is an alphanumeric value (0-9, a-z,
A-Z).
is_digit( Char ch, [Int32 base] ).Boolean
Returns true if the given character is a valid digit in the
specified number base (2 to 36 where bases greater than
10 accept characters "a..z" or "A..Z" as digits 10..35).
is_even( BigInt n ).Booleanis_even( Int64 n ).Boolean
Returns "true" if 'n' is an even number.
is_even( Int32 n ).Boolean
Returns "true" if 'n' is an even number.
is_fullscreen().Boolean
Returns "true" if the application
is running in fullscreen mode or "false" if it's running in
windowed mode.
is_hex_digit( Char ch ).Boolean
Returns "true" if 'ch' is an base-16 digit (0-9, a-f, A-F).
is_letter( Char ch ).Boolean
Returns "true" if 'ch' is a letter of the alphabet (A-Z, a-z).
is_lowercase( Char ch ).Boolean
Returns "true" if 'ch' is an lowercase letter (a-z).
is_odd( BigInt n ).Booleanis_odd( Int64 n ).Boolean
Returns "true" if 'n' is an odd number.
is_odd( Int32 n ).Boolean
Returns "true" if 'n' is an odd number.
is_power_of_two( Int64 n ).Boolean
Returns "true" if 'n' is a power of 2.
is_power_of_two( Int32 n ).Boolean
Returns "true" if 'n' is a power of 2.
is_uppercase( Char ch ).Boolean
Returns "true" if 'ch' is an uppercase letter (A-Z).
left_rotated( Int64 n, Int32 num_bits ).Int64
Returns 'n' with its bits left-rotated by 'num_bits' digits.
left_rotated( Int32 n, Int32 num_bits ).Int32
Returns 'n' with its bits left-rotated by 'num_bits' digits.
left_shifted( Int32 n, Int32 num_bits ).Int32
Returns 'n' with its bits left-shifted by 'num_bits' digits.
Zero bits are shifted in on the right side.
left_shifted( Int64 n, Int32 num_bits ).Int64
Returns 'n' with its bits left-shifted by 'num_bits' digits.
Zero bits are shifted in on the right side.
length_of( Line line ).Real64
Returns the length of the given line.
load_bitmap( String filename ).Bitmap
Loads the given png or jpg image with the given filename.
load_image( String filename, [Int32 pixel_format] ).Int32Returns null if file not found or error loading.
Internal use.
log( String mesg )The following variations of 'filename' are checked: filename filename.ext (.ext = [.png|.jpg|.jpeg]) data/filename data/filename.extLoads the given png or jpg image with the given filename and returns the index the native layer uses to track the image (0 indicates error). 'pixel_format' is one of the flag values defined in PIXEL_FORMAT.
Prints the given message to "log.txt".
log( Vector2 v )
Logs 'v'.
magnitude_of( Vector2 v ).Real64
Returns the magnitude (radial length) of the given vector.
max( Real64 a, Real64 b ).Real64
Returns the highest of the two values 'a' and 'b'.
max( Int32 a, Int32 b ).Int32
Returns the highest of the two values 'a' and 'b'.
max( Int64 a, Int64 b ).Int64
Returns the highest of the two values 'a' and 'b'.
midpoint_of( Line line ).Vector2
Returns the point in the middle of the given line.
min( Real64 a, Real64 b ).Real64
Returns the lowest of the two values 'a' and 'b'.
min( Int64 a, Int64 b ).Int64
Returns the lowest of the two values 'a' and 'b'.
min( Int32 a, Int32 b ).Int32
Returns the lowest of the two values 'a' and 'b'.
min_bits( Int32 n ).Int32
Returns the minimum number of bits required to represent the
given value. For example, min_bits(4) would return 3,
since 3 bits can represent the values 0..7.
new_Circle( Vector2 position, Real64 radius ).CircleInvariant: result >= 1 and result <= 32 (2^result-1) >= n if (n < 0) result == 32
Creates a Circle at the given 'position' with the given 'radius'.
new_Color( Int32 r, Int32 g, Int32 b, [Int32 a] ).Color
Creates a Color compound from the given integer
components.
new_Color( Real64 r, Real64 g, Real64 b, [Real64 a] ).ColorParameters:
r - The red component 0-255.
g - The green component 0-255.
b - The blue component 0-255.
a - The alpha component 0-255. 0 is completely
transparent, 255 [default] is completely opaque.
Creates a Color compound from the given real number
components.
new_Color( RealColor real_color ).ColorParameters:
r - The red component 0-1.0.
g - The green component 0-1.0.
b - The blue component 0-1.0.
a - The alpha component 0-1.0. 0 is completely
transparent, 1.0 [default] is completely opaque.
Creates a Color compound from the given RealColor
compound.
new_Color( Color top_color, Color bottom_color ).Color
Creates a Color compound by alpha-blending the two given
Colors. For each RGB color component, the difference to get
from the bottom color to the top color is first multiplied by
the top color's alpha value as a proportion. The alpha
value of the new color is 255.
new_Color( HSV hsv ).Color
Creates a Color compound from the given HSV compound.
new_Corners( Vector2 top_left, Vector2 bottom_right ).Corners
Creates a Corners compound from the given top-left and bottom-
right coordinates.
new_Corners( Vector2 position ).Corners
Creates a corners compound with 'position' as both the
top-left and bottom-right coordinates.
new_Corners( Real64 x1, Real64 y1, Real64 x2, Real64 y2 ).Corners
Creates a Corners compound from the given top-left and bottom-
right coordinates.
new_Corners( Rect r ).Corners
Creates a corners compound with the same dimensions as 'r'.
new_Degrees( Real64 n ).Degrees
Creates a Degrees value of 'n' degrees.
new_Degrees( Real32 n ).Degrees
Creates a Degrees value of 'n' degrees.
new_Degrees( Radians rad ).Degrees
Creates a Degrees value of the same angle as 'rad'.
new_HSV( Color color ).HSV
Creates a HSV compound from the given Color compound.
new_HSV( RealColor argb ).HSV
Creates a HSV compound from the given RealColor compound.
new_Line( Vector2 begin, Vector2 end ).Line
Creates a Line from 'begin' to 'end'.
new_Line( Real64 x1, Real64 y1, Real64 x2, Real64 y2 ).Line
Creates a Line from (x1,y1) to (x2,y2).
new_Quad( Rect r ).Quad
Creates a Quad with the same position and size as the given
rectangle.
new_Quad( Vector2 top_left, Vector2 top_right, Vector2 bottom_right, Vector2 bottom_left ).Quad
Creates a Quad with the given four coordinates.
new_Radians( Real32 n ).Radians
Creates a Radians value of 'n' radians.
new_Radians( Real64 n ).Radians
Creates a Radians value of 'n' radians.
new_Radians( Degrees deg ).Radians
Creates a Radians value of the same angle as 'deg'.
new_RealColor( Real64 r, Real64 g, Real64 b, [Real64 a] ).RealColor
Creates a RealColor compound from the given real number
components.
new_RealColor( Color c ).RealColorParameters:
r - The red component 0.0-1.0.
g - The green component 0.0-1.0.
b - The blue component 0.0-1.0.
a - The alpha component 0.0-1.0. 0.0 is completely
transparent, 1.0 [default] is completely opaque.
Creates a RealColor compound from the given Color compound.
new_RealColor( HSV hsv ).RealColor
Creates a RealColor compound from the given real number
components.
new_Rect( Real64 x, Real64 y, Real64 width, Real64 height ).RectParameters:
r - The red component 0-1.0.
g - The green component 0-1.0.
b - The blue component 0-1.0.
a - The alpha component 0-1.0. 0 is completely
transparent, 1.0 [default] is completely opaque.
Creates a Rect compound with the given position and size.
new_Rect( Vector2 position, Vector2 size ).Rect
Creates a Rect compound with the given position and size.
new_Rect( Vector2 size ).Rect
Creates a Rect compound with the given size and position
(0,0).
new_Rect( Corners c ).Rect
Creates a Rect compound with the given corners.
new_Vector2( Real64 magnitude, Degrees angle ).Vector2
Creates a Vector2 compound from the given magnitude and
angle in degrees.
new_Vector2( Real64 x, Real64 y ).Vector2
Creates a Vector2 compound containing the given (x,y)
values.
new_Vector2( Real64 magnitude, Radians angle ).Vector2
Creates a Vector2 compound from the given magnitude and
angle in radians.
normal_of( Vector2 v ).Vector2
Returns the normal of the given vector.
normalize( Vector2 v ).Vector2
Normalizes 'v' to have the same angle with magnitude 1.0.
op%( Vector2 v1, Real64 n ).Vector2
Returns the Vector2 modulo of each component of 'v1' divided
by 'n'. Equivalent to
op%( Real64 n, Vector2 v ).Vector2v1 % Vector2(n,n)
Equivalent to Vector2(n,n) % v
op%( Vector2 v1, Vector2 v2 ).Vector2
Returns the vector product v3 = v1 % v2 where
op*( HSV c, Real64 factor ).HSVv3.x = v1.x % v2.x v3.y = v1.y % v2.y
Multiplies the color components of 'c' by the given scaling factor
while preserving Alpha.
op*( Radians rad, Real64 factor ).Radians
Returns "rad" scaled by "factor".
op*( Real64 factor, Degrees deg ).Degrees
Returns "deg" scaled by "factor".
op*( Degrees deg, Real64 factor ).Degrees
Returns "deg" scaled by "factor".
op*( Rect rect, Real64 n ).Rect
Scales the "vertices" of 'rect' by 'n'.
op*( Rect rect, Vector2 n ).Rect
Scales the "vertices" of 'rect' by 'n'.
op*( Line line, Real64 n ).Line
Scales the position of 'line' by n.
op*( Circle circle, Real64 n ).Circle
Scales the position and size of 'circle' by 'n'.
op*( Corners corners, Vector2 n ).Corners
Scales the "vertices" of 'corners' by 'n'.
op*( Real64 n, Vector2 v ).Vector2
Equivalent to Vector2(n,n) * v
op*( Quad quad, Vector2 n ).Quad
Scales the vertices of 'quad' by +n.
op*( Real64 factor, Radians rad ).Radians
Returns "rad" scaled by "factor".
op*( Quad quad, Real64 n ).Quad
Scales the vertices of 'quad' by +n.
op*( Vector2 v1, Vector2 v2 ).Vector2
Returns the vector product v3 = v1 * v2 where
op*( Corners corners, Real64 n ).Cornersv3.x = v1.x * v2.x v3.y = v1.y * v2.y
Scales the "vertices" of 'corners' by 'n'.
op*( Line line, Vector2 n ).Line
Scales the position of 'line' by n.
op*( Color c, Real64 factor ).Color
Multiplies the color components of 'c' by the given scaling factor
while preserving Alpha.
op*( RealColor c, Real64 factor ).RealColor
Multiplies the color components of 'c' by the given scaling factor
while preserving Alpha.
op*( Vector2 v1, Real64 n ).Vector2
Multiplies both components of v1 by 'n'. Equivalent to
op+( Radians rad, Degrees deg ).Radiansv1 * Vector2(n,n)
Returns the sum of two angles. Called automatically
when there's an expression of the form "a1 + a2".
op+( Degrees deg1, Degrees deg2 ).Degrees
Returns the sum of two angles. Called automatically
when there's an expression of the form "a1 + a2".
op+( Corners corners, Vector2 v ).Corners
Shifts the position of 'corners' by +v.
op+( Rect rect, Vector2 v ).Rect
Shifts the position of 'rect' by +v.
op+( Quad quad, Vector2 n ).Quad
Shifts the vertices of 'quad' by +n.
op+( Circle circle, Vector2 v ).Circle
Shifts the position of 'circle' by +v.
op+( Vector2 v1, Real64 n ).Vector2
Adds 'n' to both components of v1. Equivalent to
op+( Real64 n, Vector2 v ).Vector2v1 + Vector2(n,n)
Equivalent to Vector2(n,n) + v
op+( Radians rad1, Radians rad2 ).Radians
Returns the sum of two angles. Called automatically
when there's an expression of the form "a1 + a2".
op+( Degrees deg, Radians rad ).Degrees
Returns the sum of two angles. Called automatically
when there's an expression of the form "a1 + a2".
op+( Line line, Vector2 v ).Line
Shifts the position of 'line' by +v.
op+( Vector2 v1, Vector2 v2 ).Vector2
Returns the vector sum v3 = v1 + v2 where
op-( Degrees deg1, Degrees deg2 ).Degreesv3.x = v1.x + v2.x v3.y = v1.y + v2.y
Returns the difference of two angles. Called automatically
when there's an expression of the form "a1 - a2".
op-( Radians rad, Degrees deg ).Radians
Returns the difference of two angles. Called automatically
when there's an expression of the form "a1 - a2".
op-( Corners corners, Vector2 v ).Corners
Shifts the position of 'corners' by -v.
op-( Degrees deg1 ).Degrees
Returns the negative of the given angle. Called automatically
when there's an expression of the form "-a".
op-( Radians rad1 ).Radians
Returns the negative of the given angle. Called automatically
when there's an expression of the form "-a".
op-( Vector2 v ).Vector2
Returns the negative of this vector v2 = -v1 where
op-( Quad quad, Vector2 n ).Quadv2.x = -v1.x v2.y = -v1.y
Shifts the vertices of 'quad' by -n.
op-( Circle circle, Vector2 v ).Circle
Shifts the position of 'circle' by -v.
op-( Vector2 v1, Real64 n ).Vector2
Subtracts 'n' from both components of v1. Equivalent to
op-( Rect rect, Vector2 v ).Rectv1 - Vector2(n,n)
Shifts the position of 'rect' by -v.
op-( Real64 n, Vector2 v ).Vector2
Equivalent to Vector2(n,n) - v
op-( Circle circle, Real64 n ).Circle
Scales the position and size of 'circle' by 'n'.
op-( Radians rad1, Radians rad2 ).Radians
Returns the difference of two angles. Called
automatically when there's an expression of the form "a1 - a2".
op-( Degrees deg, Radians rad ).Degrees
Returns the difference of two angles. Called automatically
when there's an expression of the form "a1 - a2".
op-( Line line, Vector2 v ).Line
Shifts the position of 'line' by -v.
op-( Vector2 v1, Vector2 v2 ).Vector2
Returns the vector sum v3 = v1 - v2 where
op/( Radians rad, Real64 factor ).Radiansv3.x = v1.x - v2.x v3.y = v1.y - v2.y
Returns "rad" scaled by "factor".
op/( RealColor c, Real64 factor ).RealColor
Divides the color components of 'c' by the given scaling factor
while preserving Alpha.
op/( Real64 factor, Degrees deg ).Degrees
Returns "deg" scaled by "factor".
op/( HSV c, Real64 factor ).HSV
Divides the color components of 'c' by the given scaling factor
while preserving Alpha.
op/( Degrees deg, Real64 factor ).Degrees
Returns "deg" scaled by "factor".
op/( Corners corners, Vector2 n ).Corners
Scales the "vertices" of 'corners' by 'n'.
op/( Rect rect, Real64 n ).Rect
Scales the "vertices" of 'rect' by 'n'.
op/( Vector2 v1, Real64 n ).Vector2
Divides both components of v1 by 'n'. Equivalent to
op/( Rect rect, Vector2 n ).Rectv1 / Vector2(n,n)
Scales the "vertices" of 'rect' by 'n'.
op/( Quad quad, Vector2 n ).Quad
Scales the vertices of 'quad' by -n.
op/( Real64 n, Vector2 v ).Vector2
Equivalent to Vector2(n,n) / v
op/( Line line, Real64 n ).Line
Scales the position of 'line' by n.
op/( Real64 factor, Radians rad ).Radians
Returns "rad" scaled by "factor".
op/( Line line, Vector2 n ).Line
Scales the position of 'line' by n.
op/( Quad quad, Real64 n ).Quad
Scales the vertices of 'quad' by -n.
op/( Color c, Real64 factor ).Color
Divides the color components of 'c' by the given scaling factor
while preserving Alpha.
op/( Vector2 v1, Vector2 v2 ).Vector2
Returns the vector product v3 = v1 / v2 where
op/( Corners corners, Real64 n ).Cornersv3.x = v1.x / v2.x v3.y = v1.y / v2.y
Scales the "vertices" of 'corners' by 'n'.
point_along( Line line, Real64 p ).Vector2
Returns the point along the given line corresponding to
fraction 'p', where 0 <= p <= 1.0.
point_at( Circle circle, Degrees angle ).Vector2Invariant: point_along(line,0.0) == line.begin point_along(line,0.5) == center_of(line) point_along(line,1.0) == line.end
Returns the point along the edge of the circle at the given angle.
point_at( Circle circle, Radians angle ).Vector2
Returns the point along the edge of the circle at the given angle.
print( Corners c )
Prints 'c' in text form to stdout.
print( Vector2 v )
Prints 'v' in text form to stdout.
print( Byte n )
Prints the given Byte to stdout as a human-readable series of
digits.
print( Char n )
Prints the given Char to stdout. The symbol corresponding
to the Unicode value of 'n' will be displayed.
print( Real64 n )
Prints the given Real64 to stdout as a human-readable series
of digits.
print( Object obj )
Prints the to_String() value of the given Object to stdout.
If the 'obj' reference is null, the word "null" is printed
out instead.
print( ParsePos p )
Prints the given ParsePos to stdout.
print( HSV hsv )
Prints 'hsv' to stdout.
print( Rect r )
Prints 'r' in text form to stdout.
print( Quad q )
Prints 'q' in text form to stdout.
print( Circle circle )
Prints 'circle' in text form.
print( Line line )
Prints 'line' in text form.
print( Int64 n )
Prints the given Int64 to stdout as a human-readable series of
digits.
print( Color c )
Prints 'c' to stdout.
print( RealColor argb )
Prints 'argb' to stdout.
print( Boolean n )
Prints the given Boolean to stdout as the words "true" or
"false".
print( Degrees deg )
Prints the given degrees value.
print( Radians rad )
Prints the given radians value.
print( Ternary n )
Prints the given Ternary to stdout as the words 'yes', 'no',
or 'void'.
println( RealColor argb )
Prints 'argb' to stdout and advances the cursor to the next
line.
println( Color c )
Prints 'c' to stdout and advances the cursor to the next line.
println( Vector2 v )
Prints 'v' in text form to stdout and advances the cursor
to the next line.
println( Rect r )
Prints 'r' in text form to stdout and advances the cursor to
the next line.
println( Corners c )
Prints 'c' in text form to stdout and advances the cursor to
the next line.
println()
Moves the cursor to the next line.
println( Quad q )
Prints 'q' in text form to stdout and advances the cursor to the next
line.
println( Line line )
Prints 'line' in text form to stdout and advances the cursor
to the next line of text output.
println( Circle circle )
Prints 'circle' in text form to stdout and advances the cursor
to the next circle of text output.
println( ParsePos p )
Prints the given ParsePos to stdout and advances the
cursor to the next line.
println( Byte n )
Prints the given Byte value and advances the cursor to the
next line.
println( Char n )
Prints the given Char value and advances the cursor to the
next line.
println( Real64 n )
Prints the given Real64 value and advances the cursor to the
next line.
println( Ternary n )
Prints the given Ternary value and advances the cursor to the
next line.
println( Radians rad )
Prints the given radians value and advances the cursor to the
next line.
println( Boolean n )
Prints the given Boolean value and advances the cursor to the
next line.
println( Degrees deg )
Prints the given degrees value and advances the cursor to the
next line.
println( HSV hsv )
Prints 'hsv' to stdout and advances the cursor to the next
line.
println( Int64 n )
Prints the given Int64 value and advances the cursor to the
next line.
println( Object obj )
Prints the given object and advances the cursor to the next
line.
project_onto_axis( Vector2 v, Line line ).Vector2
Returns the projection of 'v' on 'axis'. The return value
is a point along the axis of 'axis'.
radians_of( Vector2 v ).Radians
Returns the angle of the given vector in radians.
random_Boolean().Boolean
Returns either "true" or "false" with equal likelihood.
random_Color().Color
Returns a color with randomized (r,g,b) values and an
alpha of 255.
random_Degrees().Degrees
Returns a random angle in the range (0,360) exclusive.
random_Int32( Int32 limit ).Int32
Returns a normalized, evenly distributed random integer in
the range [0,limit) - includes 0 but does not include limit.
random_Int32().Int32Example: println( random_Int32(100) ) #prints a number 0..99
Returns a normalized, evenly distributed random integer in
the range [-2^31,2^31-1] inclusive.
random_Int32( Int32 low, Int32 high ).Int32
Returns a random integer between low and high, inclusive.
random_Radians().Radians
Returns a random angle in the range (0,2*pi) exclusive.
random_Real64().Real64
Returns a normalized, evenly distributed random real number in
the range (0.0,1.0) exclusive (does not include 0.0 or 1.0).
random_Real64( Real64 low, Real64 high ).Real64
Returns a normalized, evenly distributed random real number in
the range (low,high) exclusive (does not include low or high).
random_Vector2().Vector2
Creates a Vector2 compound with randomized (x,y) values,
each in the range (0.0,1.0) exclusive.
read_Int32().Int32
Reads a line of text in from the user - up to the [ENTER]
key being pressed - and attempts to parse an Int32 value
from the text. If the input is not a well-formed integer
value then an InvalidOperandError is thrown.
read_Int64().Int64
Reads a line of text in from the user - up to the [ENTER]
key being pressed - and attempts to parse an Int64 value
from the text. If the input is not a well-formed integer
value then an InvalidOperandError is thrown.
read_line().String
Reads a line of text in from the user - up to the [ENTER]
key being pressed - and returns the line of text as a
String. The end-of-line characters are not part of the
string and are discarded.
right_rotated( Int32 n, Int32 num_bits ).Int32
Returns 'n' with its bits right-rotated by 'num_bits' digits.
right_rotated( Int64 n, Int32 num_bits ).Int64
Returns 'n' with its bits right-rotated by 'num_bits' digits.
right_shifted( Int32 n, Int32 num_bits ).Int32
Returns 'n' with its bits right-shifted by 'num_bits' digits.
Zero bits are shifted in on the right side.
right_shifted( Int64 n, Int32 num_bits ).Int64
Returns 'n' with its bits right-shifted by 'num_bits' digits.
Zero bits are shifted in on the right side.
right_xshifted( Int32 n, Int32 num_bits ).Int32
Returns 'n' with its bits right-shifted by 'num_bits' digits.
The most significant bit is duplicated with each shift to
preserve the sign of the number.
right_xshifted( Int64 n, Int32 num_bits ).Int64
Returns 'n' with its bits right-shifted by 'num_bits' digits.
The most significant bit is duplicated with each shift to
preserve the sign of the number.
rotate( Vector2 v, Radians rad ).Vector2
Rotates 'v' around the origin by the given number of radians.
rotate( Vector2 v, Degrees deg ).Vector2
Rotates 'v' around the origin by the given number of degrees.
round_off( Vector2 v ).Vector2
Returns the vector containing the rounded-off values of each
component of 'v'.
round_off( Real64 n ).Real64
Returns the value of 'n' rounded off.
rounded_up_to_power_of_two( Int32 n ).Int32println( round_off(3.4) ) #prints: 3 println( round_off(3.5) ) #prints: 4 println( round_off(-3.4) ) #prints: -4 println( round_off(-3.5) ) #prints: -3
Returns 'n' rounded up to the next power of 2. If it is
already a power of two it is returned unmodified.
scale( Circle circle, Real64 factor ).CircleRequires: n >= 0Invariant: 2^(result-1) < n and 2^(result) >= n
Scales the radius of 'circle' by 'factor'.
scale( Rect rect, Real64 factor ).Rect
Scales the size of 'rect' by 'factor'.
scale( Rect rect, Vector2 factor ).Rect
Scales the size of 'rect' by 'factor'.
set_alpha_source( Int32 image_index, Int32 alpha_src_image_index )
Internal use.
set_fullscreen( Boolean setting )Sets the given image to its colors but the alpha of the other given image.
Sets the application to fullscreen
if the setting is "true" or windowed mode if it's "false".
set_image( Int32 image_index, Bitmap new_bitmap )
Copies the pixel data from 'new_bitmap' into the
hardware-accelerated image at the given index. Useful for
dynamically-generated bitmaps and more efficient than calling
create_image(Bitmap) repeatedly.
set_up_stdio()Note: the resulting image is always in rgb32 format.
Sets up stdin and stdout.
set_uv( Int32 image_index, Corners corners )
Internal use.
sign( Real64 n ).Real64Sets the (u,v) coordinate pairs for the top-left and bottom right of the given image.
Returns the sign of 'n' as an Real64 value:
sign( Int32 n ).Int321 when n > 0 -1 when n < 0 0 when n == 0
Returns the sign of 'n' as an Int32 value:
sign( Int64 n ).Int641 when n > 0 -1 when n < 0 0 when n == 0
Returns the sign of 'n' as an Int64 value:
sin( Radians rad ).Real641 when n > 0 -1 when n < 0 0 when n == 0
Returns the sine value of angle 'rad'.
sin( Degrees deg ).Real64Given a vector of angle 'rad', the sine value tells us what proportion of that line lies along the y axis.
Returns the sine value of angle 'deg'.
size_of( Corners c ).Vector2Given a vector of angle 'deg', the sine value tells us what proportion of that line lies along the y axis.
Returns the size of 'c'. Equivalent to
sleep( Int32 ms )(c.bottom_right - c.top_left).
Puts this program to sleep for the given number of milliseconds.
For example, to sleep for 2.5 seconds:
sqrt( Int32 n ).Int32sleep( 2500 )
Returns the square root of 'n'.
sqrt( Real64 n ).Real64
Returns the square root of 'n'.
sqrt( Int64 n ).Int64
Returns the square root of 'n'.
surround( Circle c1, Circle c2 ).Circle
Creates a circle just big enough to contain both given circles.
surround( Rect rect ).Circle
Creates a circle just big enough to contain the given rectangle.
surround( Line line ).Circle
Creates a circle just big enough to contain the given line.
tan( Radians rad ).Real64
Returns the tangent value of angle 'rad'.
tan( Degrees deg ).Real64Given a vector of angle 'rad', the tangent value gies us the slope (y/x) of that vector.
Returns the tangent value of angle 'deg'.
time_ms().Int64Given a vector of angle 'deg', the tangent value gies us the slope (y/x) of that vector.
Returns the current time in milliseconds since January 1,
1970.
to_Degrees( Radians rad ).DegreesExample: local var start_ms = time_ms ...code... local var elapsed_ms = time_ms - start_ms println( "Elapsed time: $ seconds" (elapsed_ms / 1000.0) )
Converts the given value from radians into degrees.
to_Radians( Degrees deg ).Radians
Converts the given value from degrees into radians.
to_String( Real64 n ).String
Returns a string representation of 'n'.
to_String( Object obj ).String
Returns the string representation of the given object.
Returns "null" if the 'obj' reference is null, else returns
the result of obj.to_String().
to_String( Int8 n, Int32 base ).String
Returns a string representation of 'n' in the specified base.
If 'base' is 2 or 16 then exactly 8 or 2 digits will be
returned, respectively.
to_String( Line line ).String
Returns a string representation of 'line'.
to_String( Int64 n ).String
Returns a string representation of 'n'.
to_String( Int32 n ).String
Returns a string representation of 'n'.
to_String( Circle circle ).String
Returns a string representation of 'circle'.
to_String( Ternary n ).String
Returns a string representation of boolean 'n' as "yes",
"no", or "void".
to_String( Degrees deg ).String
Returns a string representation of the given value in degrees.
to_String( Radians rad ).String
Returns a string representation of the given radians value.
to_String( Boolean n ).String
Returns a string representation of boolean 'n' as "true"
or "false".
to_String( Char ch, Int32 base ).String
Returns a string representation of 'n' in the specified base.
If 'base' is 2 or 16 then exactly 16 or 8 digits will be
returned, respectively. Note that to_String('A') returns
"A" while to_String('A',10) returns "65".
to_String( Color c ).String
Returns a string representation of 'c'.
to_String( HSV hsv ).String
Returns a string representation of 'hsv'.
to_String( Vector2 v ).String
Returns a string representation of 'v'.
to_String( Rect r ).String
Returns a string representation of 'r'.
to_String( Corners c ).String
Returns a string representation of 'c'.
to_String( Quad q ).String
Returns a string representation of 'q'.
to_String( ParsePos p ).String
Returns a string representation of the given ParsePos.
to_String( Byte n, Int32 base ).String
Returns a string representation of 'n' in the specified base.
If 'base' is 2 or 16 then exactly 8 or 2 digits will be
returned, respectively.
to_String( Int64 n, Int32 base ).String
Returns a string representation of 'n' in the specified base.
If 'base' is 2 or 16 then exactly 64 or 16 digits will be
returned, respectively.
to_String( Int16 n, Int32 base ).String
Returns a string representation of 'n' in the specified base.
If 'base' is 2 or 16 then exactly 16 or 4 digits will be
returned, respectively.
to_String( Int32 n, Int32 base ).String
Returns a string representation of 'n' in the specified base.
If 'base' is 2 or 16 then exactly 32 or 8 digits will be
returned, respectively.
to_String( Byte n ).String
Returns a string representation of 'n'.
to_String( Char ch ).String
Returns a string representation of 'ch'. This will be a
string containing 'ch' as its single character.
to_String( RealColor argb ).String
Returns a string representation of 'argb'.
to_value( Char ch ).Int32
Converts the character 'ch' into the value it represents
where '0'..'9' represent values 0..9 and 'a'..'z' (or
'A'..'Z' represent values 10..35.
top_left_of( Rect r ).Vector2Returns: 0..35
Returns the top-left coordinate of 'r'.
top_right_of( Rect r ).Vector2
Returns the top-right coordinate of 'r'.
trace( String mesg )
Prints the given trace message to the screen as well as
logging it to "log.txt".
trace( Vector2 v )
Traces 'v' as a text message.
type_name( Real64 n ).String
Returns "Real64".
type_name( Int64 n ).String
Returns "Int64".
type_name( Boolean n ).String
Returns "Boolean".
type_name( Real32 n ).String
Returns "Real32".
type_name( Ternary n ).String
Returns "Ternary".
type_name( Int8 n ).String
Returns "Int8".
type_name( Int16 n ).String
Returns "Int16".
type_name( Int32 n ).String
Returns "Int32".
type_name( Byte n ).String
Returns "Byte".
type_name( Char n ).String
Returns "Char".
width_of( Rect r ).Real64
Returns the width of 'r'.
wrap( Real64 num, Real64 low, Real64 high ).Real64
Returns 'num' constrained to the number cycle low..high;
similar to modulo.
wrap( Int32 num, Int32 low, Int32 high ).Int32Example: println( wrap( 2.2, 0.0, 1.0) ) #prints: 0.2000 println( wrap(-1.4, 0.0, 1.0) ) #prints: 0.6000
Returns 'num' constrained to the number cycle low..high;
similar to modulo.
wrap( Int64 num, Int64 low, Int64 high ).Int64Example: println( wrap(8,1,6) ) #prints: 2 println( wrap(-7,1,6) ) #prints: 5
Returns 'num' constrained to the number cycle low..high;
similar to modulo.
x1_of( Corners c ).Real64Example: println( wrap(8,1,6) ) #prints: 2 println( wrap(-7,1,6) ) #prints: 5
Returns the leftmost x coordinate of 'c'.
x1_of( Circle circle ).Real64
Returns the leftmost coordinate of the given circle.
x1_of( Rect r ).Real64
Returns the leftmost x coordinate of 'r'.
x2_of( Corners c ).Real64
Returns the rightmost x coordinate of 'c'.
x2_of( Rect r ).Real64
Returns the rightmost x coordinate of 'r'.
x2_of( Circle circle ).Real64
Returns the rightmost coordinate of the given circle.
y1_of( Rect r ).Real64
Returns the topmost y coordinate of 'r'.
y1_of( Corners c ).Real64
Returns the topmost y coordinate of 'c'.
y1_of( Circle circle ).Real64
Returns the topmost coordinate of the given circle.
y2_of( Rect r ).Real64
Returns the bottommost y coordinate of 'r'.
y2_of( Corners c ).Real64
Returns the bottommost y coordinate of 'c'.
y2_of( Circle circle ).Real64
Returns the bottommost coordinate of the given circle.
|
| Object Methods |
|---|
|
compare_to( Object other ).Ternary
This method is used for ordering (quantitative) comparisons
between this object and another.
create_duplicate().ObjectReturns 'eq' if they're equivalent, 'lt' if this object is "less than" the other, or 'gt' if this object is "greater than" another. The compiler converts: 'obj1 < obj2' -> 'obj1.compare_to(obj2) == lt' 'obj1 > obj2' -> 'obj1.compare_to(obj2) == gt' 'obj1 <= obj2' -> 'obj1.compare_to(obj2) != gt' 'obj1 >= obj2' -> 'obj1.compare_to(obj2) != lt'Implementations of compare_to() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract:
if (obj1.compare_to(obj2) == eq)
obj1.equals(obj2) == true
obj1.hash_code == obj2.hash_code
else
obj1.equals(obj2) == false
endIf
Note that two "equal" objects *must* have the same hash code,
but "unequal" objects may or may not have the same hash code.
This default implementation throws an UnsupportedMethodError.
Should create a duplicate of this object such that
obj1.equals(obj1.create_duplicate) return true.
equals( Object other ).BooleanThe command duplicate(obj) is transformed by the compiler into Object.create_duplicate(obj), which then calls this method. For optimal performance (by removing an internal typecast in most situations), have your overridden create_duplicate have the same return type as the class it's defined in. For instance, Strings implementation is 'create_duplicate.String'. This default implementation throws an UnsupportedMethodError.
Returns true if this object is equivalant to another.
hash_code().Int32The compiler converts 'obj1 == obj2' into 'obj1.equals(obj2)' and 'obj1 != obj2' into 'not obj1.equals(obj2)'. Implementations of equals() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract: if (obj1.equals(obj2)) obj1.compare_to(obj2) == eq obj1.hash_code == obj2.hash_code else obj1.compare_to(obj2) != eq endIfNote that two "equal" objects *must* have the same hash code, but "unequal" objects may or may not have the same hash code. This default implementation returns true if the this object and the 'other' reference are the same object ('this is other').
Returns the hash code of this object, which some classes
(like HashTable) rely on. This default implementation
throws an UnsupportedMethodError.
to_String().StringHash codes are used to quickly test and see if two complex objects are NOT equal. The value returned has no intrinsic meaning, but should conform to the following rules: 1. Two objects that are equivalent should produce the same hash code. 2. If an object's state doesn't change, its hash code shouldn't change either. Internally, this precludes the hash code being based on an object's memory address since Slag doesn't guarantee that an object's address won't change over time. This has the following implications: If you override hash_code you should also override equals() and possibly compare_to() and ensure the following contract. Invariant:
if (obj1.hash_code != obj2.hash_code)
obj1.equals(obj2) == false
obj1.compare_to(obj2) != eq
endIf
Returns:
type_name().StringA String representation of this object. Most classes should override this method to summarize an object's state for convenience in testing and debugging.
Returns the true class name of this object. Implemented by
the runtime; you should not override this method.
Example: local Object obj = "Hello World" println( obj.type_name ) #prints: String |
Enumeration of valid "handle" or "hot spot" categories for drawing images. See Image::handle.
| Categories |
|---|
|
bottom_center bottom_left bottom_right center left_center right_center top_center top_left top_right |
| Class Variables |
|---|
|
definitions : HashTable<<String,EnumType>>
Internal use - hashtable of names->categories.
values : EnumType[]
Internal use - a list of the category objects in this
enumeration.
|
| Class Methods |
|---|
|
by_name( String name ).EnumType
Returns the category object corresponding to the given string
name.
by_ordinal( Int32 ordinal ).EnumTypeContract:
FRUIT.by_name("banana") == FRUIT.banana
Returns the category object corresponding to the given
ordinal position.
create_duplicate( Object existing ).ObjectContract:
if (FRUIT.banana.ordinal == 2)
FRUIT.by_ordinal(2) == FRUIT.banana
endIf
This factory method initiates object duplication. The
compiler transforms the duplicate(obj) command into
Object.create_duplicate(obj).
includes( String name ).BooleanReturns: 'null' if 'existing' is null. existing.create_duplicate otherwise
Returns "true" if the given name is a category of this
enumeration.
set_up_def( EnumType enum_def, String name ).EnumTypeExample:
FRUIT.includes("carrot") -> false
Internal use.
|
| Object Variables |
|---|
|
name : String
The name of this category. This is a string with the
the same as the enum categery.
ordinal : Int32Suit.spades.name == "spades"
The positional index value of this enumeration category,
corresponding to the order that the categories were
declared in (starting at zero).
enum Suit
CATEGORIES
spades, hearts, clubs, diamonds
endEnum
... Suit.spades.ordinal == 0 Suit.diamonds.ordinal == 3 |
| Object Methods |
|---|
|
compare_to( Object other ).Ternary
This method is used for ordering (quantitative) comparisons
between this object and another.
compare_to( EnumType other ).TernaryReturns 'eq' if they're equivalent, 'lt' if this object is "less than" the other, or 'gt' if this object is "greater than" another. The compiler converts: 'obj1 < obj2' -> 'obj1.compare_to(obj2) == lt' 'obj1 > obj2' -> 'obj1.compare_to(obj2) == gt' 'obj1 <= obj2' -> 'obj1.compare_to(obj2) != gt' 'obj1 >= obj2' -> 'obj1.compare_to(obj2) != lt'Implementations of compare_to() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract:
if (obj1.compare_to(obj2) == eq)
obj1.equals(obj2) == true
obj1.hash_code == obj2.hash_code
else
obj1.equals(obj2) == false
endIf
Note that two "equal" objects *must* have the same hash code,
but "unequal" objects may or may not have the same hash code.
This default implementation throws an UnsupportedMethodError.
Returns the relative ordering (lt, eq, gt) of this enum's
ordinal versus the ordinal of the given enum.
create_duplicate().Object
Should create a duplicate of this object such that
obj1.equals(obj1.create_duplicate) return true.
equals( Object other ).BooleanThe command duplicate(obj) is transformed by the compiler into Object.create_duplicate(obj), which then calls this method. For optimal performance (by removing an internal typecast in most situations), have your overridden create_duplicate have the same return type as the class it's defined in. For instance, Strings implementation is 'create_duplicate.String'. This default implementation throws an UnsupportedMethodError.
Returns true if this object is equivalant to another.
hash_code().Int32The compiler converts 'obj1 == obj2' into 'obj1.equals(obj2)' and 'obj1 != obj2' into 'not obj1.equals(obj2)'. Implementations of equals() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract: if (obj1.equals(obj2)) obj1.compare_to(obj2) == eq obj1.hash_code == obj2.hash_code else obj1.compare_to(obj2) != eq endIfNote that two "equal" objects *must* have the same hash code, but "unequal" objects may or may not have the same hash code. This default implementation returns true if the this object and the 'other' reference are the same object ('this is other').
Returns the hash code of this object, which some classes
(like HashTable) rely on. This default implementation
throws an UnsupportedMethodError.
init()Hash codes are used to quickly test and see if two complex objects are NOT equal. The value returned has no intrinsic meaning, but should conform to the following rules: 1. Two objects that are equivalent should produce the same hash code. 2. If an object's state doesn't change, its hash code shouldn't change either. Internally, this precludes the hash code being based on an object's memory address since Slag doesn't guarantee that an object's address won't change over time. This has the following implications: If you override hash_code you should also override equals() and possibly compare_to() and ensure the following contract. Invariant:
if (obj1.hash_code != obj2.hash_code)
obj1.equals(obj2) == false
obj1.compare_to(obj2) != eq
endIf
Default initializer.
next().EnumType
Returns the category that was defined after this one.
next_in_cycle().EnumTypeExample: Suit.spades.next == Suit.hearts Suit.diamonds.next is null
Like 'next' but wraps around from the last to the first.
previous().EnumTypeExample: Suit.spades.next_in_cycle == Suit.hearts Suit.diamonds.next_in_cycle == Suit.spades
Returns the category that was defined before this one.
previous_in_cycle().EnumTypeExample: Suit.spades.previous is null Suit.diamonds.previous == Suit.clubs
Like 'previous' but wraps around from the last to the first.
to_String().StringExample: Suit.spades.previous_in_cycle == Suit.diamonds Suit.diamonds.previous_in_cycle == Suit.clubs
Returns 'name'
type_name().String
Returns the true class name of this object. Implemented by
the runtime; you should not override this method.
Example: local Object obj = "Hello World" println( obj.type_name ) #prints: String |
Defines a color using real number hue, saturation, and value color components, each 0..1.0.
HSV-related methods in class Global
new_Color( HSV hsv ).Color
new_RealColor( HSV hsv ).RealColor
print( HSV hsv )
println( HSV hsv )
to_String( HSV hsv ).String
| Composite Elements |
|---|
|
hue : Real64 saturation : Real64 value : Real64 |
Defines a lookup table that uses chained hashing (bins of linked lists) to associate key/value pairs. All the keys must be of the same datatype and all the values must be of the same datatype, but the keys can be different datatypes from the values.
The following requirements must be met for the following types to be used as KeyType:
primitive (Int32, Real64, etc)
No restrictions.
compound
You must define the following class method:
Global::hash_code(CompoundType c).Int32
reference
You must override hash_code.Int32 in the class type.
Class String already defines hash_code.
See Object::hash_code() for more information on creating hash
codes.
HashTable defaults to 16 bins with an average bin size of 3 - once the average number of entries per bin exceeds 3 the number of bins is doubled. Alternate values may be specified in the initializer.
Example:
local HashTable<<String,Int32>> numbers() numbers[ "one" ] = 1 numbers[ "two" ] = 2 numbers[ "three" ] = 3 ...local HashTable<<String,Int32>> factors() factors[ "hundred" ] = 10^2 factors[ "thousand" ] = 10^3 factors[ "million" ] = 10^6 ...
local String word_form = "two million" local String[] words = word_form.tidy.split println( numbers[words[0]] * factors[words[1]] ) #prints: 2000000
| Class Methods |
|---|
|
create_duplicate( Object existing ).Object
This factory method initiates object duplication. The
compiler transforms the duplicate(obj) command into
Object.create_duplicate(obj).
Returns: 'null' if 'existing' is null. existing.create_duplicate otherwise |
| Object Variables |
|---|
|
average_bin_size : Real64
Limit of the average bin size. If there are 16 bins and an
average_bin_size of 3, the table will expand once there
are 3 items in each bin (3*16=48 items total, 48/16 bins=3
avg) or when a single bin has 48 items (48 / 16 = 3 avg).
This value is used to calculate the max_entries before the
table expands.
bins : HashTableBin<<KeyType,ValueType>>[]hash_mask : Int32
Internal use. Set to the number of bins-1. E.g. for 16 bins
the mask is 15, since hash_code & 15 -> 0..15
max_bins : Int32
The number of bins (default: 512 ) at which the table will
stop auto-expanding # and instead continue to fill the
existing bins however large they may get.
max_entries : Real64
Recalculated from average_bin_size each time the table
expands.
num_entries : Int32 |
| Object Methods |
|---|
|
clear()
Removes all mappings from this hash table.
compare_to( Object other ).Ternary
This method is used for ordering (quantitative) comparisons
between this object and another.
contains( KeyType key ).BooleanReturns 'eq' if they're equivalent, 'lt' if this object is "less than" the other, or 'gt' if this object is "greater than" another. The compiler converts: 'obj1 < obj2' -> 'obj1.compare_to(obj2) == lt' 'obj1 > obj2' -> 'obj1.compare_to(obj2) == gt' 'obj1 <= obj2' -> 'obj1.compare_to(obj2) != gt' 'obj1 >= obj2' -> 'obj1.compare_to(obj2) != lt'Implementations of compare_to() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract:
if (obj1.compare_to(obj2) == eq)
obj1.equals(obj2) == true
obj1.hash_code == obj2.hash_code
else
obj1.equals(obj2) == false
endIf
Note that two "equal" objects *must* have the same hash code,
but "unequal" objects may or may not have the same hash code.
This default implementation throws an UnsupportedMethodError.
Returns "true" if 'key' has an associated value in this table
that can be retrieved with get().
count().Int32
Returns the number of mappings in this table.
create_duplicate().Object
Should create a duplicate of this object such that
obj1.equals(obj1.create_duplicate) return true.
equals( Object other ).BooleanThe command duplicate(obj) is transformed by the compiler into Object.create_duplicate(obj), which then calls this method. For optimal performance (by removing an internal typecast in most situations), have your overridden create_duplicate have the same return type as the class it's defined in. For instance, Strings implementation is 'create_duplicate.String'. This default implementation throws an UnsupportedMethodError.
Returns true if this object is equivalant to another.
expand_table()The compiler converts 'obj1 == obj2' into 'obj1.equals(obj2)' and 'obj1 != obj2' into 'not obj1.equals(obj2)'. Implementations of equals() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract: if (obj1.equals(obj2)) obj1.compare_to(obj2) == eq obj1.hash_code == obj2.hash_code else obj1.compare_to(obj2) != eq endIfNote that two "equal" objects *must* have the same hash code, but "unequal" objects may or may not have the same hash code. This default implementation returns true if the this object and the 'other' reference are the same object ('this is other').
Resizes this hash table to have double the number of bins as
before.
find( KeyType key ).Mapping<<KeyType,ValueType>>
Finds the underlying Mapping that defines the mapping
between 'key' and 'value'. Returns a null reference if no
mapping is present. Useful for optimizing conditional table
operations.
get( KeyType key ).ValueTypeExample without find():
if (table.contains(id))
person = table[id]
endIf
Example with find() - a bit faster:
local var mapping = table.find(id)
if (mapping isNot null)
person = mapping.value
endIf
Retrieves the value (previously mapped with set()) associated
with 'key'. Throws a NoSuchElementError if 'key' has not been
defined.
get_bin( KeyType key ).HashTableBin<<KeyType,ValueType>>hash_code().Int32
Returns the hash code of this object, which some classes
(like HashTable) rely on. This default implementation
throws an UnsupportedMethodError.
init( [Int32 num_bins], [Real64 average_bin_size] )Hash codes are used to quickly test and see if two complex objects are NOT equal. The value returned has no intrinsic meaning, but should conform to the following rules: 1. Two objects that are equivalent should produce the same hash code. 2. If an object's state doesn't change, its hash code shouldn't change either. Internally, this precludes the hash code being based on an object's memory address since Slag doesn't guarantee that an object's address won't change over time. This has the following implications: If you override hash_code you should also override equals() and possibly compare_to() and ensure the following contract. Invariant:
if (obj1.hash_code != obj2.hash_code)
obj1.equals(obj2) == false
obj1.compare_to(obj2) != eq
endIf
Initializes this hash table with the given number of bins
(default 16) and the given average_bin_size (default 3.0).
keys().HashTableKeyReader<<KeyType,ValueType>>
Returns a reader that iterates through this hash table's keys.
These are not guaranteed to be an any particular order.
remove( KeyType key ).ValueTypeExample:
local HashTable<<String,Int32>> ages()
ages["Abe"] = 34
ages["Murphy"] = 30
ages["Matt"] = 28
forEach (name in ages.keys)
println( "$ is $ years old." (name,ages[name]) )
#prints:
# Abe is 34 years old.
# Matt is 28 years old.
# Murphy is 30 years old.
endForEach
Removes the mapping between 'key' and its value from this table.
Throws a NoSuchElementError if 'key' has not been defined.
set( Mapping<<KeyType,ValueType>> entry )
Associates the given value with the given key. When get() is
called with 'key', 'value' will be returned.
set( KeyType key, ValueType value )
Associates the given value with the given key. When get() is
called with 'key', 'value' will be returned.
to_String().String
Returns a string representation of this hashtable.
type_name().String
Returns the true class name of this object. Implemented by
the runtime; you should not override this method.
values().HashTableValueReader<<KeyType,ValueType>>Example: local Object obj = "Hello World" println( obj.type_name ) #prints: String
Returns a reader that iterates through this hash table's values.
These are not guaranteed to be an any particular order.
|
Internal use. A linked list of key/value mappings for a given hashcode bin.
| Class Methods |
|---|
|
create_duplicate( Object existing ).Object
This factory method initiates object duplication. The
compiler transforms the duplicate(obj) command into
Object.create_duplicate(obj).
Returns: 'null' if 'existing' is null. existing.create_duplicate otherwise |
| Object Variables |
|---|
|
entries : Mapping<<KeyType,ValueType>>[] |
| Object Methods |
|---|
|
add_entry( KeyType key, ValueType value ).Boolean add_entry( Mapping<<KeyType,ValueType>> entry ).Boolean clear() compare_to( Object other ).Ternary
This method is used for ordering (quantitative) comparisons
between this object and another.
create_duplicate().ObjectReturns 'eq' if they're equivalent, 'lt' if this object is "less than" the other, or 'gt' if this object is "greater than" another. The compiler converts: 'obj1 < obj2' -> 'obj1.compare_to(obj2) == lt' 'obj1 > obj2' -> 'obj1.compare_to(obj2) == gt' 'obj1 <= obj2' -> 'obj1.compare_to(obj2) != gt' 'obj1 >= obj2' -> 'obj1.compare_to(obj2) != lt'Implementations of compare_to() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract:
if (obj1.compare_to(obj2) == eq)
obj1.equals(obj2) == true
obj1.hash_code == obj2.hash_code
else
obj1.equals(obj2) == false
endIf
Note that two "equal" objects *must* have the same hash code,
but "unequal" objects may or may not have the same hash code.
This default implementation throws an UnsupportedMethodError.
Should create a duplicate of this object such that
obj1.equals(obj1.create_duplicate) return true.
equals( Object other ).BooleanThe command duplicate(obj) is transformed by the compiler into Object.create_duplicate(obj), which then calls this method. For optimal performance (by removing an internal typecast in most situations), have your overridden create_duplicate have the same return type as the class it's defined in. For instance, Strings implementation is 'create_duplicate.String'. This default implementation throws an UnsupportedMethodError.
Returns true if this object is equivalant to another.
find_entry( KeyType key ).Mapping<<KeyType,ValueType>>The compiler converts 'obj1 == obj2' into 'obj1.equals(obj2)' and 'obj1 != obj2' into 'not obj1.equals(obj2)'. Implementations of equals() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract: if (obj1.equals(obj2)) obj1.compare_to(obj2) == eq obj1.hash_code == obj2.hash_code else obj1.compare_to(obj2) != eq endIfNote that two "equal" objects *must* have the same hash code, but "unequal" objects may or may not have the same hash code. This default implementation returns true if the this object and the 'other' reference are the same object ('this is other'). hash_code().Int32
Returns the hash code of this object, which some classes
(like HashTable) rely on. This default implementation
throws an UnsupportedMethodError.
index_of_entry( KeyType key ).Int32Hash codes are used to quickly test and see if two complex objects are NOT equal. The value returned has no intrinsic meaning, but should conform to the following rules: 1. Two objects that are equivalent should produce the same hash code. 2. If an object's state doesn't change, its hash code shouldn't change either. Internally, this precludes the hash code being based on an object's memory address since Slag doesn't guarantee that an object's address won't change over time. This has the following implications: If you override hash_code you should also override equals() and possibly compare_to() and ensure the following contract. Invariant:
if (obj1.hash_code != obj2.hash_code)
obj1.equals(obj2) == false
obj1.compare_to(obj2) != eq
endIf
init( Int32 initial_capacity ) to_String().String type_name().String
Returns the true class name of this object. Implemented by
the runtime; you should not override this method.
Example: local Object obj = "Hello World" println( obj.type_name ) #prints: String |
Reader that iterates through a HashTable's keys.
| Class Methods |
|---|
|
create_duplicate( Object existing ).Object
This factory method initiates object duplication. The
compiler transforms the duplicate(obj) command into
Object.create_duplicate(obj).
Returns: 'null' if 'existing' is null. existing.create_duplicate otherwise |
| Object Variables |
|---|
|
bins : Reader<<HashTableBin<<KeyType,ValueType>>>> entries : Reader<<Mapping<<KeyType,ValueType>>>> |
| Object Methods |
|---|
|
available().Int32
Returns the minimum number of additional values that can be
immediately read from this reader.
close()If the reader is exhausted or if it must block to peek or read next then the result will be 0. It is important to note that '0' does not necessarily mean the reader is exhausted. Many readers will report that they have 1 available even if there are thousands of values waiting to be read. The 'available' property should be used as an aide for buffer sizes and the like but should not be taken as an absolute size.
Closes this reader as a source of input. Useful for file
readers, but for most others this command does nothing.
compare_to( Object other ).Ternary
This method is used for ordering (quantitative) comparisons
between this object and another.
consume( DataType look_for ).BooleanReturns 'eq' if they're equivalent, 'lt' if this object is "less than" the other, or 'gt' if this object is "greater than" another. The compiler converts: 'obj1 < obj2' -> 'obj1.compare_to(obj2) == lt' 'obj1 > obj2' -> 'obj1.compare_to(obj2) == gt' 'obj1 <= obj2' -> 'obj1.compare_to(obj2) != gt' 'obj1 >= obj2' -> 'obj1.compare_to(obj2) != lt'Implementations of compare_to() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract:
if (obj1.compare_to(obj2) == eq)
obj1.equals(obj2) == true
obj1.hash_code == obj2.hash_code
else
obj1.equals(obj2) == false
endIf
Note that two "equal" objects *must* have the same hash code,
but "unequal" objects may or may not have the same hash code.
This default implementation throws an UnsupportedMethodError.
Attempts to match and discard the next value from this
reader, returning true, or else leaves the next value still
pending and returns false.
create_duplicate().ObjectReturns: "true" if old.peek == look_for "false" if old.peek != look_forInvariant: if (old.peek == look_for) old.skip
Should create a duplicate of this object such that
obj1.equals(obj1.create_duplicate) return true.
equals( Object other ).BooleanThe command duplicate(obj) is transformed by the compiler into Object.create_duplicate(obj), which then calls this method. For optimal performance (by removing an internal typecast in most situations), have your overridden create_duplicate have the same return type as the class it's defined in. For instance, Strings implementation is 'create_duplicate.String'. This default implementation throws an UnsupportedMethodError.
Returns true if this object is equivalant to another.
has_another().BooleanThe compiler converts 'obj1 == obj2' into 'obj1.equals(obj2)' and 'obj1 != obj2' into 'not obj1.equals(obj2)'. Implementations of equals() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract: if (obj1.equals(obj2)) obj1.compare_to(obj2) == eq obj1.hash_code == obj2.hash_code else obj1.compare_to(obj2) != eq endIfNote that two "equal" objects *must* have the same hash code, but "unequal" objects may or may not have the same hash code. This default implementation returns true if the this object and the 'other' reference are the same object ('this is other').
Returns "true" if this reader has another value that can
be previewed with peek() or read with read().
hash_code().Int32
Returns the hash code of this object, which some classes
(like HashTable) rely on. This default implementation
throws an UnsupportedMethodError.
init( Reader<<HashTableBin<<KeyType,ValueType>>>> bins )Hash codes are used to quickly test and see if two complex objects are NOT equal. The value returned has no intrinsic meaning, but should conform to the following rules: 1. Two objects that are equivalent should produce the same hash code. 2. If an object's state doesn't change, its hash code shouldn't change either. Internally, this precludes the hash code being based on an object's memory address since Slag doesn't guarantee that an object's address won't change over time. This has the following implications: If you override hash_code you should also override equals() and possibly compare_to() and ensure the following contract. Invariant:
if (obj1.hash_code != obj2.hash_code)
obj1.equals(obj2) == false
obj1.compare_to(obj2) != eq
endIf
is_exhausted().Boolean
Returns "true" if this reader does not have another value
or "false" if it does.
peek().KeyType
Returns the next value that will be returned from read().
If there is no next value then a NoNextValueError is thrown.
position( Int32 new_position )
This optional property-write sets the zero-based read position
of this reader. When a reader is first created position()
returns 0. After a single read() it returns 1, and so on.
Readers that don't implement this property will throw an
UnsupportedMethodError when it's accessed.
position().Int32
This optional property-read returns the zero-based read
position of this reader. When a reader is first created
position() returns 0. After a single read() it returns 1,
and so on.
prep_next()Readers that don't implement this property will throw an UnsupportedMethodError when it's accessed.
Prepares the next value that will be used by peek() and
read(). As a composite range reader, this involves advancing
to the next range reader if the current range reader is
empty.
read().KeyType
Returns the next value from this reader. If (not has_another)
then a NoNextValueError is thrown.
read_line().String
Reads and returns the next line of characters up to the next
LF or CRLF. The CRLF characters are not part of
the return value and are discarded.
read_list( Int32 size ).DataType[]Only defined for Reader<<Char>>.
Reads the next 'size' number of values and returns them in a
list. Requires that there are at least 'size' number of
values remaining to be read.
remaining().Int32
This optional property returns how many values remain to be
read before the reader is exhausted. Not all readers
can implement this property; those that don't will throw
an UnsupportedMethodError when it's accessed.
rewind()
This optional method resets this reader so that the next
read() will return the first value of the series.
Readers that don't implement this property will throw an
UnsupportedMethodError when it's accessed.
skip( [Int32 skip_count] )
Discards exactly the next 'skip_count' number of values
rather than reading them. If there are not enough values
remaining then a NoNextValueError will be thrown from read().
to_List().DataType[]This program fragment: local var a = reader.read reader.read reader.read local var b = reader.readis equivalent to this: local var a = reader.read reader.skip(2) local var b = reader.read
Creates and returns a list of all the remaining values of
this reader.
to_String().String
Returns a string representation of this reader's values.
type_name().String
Returns the true class name of this object. Implemented by
the runtime; you should not override this method.
Example: local Object obj = "Hello World" println( obj.type_name ) #prints: String |
Reader that iterates through a HashTable's values.
| Class Methods |
|---|
|
create_duplicate( Object existing ).Object
This factory method initiates object duplication. The
compiler transforms the duplicate(obj) command into
Object.create_duplicate(obj).
Returns: 'null' if 'existing' is null. existing.create_duplicate otherwise |
| Object Variables |
|---|
|
bins : Reader<<HashTableBin<<KeyType,ValueType>>>> entries : Reader<<Mapping<<KeyType,ValueType>>>> |
| Object Methods |
|---|
|
available().Int32
Returns the minimum number of additional values that can be
immediately read from this reader.
close()If the reader is exhausted or if it must block to peek or read next then the result will be 0. It is important to note that '0' does not necessarily mean the reader is exhausted. Many readers will report that they have 1 available even if there are thousands of values waiting to be read. The 'available' property should be used as an aide for buffer sizes and the like but should not be taken as an absolute size.
Closes this reader as a source of input. Useful for file
readers, but for most others this command does nothing.
compare_to( Object other ).Ternary
This method is used for ordering (quantitative) comparisons
between this object and another.
consume( DataType look_for ).BooleanReturns 'eq' if they're equivalent, 'lt' if this object is "less than" the other, or 'gt' if this object is "greater than" another. The compiler converts: 'obj1 < obj2' -> 'obj1.compare_to(obj2) == lt' 'obj1 > obj2' -> 'obj1.compare_to(obj2) == gt' 'obj1 <= obj2' -> 'obj1.compare_to(obj2) != gt' 'obj1 >= obj2' -> 'obj1.compare_to(obj2) != lt'Implementations of compare_to() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract:
if (obj1.compare_to(obj2) == eq)
obj1.equals(obj2) == true
obj1.hash_code == obj2.hash_code
else
obj1.equals(obj2) == false
endIf
Note that two "equal" objects *must* have the same hash code,
but "unequal" objects may or may not have the same hash code.
This default implementation throws an UnsupportedMethodError.
Attempts to match and discard the next value from this
reader, returning true, or else leaves the next value still
pending and returns false.
create_duplicate().ObjectReturns: "true" if old.peek == look_for "false" if old.peek != look_forInvariant: if (old.peek == look_for) old.skip
Should create a duplicate of this object such that
obj1.equals(obj1.create_duplicate) return true.
equals( Object other ).BooleanThe command duplicate(obj) is transformed by the compiler into Object.create_duplicate(obj), which then calls this method. For optimal performance (by removing an internal typecast in most situations), have your overridden create_duplicate have the same return type as the class it's defined in. For instance, Strings implementation is 'create_duplicate.String'. This default implementation throws an UnsupportedMethodError.
Returns true if this object is equivalant to another.
has_another().BooleanThe compiler converts 'obj1 == obj2' into 'obj1.equals(obj2)' and 'obj1 != obj2' into 'not obj1.equals(obj2)'. Implementations of equals() must maintain the following general contract between equals(), compare_to(), and hash_code(). Contract: if (obj1.equals(obj2)) obj1.compare_to(obj2) == eq obj1.hash_code == obj2.hash_code else obj1.compare_to(obj2) != eq endIfNote that two "equal" objects *must* have the same hash code, but "unequal" objects may or may not have the same hash code. This default implementation returns true if the this object and the 'other' reference are the same object ('this is other').
Returns "true" if this reader has another value that can
be previewed with peek() or read with read().
hash_code().Int32
Returns the hash code of this object, which some classes
(like HashTable) rely on. This default implementation
throws an UnsupportedMethodError.
init( Reader<<HashTableBin<<KeyType,ValueType>>>> bins )Hash codes are used to quickly test and see if two complex objects are NOT equal. The value returned has no intrinsic meaning, but should conform to the following rules: 1. Two objects that are equivalent should produce the same hash code. 2. If an object's state doesn't change, its hash code shouldn't change either. Internally, this precludes the hash code being based on an object's memory address since Slag doesn't guarantee that an object's address won't change over time. This has the following implications: If you override hash_code you should also override equals() and possibly compare_to() and ensure the following contract. Invariant:
if (obj1.hash_code != obj2.hash_code)
obj1.equals(obj2) == false
obj1.compare_to(obj2) != eq
endIf
is_exhausted().Boolean
Returns "true" if this reader does not have another value
or "false" if it does.
peek().ValueType
Returns the next value that will be returned from read().
If there is no next value then a NoNextValueError is thrown.
position( Int32 new_position )
This optional property-write sets the zero-based read position
of this reader. When a reader is first created position()
returns 0. After a single read() it returns 1, and so on.
Readers that don't implement this property will throw an
UnsupportedMethodError when it's accessed.
position().Int32
This optional property-read returns the zero-based read
position of this reader. When a reader is first created
position() returns 0. After a single read() it returns 1,
and so on.
prep_next()Readers that don't implement this property will throw an UnsupportedMethodError when it's accessed.
Prepares the next value that will be used by peek() and
read(). As a composite range reader, this involves advancing
to the next range reader if the current range reader is
empty.
read().ValueType
Returns the next value from this reader. If (not has_another)
then a NoNextValueError is thrown.
read_line().String
Reads and returns the next line of characters up to the next
LF or CRLF. The CRLF characters are not part of
the return value and are discarded.
read_list( Int32 size ).DataType[]Only defined for Reader<<Char>>.
Reads the next 'size' number of values and returns them in a
list. Requires that there are at least 'size' number of
values remaining to be read.
remaining().Int32
This optional property returns how many values remain to be
read before the reader is exhausted. Not all readers
can implement this property; those that don't will throw
an UnsupportedMethodError when it's accessed.
rewind()
This optional method resets this reader so tha |