NetLinx Programming Overview
20
NetLinx Programming Language Reference Guide
The NetLinx compiler passes all variables by reference. This means that the variable the subroutine
operates on is the same variable the caller passed. Any change made to the variable, passed as a calling
parameter, updates the variable's value from the caller's perspective. You can take advantage of this pass
by reference feature by returning an updated value through a calling parameter rather than as the return
value.
Constants, on the other hand, are passed by value. When this happens, a copy of the parameter is
delivered to the subroutine. Any change made to the variable representing the constant is lost once the
function or subroutine is lost.
To specify an array as a function or subroutine parameter, one set of brackets for each array dimension
must follow the variable name, as shown in the following example:
DEFINE_CALL 'READ INPUT' (CHAR BUFFER[][])
{
(* body of the subroutine *)
}
The parameter
BUFFER
is declared to be a two-dimensional array by including two sets of brackets after
the name. For compatibility with existing programs, the array dimensions may be specified inside the
brackets. These dimensions, however, are not required and are ignored by the compiler. The NetLinx
Interpreter will do bounds checking on the array and generate a run-time error if the array bounds are
exceeded.
DEFINE_FUNCTION
DEFINE_FUNCTION
provides a way to return a value to a statement. It has the same functionality as a
DEFINE_CALL
. The
DEFINE_FUNCTION
is used inline in a statement, where a
DEFINE_CALL
must be
used as a standalone statement. The basic structure is:
DEFINE_FUNCTION [<return type>]<name>[(<param1>,<param2>, … <parameN>)]
{
(* statements *)
}
The following
DEFINE_FUNCTION
creates a subroutine to cube a number and returns a
LONG
integer
value:
DEFINE_FUNCTION LONG CUBEIT (LONG VALUE)
{
STACK_VAR RESULT
RESULT = VALUE * VALUE * VALUE
RETURN RESULT
}
DEFINE_PROGRAM
PUSH[TP1, 1]
{
CUBED_VAL = CUBEIT ( 3 )
(* CUBED_VAL = 27 *)
}
Summary of Contents for NETLINX PROGRAMMING LANGUAGE
Page 15: ...Table of Contents xiii NetLinx Programming Language Reference Guide...
Page 16: ...xiv NetLinx Programming Language Reference Guide Table of Contents...
Page 18: ...Introduction 2 NetLinx Programming Language Reference Guide...
Page 76: ...Language Elements 60 NetLinx Programming Language Reference Guide...
Page 106: ...Combining Devices Levels and Channels 90 NetLinx Programming Language Reference Guide...
Page 112: ...Master To Master M2M 96 NetLinx Programming Language Reference Guide...
Page 182: ...Reserved Identifiers 166 NetLinx Programming Language Reference Guide...
Page 204: ...NetLinx UniCode Functions 188 NetLinx Programming Language Reference Guide...
Page 244: ...Appendix B Glossary 228 NetLinx Programming Language Reference Guide...
Page 245: ...Appendix B Glossary 229 NetLinx Programming Language Reference Guide...