LuaFunction.setEnvironment

Set a new environment for this function.

The environment of a function is the table used for looking up non-local (global) variables.

struct LuaFunction
void
setEnvironment

Parameters

env LuaTable

new environment

Examples

lua["foo"] = "bar";
auto func = lua.loadString(`return foo`);
assert(func.call!string() == "bar");

auto env = lua.wrap(["foo": "test"]);
func.setEnvironment(env);
assert(func.call!string() == "test");

Meta