ARGS is currently empty or: -noinit. See the init command.
This implementation has been motivated by the desire for JS/DOM support in the BrowseX Web browser. Notwithstanding, there are no internal couplings with either BrowseX or Tkhtml. The dynamic approach used means there is virtually no overhead until DOM objects are actually accessed.
For the most part the design has been to passthru to NGS JS as much as possible, so see that documentation and source code for in depth details. One major difference is that I've extended NGS so that the compiler exists in only the first widget created. This is because the compiler is itself implemented as Byte-compiled Javascript and so would add overhead per-instance.
s | string a character string. i | integer a whole numerical quantity. f | float a floating point value b | boolean a boolean value a | array an array of values v | variable type is returned as first element in string: see below
Properties/Methods get defined with the NGS attributes Static and Mutable. However, you can change these. by appending a :X where is one of the following lettters:
Here is an example:
S | Set Static 1 (default) D | Set Static 0 I | Set Immutable 1 C | Set Immutable 0 (default)
.path class teach -props {prof:If dunc:bD}
which means prof is a immutable float, dunc is a non-static boolean.
For commands that take switch parameters, you may abbreviate to the shortest unique sequence, usually a single chars after the dash. ie. -l means the same as -lencmd.
NGS JS Equivalence: js_apply + ...
You may call the array command multiple times for a given array to modify/extend it's parameters. The lencmd returns the actual size and will be called when the length property is accessed. The array is sparse until elements are actually accessed, or until you invoke one of the builtin array methods for the array object.
-init {V V V ...} Set of values to initialize array with. -pairs {T V T V ...} Like above, but with Type/Value pairs. -datacmd CMD Serves the same purpose as -datacmd in class: See Note. -lencmd CMD Command to call that returns the array length. -namecmd CMD Command to call that translates string index to integer. -type TYPE Specify the type of elements for homogenous array. -size N Specify the size (for homogenous arrays).
Note: The tag argument is always A for arrays.
When an array is created with a -type of class,
all values after the -type argument will be passed to the class command.
If no -type is specified, then return from -datacmd is presumed to be
variable.
NGS JS Equivalence: js_type_make_array+ ...
You may call class multiple times to add additional methods or properties, or to change the CMDs. Attempts to redefine existing properties or methods are silently ignored. When the propcmd CMD is invoked, 5 arguments are appended: idx isset name val:
-props LIST define propertys in list -datacmd CMD call CMD when property accessed -meths LIST define methods in list -funccmd CMD call CMD when javascript method called
Returning the array type invokes the array command above, class invokes the class command, etc. In this fashion, we can dynamically build multileveled objects.
string a string value integer a numeric value float a floating point value boolean a boolean value new followed by a class name, and optionally a tag array an array, with arguments the same as after NAME in the array command. link plus the name of the property to link to undef undefined
.path class document -datacmd docs -props form table ul ol dl img a
#!/usr/bin/tclsh8.4
load ./jstcl.so
proc docs {v idx isset name val} {
puts "docs: $v $idx $isset $name $val"
switch $name {
images {
return {array -d {doci 36}}
}
}
}
# Instantiate an element in array
proc doci {v idx isset name val} {
puts "doci: $v $idx $isset $name $val"
if $isset return
return {new Image}
}
proc img {v idx isset name val} {
global imgvar
if !$isset [ return $imgvar($name)]
set imgvar($name) $val
}
jstcl .j -g
.j class document_class -d {docs 37} -p {forms:v images:v}
.j new document_class document
.j class Image -d {img 0} -p {src name width height border}
.j parse {
<!--
ij=new Image;
ij.src="abc";
document.images[0].src=ij.src;
print(document.images[0].src);
}
This instantiates a document object. When an assignment of the
form document.images occurs, doci is called , which
dynamically instantiates an Image object.
Note: class assigns a unique handle to each class of the form .jscN where N is a unique integer.
NGS JS Equivalence: js_class_create + ...
NGS JS Equivalence: js_class_destroy
NGS JS Equivalence: js_error_message
NGS JS Equivalence: js_eval_data
NGS JS Equivalence: js_eval_file
NGS JS Equivalence: js_eval_javascript_file
NGS JS Equivalence: js_execute_byte_code_file
NGS JS Equivalence: js_execute_byte_code
NGS JS Equivalence: js_define_method
Mandatory arguments to long options are mandatory for short options too.
-a, --annotate-assembler annotate generated assembler listing with
the original source code
-c, --compile compile JavaScript input file to byte-code
and save the result to the file `FILE.jsc'
-d, --dispatch=METHOD use method METHOD for byte-code instruction
dispatching one of: jumps, switch, or switch-basic.
-e, --eval=CODE evaluate JavaScript code CODE
-E, --events print interpreter events
-f, --file evaluate the next argument file and pass
all remaining arguments to the interpreter
through the ARGS array
-g, --debug[=INT] generate debugging information, zero for off
-h, --help print this help and exit
-l, --load evaluate argument files until option `-f',
`--file' is encountered
-N, --no-compiler do not define compiler to the JavaScript
interpreter
-O, --optimize[=LEVEL] optimize at level LEVEL
-r, --secure=OPTION turn on security option OPTION, one of:
file, nofile, system, nosystem,
-s, --stack-size=SIZE set the interpreter stack size to SIZE nodes
-S, --assembler compile JavaScript intput file to assembler
and save the result to the file `FILE.jas'
-t, --stacktrace print stacktrace on error
-v, --verbose tell what the interpreter is doing
-V, --version print version number
-W, --compiler-option=OPTION
set compilation option OPTION
-x, --executable generate executable byte-code files program
Report bugs to mtr@ngs.fi
Compiler options which may be prefixed with -no- to disable, include:
The latter, the vars-global option was added to support Web javascript which requires all var variables outside of functions to be global.
deprecated default off unused-argument default off unused-variable default on undefined default on shadow default on with-clobber default on missing-semicolon default off strict-ecma default off vars-global default on
NOTE: The -noinit option must be used at widget creation if the iohook command is to be used. Follow this by the init command.
NGS JS Equivalence: js_byte_compile+js_exec+js_vm_debug_position...
NGS JS Equivalence: js_byte_compile+js_exec+js_vm_debug_position...
NGS JS Equivalence: js_result.
The default type is s or string.
s string i integer f floating point value b boolean
NGS JS Equivalence: js_get_var and js_set_var.
NGS JS Equivalence: js_version.
Copyright 2001 peter@browsex.com