mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-07-10 06:04:37 +00:00
tscript change
Adds the ability to declare defaults for function arguments
eg
function testFunc(%x = 1, %y = 1)
{
return %x + %y;
}
can now be called as
testFunc(10) and it will return the value of 11.
This commit is contained in:
parent
7e64493dbf
commit
b0f8a5f9bd
8 changed files with 1375 additions and 1206 deletions
|
|
@ -138,6 +138,7 @@ struct Token
|
|||
%type <slot> slot_acc
|
||||
%type <intslot> intslot_acc
|
||||
%type <stmt> expression_stmt
|
||||
%type <var> param
|
||||
%type <var> var_list
|
||||
%type <var> var_list_decl
|
||||
%type <asn> assign_op_struct
|
||||
|
|
@ -242,12 +243,31 @@ var_list_decl
|
|||
;
|
||||
|
||||
var_list
|
||||
: VAR
|
||||
{ $$ = VarNode::alloc( $1.lineNumber, $1.value, NULL ); }
|
||||
| var_list ',' VAR
|
||||
{ $$ = $1; ((StmtNode*)($1))->append((StmtNode*)VarNode::alloc( $3.lineNumber, $3.value, NULL ) ); }
|
||||
: param
|
||||
{ $$ = $1; }
|
||||
| var_list ',' param
|
||||
{ $$ = $1; ((StmtNode*)($1))->append((StmtNode*)$3 ); }
|
||||
;
|
||||
|
||||
param
|
||||
: VAR
|
||||
{
|
||||
$$ = VarNode::allocParam($1.lineNumber, $1.value, NULL);
|
||||
}
|
||||
| VAR '?'
|
||||
{
|
||||
$$ = VarNode::allocParam($1.lineNumber, $1.value, NULL);
|
||||
}
|
||||
| VAR '=' expr
|
||||
{
|
||||
$$ = VarNode::allocParam($1.lineNumber, $1.value, $3);
|
||||
}
|
||||
| VAR '?' '=' expr
|
||||
{
|
||||
$$ = VarNode::allocParam($1.lineNumber, $1.value, $4);
|
||||
}
|
||||
;
|
||||
|
||||
datablock_decl
|
||||
: rwDATABLOCK class_name_expr '(' expr parent_block ')' '{' slot_assign_list_opt '}' ';'
|
||||
{ $$ = ObjectDeclNode::alloc( $1.lineNumber, $2, $4, NULL, $5.value, $8, NULL, true, false, false); }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue