Variable and Command by name.
Namespaces exist in a hierarchy. Variables and Commands added to this
namespace usually shadow those from parent namespaces, and are usually
visible to child namespaces.
A Namespace is passed in from the script executor to
Command.createStackFrame(org.praxislive.script.Namespace, java.util.List).
-
Method Summary
Modifier and TypeMethodDescriptionvoidaddCommand(String id, Command cmd) Add a Command with the given ID to this Namespace.voidaddVariable(String id, Variable var) Add a Variable with the given ID to this Namespace.Create a child Namespace of this Namespace.default VariablecreateConstant(String id, Value value) Create a constant in this namespace with the initial value given.default VariablecreateVariable(String id, Value value) Create a variable in this namespace with the initial value given.getCommand(String id) Get the Command with the given ID, ornullif it doesn't exist in this or a parent namespace.default VariablegetOrCreateVariable(String id, Value defaultValue) Get the variable with the given ID from this namespace or a parent namespace, creating and initializing a variable with the provided default value if none exists.getVariable(String id) Get the Variable with the given ID, ornullif it doesn't exist in this or a parent namespace.
-
Method Details
-
getVariable
Get the Variable with the given ID, ornullif it doesn't exist in this or a parent namespace.- Parameters:
id- variable ID- Returns:
- named variable, or null if none exists
-
addVariable
Add a Variable with the given ID to this Namespace.- Parameters:
id- variable IDvar- variable to add- Throws:
IllegalArgumentException- if a variable with that ID already exists in this namespace
-
getCommand
Get the Command with the given ID, ornullif it doesn't exist in this or a parent namespace.- Parameters:
id- command ID- Returns:
- named command, or null if none exists
-
addCommand
Add a Command with the given ID to this Namespace.- Parameters:
id- command IDcmd- command to add- Throws:
IllegalArgumentException- if a command with that ID already exists in this namespace
-
createChild
Namespace createChild()Create a child Namespace of this Namespace.- Returns:
- child namespace
-
createVariable
Create a variable in this namespace with the initial value given.The default implementation of this method creates a new instance of a variable implementation, and calls
addVariable(java.lang.String, org.praxislive.script.Variable)to register it.- Parameters:
id- variable IDvalue- initial value- Returns:
- created variable
- Throws:
IllegalArgumentException- if a variable with that name already exists in this namespace
-
getOrCreateVariable
Get the variable with the given ID from this namespace or a parent namespace, creating and initializing a variable with the provided default value if none exists.The default implementation of this method calls
getVariable(java.lang.String)to find a registered variable, and if that method returns} delegates toinvalid @link
{@link nullcreateVariable(java.lang.String, org.praxislive.core.Value).- Parameters:
id- variable IDdefaultValue- default initial value- Returns:
- created variable
-
createConstant
Create a constant in this namespace with the initial value given. The constant is guaranteed to always returnvaluefromVariable.getValue(), and to always throwUnsupportedOperationExceptionon any call toVariable.setValue(org.praxislive.core.Value).The default implementation of this method creates a new instance of a constant variable implementation, and calls
addVariable(java.lang.String, org.praxislive.script.Variable)to register it.- Parameters:
id- constant namevalue- constant value- Returns:
- created constant
- Throws:
IllegalArgumentException- if a variable with that name already exists in this namespace
-