|
|
jsstd
summary jsstd module #labels doc
jsstd module
Static functions
- string Expand( str [, obj] )
Return an expanded string using key/value stored in obj.example:
Expand(' $(h) $(w)', { h:'Hello', w:'World' }); // returns "Hello World"
- InternString( string )
Make an interned string, a string that is automatically shared with other code that needs a string with the same value.
- Seal( obj )
Prevents all write access to the object, either to add a new property, delete an existing property, or set the value or attributes of an existing property.
- Clear( obj )
Removes all properties and elements from obj in a single operation.
- scope SetScope( obj, scopeObject )
Set the scope object of obj.example:
function foo() { var data = 55; function bar() { Print( data, '\n' ); } var old = SetScope( bar, {data:7} ); bar(); var old = SetScope( bar, old ); bar(); } foo();prints:7 55
- HideProperties( obj, propertyName1 [, propertyName2 [, ... ] ] )
Hide properties from for-in loop.
- value Exec( fileName [, useAndSaveCompiledScript = true] )
Executes the script specified by fileName. If useAndSaveCompiledScript is true, the function load and save a compiled version (using XDR format) of the script on the disk ( adding 'xrd' to fileName ). If the compiled file is not found, the uncompiled version is used instead.return value:
This function returns the last evaluated statement of the script.example:
var foo = Exec('constants.js'); // loads constants.js or constants.jsxrd if available.
- void Print( value1 [, value2 [, ...]] )
Display val to the output (the screen by default).example:
Print( 'Hello World', '\n' );
- boolean IsStatementValid( statementString )
Returns true if statementString is a valid Javascript statement. The intent is to support interactive compilation, accumulate lines in a buffer until IsStatementValid returns true, then pass it to an eval. This function is useful to write an interactive console.
- real TimeCounter()
Returns the current value of a fine time counter in millisecond. The returned value is a relative time value.
- MaybeCollectGarbage()
Performs a conditional garbage collection of JS objects, doubles, and strings that are no longer needed by a script executing. This offers the JavaScript engine an opportunity to perform garbage collection if needed.
- CollectGarbage()
Performs garbage collection in the JS memory pool.
- integer IdOf( value )
Returns an integer value that is a unique identifier of value .example:
var myObj = {}; Print( IdOf(myObj), '\n' );
- Warning( string )
Report a warning.
- void ASSERT( expression [, failureMessage ] )
If the argument expression compares equal to zero, the failureMessage is written to the standard error device and the program stops its execution.example:
var foo = ['a', 'b', 'c']; ASSERT( i >= 0 || i < 3, 'Invalid value.' ); Print( foo[i] );
- void Halt()
Stop the execution of the program. This is a ungraceful way to finish a program.
Static properties
- boolean isConstructing
Determines whether or not the function currently executing was called as a constructor.
jsstd::Buffer class
Buffer class is a simple buffer that allows arbitrary length input and output.
Functions
- Constructor( | Buffer object )
Constructs a Buffer object. If a string is given as argument, the buffer is initialized with this string. If buffer object is given, the buffer is initialized with this existing buffer object (kind of copy constructor).
- Write( data [, length] )
Add data in the buffer. If length is used, only the first length bytes of data are added.
- string Unread( data )
Insert data at the begining of the buffer. This function can undo a read operation. The returned value is data.example:
function Peek(len) { return buffer.Unread( buffer.Read(len) ); }
- string Read( [ amount ] )
Read amount data in the buffer. If amount is omited, The whole buffer is returned.If amount == undefined, an arbitrary (ideal) amount of data is returned. Use this when you don't know how many data you have to read.
example:
var chunk = buffer.Read(undefined);note:
The read operation never blocks, even if the requested amount of data is greater than the buffer length.
- string ReadUntil( boundaryString [, skip] )
Reads the buffer until it match the boundaryString, else it returns <undefined>. If skip argument is <true>, the boundaryString is skiped from the buffer.
- integer IndexOf( string )
Find string in the buffer and returns the offset of the first letter. If not found, this function returns -1.
- boolean Match( string )
- Skip( length )
Skip length bytes of data from the buffer.
Properties
- integer length
Is the current length of the buffer.
Callback functions
- onunderflow( bufferObject )
This function is called by the buffer when its length is less than the requested amount of data. bufferObject is the buffer object that caused the call. This function is called only once by read operation.example:
var buffer = new Buffer(); buffer.onunderflow = function(b) { b.Write('some more data...'); } buffer.Read(10000); buffer.Read(undefined);
Remarks
Buffer class supports NI_READ_RESOURCE.
example
var buf = new Buffer();
buf.Write('1234');
buf.Write('5');
buf.Write('');
buf.Write('6789');
Print( buf.Read() );example
var buf = new Buffer();
buf.Write('0123456789');
Print( buf.Read(4) );
Print( buf.Read(1) );
Print( buf.Read(1) );
Print( buf.Read(4) );jsstd::Pack class
Pack is a class that helps to convert binary data into Integer, Real or String and to write an integer in a binary data string. The Pack class manages the system endian or network endian.
Functions
- Constructor( buffer )
Constructs a Pack object from a Buffer object. This is the only way to read or write binary data.
- integer ReadInt( size, = false, = false )
- WriteInt( size, = false [, isNetworkEndian = false] )
- real ReadReal( size )
- string ReadString( length )
Properties
- buffer
Is the current Buffer object.
- systemIntSize
Is the size (in Byte) of a system int.
- systemBigEndian
Is <true> if the system endian is BigEndian else is <false>.
- source - top - main -
Sign in to add a comment
