minilua::Environment class

The environment/configuration for the Interpreter.

This contains things like global and local variables (including functions), etc. But local variables can not be manually created.

The default constructor initializes an empty environment with the standard C++ I/O streams (std::cin, std::cout and std::cerr).

Supports equality operators.

Constructors, destructors, conversion operators

Environment()
Create an empty environment with the default C++ I/O streams in the GLOBAL_ALLOCATOR.
Environment(MemoryAllocator* allocator)
Create an empty environment with the default C++ I/O streams in the given allocator.
Environment(const Environment&)
Copy constructor.
Environment(Environment&&)
Move constructor.

Public functions

auto operator=(const Environment&) -> Environment & -> auto
Copy assignment operator.
auto operator=(Environment&&) -> Environment & -> auto
Move assignment operator.
auto allocator() const -> MemoryAllocator * -> auto
Returns the used memory allocator.
auto make_table() const -> Table -> auto
Create a new table in the allocator of this environment.
void add(const std::string& name, Value value)
Add a variable to the environment.
void add(std::string&& name, Value value)
Add a variable to the environment.
auto add_table(const std::string& name) -> Table -> auto
Add a table as a variable with the given name and return the table.
void add_all(std::unordered_map<std::string, Value> values)
Add multiple variables to the environment.
void add_all(std::initializer_list<std::pair<std::string, Value>> values)
Add multiple variables to the environment.
void add_all(std::vector<std::pair<std::string, Value>> values)
Add multiple variables to the environment.
auto get(const std::string& name) -> Value -> auto
Get the value of a variable.
auto has(const std::string& name) -> bool -> auto
Check if a variable is set.
void set_stdin(std::istream*)
Sets the stdin stream to use in lua code.
void set_stdout(std::ostream*)
Sets the stdout stream to use in lua code.
void set_stderr(std::ostream*)
Sets the stderr stream to use in lua code.
auto get_stdin() -> std::istream * -> auto
Get the configured stdin stream.
auto get_stdout() -> std::ostream * -> auto
Get the configured stdout stream.
auto get_stderr() -> std::ostream * -> auto
Get the configured stderr stream.
auto size() const -> size_t -> auto
Returns the number of variables.
void set_file(std::optional<std::shared_ptr<std::string>> file)
Sets the current file name/path.
auto get_file() const -> std::optional< std::shared_ptr< std::string >> -> auto
Returns the current file name/path.

Friends

void swap(Environment&, Environment&)
Swap function.

Function documentation

auto minilua::Environment::get(const std::string& name) -> Value

Get the value of a variable.

Returns Nil if the variable does not exist.

void minilua::Environment::set_file(std::optional<std::shared_ptr<std::string>> file)

Sets the current file name/path.

This is used when generating ranges.