minilua::Env class

Contents

Environment for use in the interpreter.

Public functions

auto make_table() const -> Table -> auto
auto global() -> Table & -> auto
auto local() -> LocalEnv & -> auto
void declare_local(const std::string&)
void set_local(const std::string&, Value)
auto get_local(const std::string&) -> std::optional< Value > -> auto
auto is_local(const std::string&) -> bool -> auto
void set_global(const std::string&, Value)
auto get_global(const std::string&) -> Value -> auto
void set_var(const std::string& name, Value value)
auto get_var(const std::string& name) -> Value -> auto
void set_varargs(std::optional<Vallist> vallist)
void set_stdin(std::istream*)
auto get_stdin() -> std::istream * -> auto
void set_file(std::optional<std::shared_ptr<std::string>> file)
auto get_file() const -> std::optional< std::shared_ptr< std::string >> -> auto

Function documentation

auto minilua::Env::make_table() const -> Table

Helper method to create a table in the same allocator as the environment.

auto minilua::Env::global() -> Table &

Returns the table for the global environment.

auto minilua::Env::local() -> LocalEnv &

Returns the table for the local environment.

NOTE: Use the helper methods to manipulate the local env.

void minilua::Env::declare_local(const std::string&)

Declares (or redeclares) a local variable.

void minilua::Env::set_local(const std::string&, Value)

Sets the value of a local variable and declares it, if it is not already declared.

auto minilua::Env::get_local(const std::string&) -> std::optional< Value >

Get a locally defined value, if it exists.

auto minilua::Env::is_local(const std::string&) -> bool

Check if a local variable with the name name is declared.

void minilua::Env::set_global(const std::string&, Value)

Sets the value of a global variable.

auto minilua::Env::get_global(const std::string&) -> Value

Gets the value of a local variable or Nil if it was not defined.

void minilua::Env::set_var(const std::string& name, Value value)

Set a variable named name to value.

If name is declared as a local variable the value of that variable will be changed. Otherwise the value of the global variable named name will be changed/set.

auto minilua::Env::get_var(const std::string& name) -> Value

Get the value of a variable name or Nil if it is not set.

void minilua::Env::set_varargs(std::optional<Vallist> vallist)

Setter and getter for the varargs of the immediately enclosing varargs function.

void minilua::Env::set_stdin(std::istream*)

Sets stdin/out/err stream to use in lua code.

NOTE: The default are c++'s cin, cout and cerr.

auto minilua::Env::get_stdin() -> std::istream *

Get the configured stdin/out/err stream.

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

Sets the current file name/path.

auto minilua::Env::get_file() const -> std::optional< std::shared_ptr< std::string >>

Returns the current file name/path.