Package com.hk.lua

Class Environment

java.lang.Object
com.hk.lua.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 Details

    • interp

      public final LuaInterpreter interp
      The interpreter this environment is currently running under.
  • Method Details

    • setVar

      public void setVar​(String name, LuaObject value)

      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 variable
      value - value of the variable
    • setVar

      public void setVar​(LuaObject key, LuaObject value)

      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 variable
      value - value of the variable
    • setLocal

      public void setLocal​(String name, LuaObject value)

      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 assign
      value - value of the variable to assign
    • getVar

      public LuaObject getVar​(String name)

      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

      public LuaObject getVar​(LuaObject key)

      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

      public boolean isLocal​(String name)

      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