Propeller Manual

Table Of Contents
PUB – Spin Language Reference
PUB
Designator: Declare a Public Method Block.
((PUB PRI))
PUB Name (Param ,Param) :RValue | LocalVar [Count ]〉〉 ,LocalVar [Count ]〉〉
SourceCodeStatements
Name is the desired name for the public method.
Param is a parameter name (optional). Methods can contain zero or more comma-
delimited parameters, enclosed in parentheses. Param must be globally unique, but
other methods may also use the same symbol name. Each parameter is essentially a
long variable and can be treated as such.
RValue is a name for the return value of the method (optional). This becomes an alias
to the method’s built-in
RESULT variable. RValue must be globally unique, but other
methods may also use the same symbol name. The RValue (and/or
RESULT variable)
is initialized to zero (0) upon each call to the method.
LocalVar is a name for a local variable (optional). LocalVar must be globally unique,
but other methods may also use the same symbol name. All local variables are of
size long (four bytes) and are left uninitialized upon each call to the method.
Methods can contain zero or more comma-delimited local variables.
Count is an optional expression, enclosed in brackets, that indicates this is a local
array variable, with Count number of elements; each being a long in size. When later
referencing these elements, they begin with element 0 and end with element Count-1.
SourceCodeStatements is one or more lines of executable source code, indented by at
least one space, that perform the function of the method.
Explanation
PUB is the Public Method Block declaration. A Public Method is a section of source code that
performs a specific function then returns a result value. This is one of six special declarations
(
CON, VAR, OBJ, PUB, PRI, and DAT) that provide inherent structure to the Spin language.
Every object can contain a number of public (
PUB) and private (PRI) methods. Public methods
can be accessed outside of the object itself and serve to make up the interface to the object.
The
PUB and PRI declarations don’t return a value themselves, but the public and private
methods they represent always return a value when called from elsewhere in the code.
Page 182 · Propeller Manual v1.1