Class Environment
public class Environment extends Object
This class encapsulates a Lua environment. A Lua environment consists of global and local variables which are all accessible through this utility.
- Author:
- theKayani
-
Field Summary
Fields Modifier and Type Field Description LuaInterpreter
interp
The interpreter this environment is currently running under. -
Method Summary
Modifier and Type Method Description LuaObject
getVar(LuaObject key)
Retrieve the value of the variable under the specified key.LuaObject
getVar(String name)
Retrieve the value of the variable under the specified name.boolean
isLocal(String name)
This checks whether the variable exists in the local space.void
setLocal(String name, LuaObject value)
This method explicitly sets the local variable with the given name to the given value.void
setVar(LuaObject key, LuaObject value)
This method sets a value to a variable.void
setVar(String name, LuaObject value)
This method sets a value to a variable.
-
Field Details
-
interp
The interpreter this environment is currently running under.
-
-
Method Details
-
setVar
This method sets a value to a variable. If the variable is local, this will reassign the local variable. If the variable is global or doesn't exist yet, this will assign the global variable.
- Parameters:
name
- name of the variablevalue
- value of the variable
-
setVar
This method sets a value to a variable. If the variable is local, this will reassign the local variable. If the variable is global or doesn't exist yet, this will assign the global variable.
- Parameters:
key
- the key of the variablevalue
- value of the variable
-
setLocal
This method explicitly sets the local variable with the given name to the given value. If the local variable already exists, it will reassign the local variable. If the local variable doesn't exist, it will assign the value to the local variable.
If there is a global variable with this name, it is left untouched. This method does not affect the global space.
- Parameters:
name
- name of the variable to assignvalue
- value of the variable to assign
-
getVar
Retrieve the value of the variable under the specified name. If this variable exists in the local space, this method will return the local value. Otherwise it will return the global value if one exists. If one does not exist in the global space, this will return
nil
.- Parameters:
name
- name of the variable to retrieve- Returns:
- value of the variable specified
-
getVar
Retrieve the value of the variable under the specified key. If this variable exists in the local space, this method will return the local value. Otherwise it will return the global value if one exists. If one does not exist in the global space, this will return
nil
.- Parameters:
key
- the key of the variable to retrieve- Returns:
- value of the variable specified
-
isLocal
This checks whether the variable exists in the local space.
- Parameters:
name
- name of the variable to check- Returns:
- whether the specific variable exists in the local space
-