📝 rename function
to command
This commit is contained in:
parent
5cb7408ee7
commit
ec6ca08d18
@ -158,24 +158,24 @@ pxl|pixel|canv|canvas draw
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
## FUNCTIONS ##
|
## OWN COMMANDS ##
|
||||||
# - functions have their own scopes
|
# - command definitions have their own scopes
|
||||||
# - they can call other functions
|
# - they can call other commands
|
||||||
# - their own vars are private
|
# - their own vars are private
|
||||||
# - they can't acces root-scope's vars (except they were made global using `glob`)
|
# - they can't acces root-scope's vars (except they were made global using `glob`)
|
||||||
# - args are copied into local scope
|
# - args are copied into local scope
|
||||||
# - args with &-prefix modify corresponding var in global scope
|
# - args with &-prefix modify corresponding var in global scope
|
||||||
|
|
||||||
# the function scope "myfunction1" starts here
|
# the command scope "mycommand1" starts here
|
||||||
# argument $1 is readonly; $2 is read/write; $3 and $4 are optional and will default to `null`
|
# argument $1 is readonly; $2 is read/write; $3 and $4 are optional and will default to `null`
|
||||||
def myfunction1 $1 &$2 ($3 $4)
|
def mycommand1 $1 &$2 ($3 $4)
|
||||||
|
|
||||||
# current function scope ends here
|
# current command scope ends here
|
||||||
end
|
end
|
||||||
|
|
||||||
# call a function called "myfunction1"
|
# call a command called "mycommand1"
|
||||||
# arg $1 = 42; arg $2 = $test (returned to parent scope)
|
# arg $1 = 42; arg $2 = $test (returned to parent scope)
|
||||||
myfunction1 42 $test
|
mycommand1 42 $test
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -183,7 +183,7 @@ myfunction1 42 $test
|
|||||||
# halt the program
|
# halt the program
|
||||||
halt
|
halt
|
||||||
|
|
||||||
# return from function to parent scope
|
# return from command to parent scope
|
||||||
# halt program in root scope
|
# halt program in root scope
|
||||||
exit|return|end
|
exit|return|end
|
||||||
|
|
||||||
|
@ -55,7 +55,7 @@ class Juicescript_parser {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
||||||
// FUNCTION DEFINITION //
|
// OWN COMMAND DEFINITION //
|
||||||
case Juicescript.token_type.DEF:
|
case Juicescript.token_type.DEF:
|
||||||
this.parse_def();
|
this.parse_def();
|
||||||
break;
|
break;
|
||||||
@ -82,7 +82,7 @@ class Juicescript_parser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
PARSER: Handle function definition
|
PARSER: Handle own command definition
|
||||||
*/
|
*/
|
||||||
parse_def(){
|
parse_def(){
|
||||||
let parameter_list = [];
|
let parameter_list = [];
|
||||||
@ -128,7 +128,7 @@ class Juicescript_parser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
PARSER: Handle function definition
|
PARSER: Handle `end` command
|
||||||
*/
|
*/
|
||||||
parse_end(){
|
parse_end(){
|
||||||
/**/this.debug("enter scope root");
|
/**/this.debug("enter scope root");
|
||||||
|
Reference in New Issue
Block a user