-
Notifications
You must be signed in to change notification settings - Fork 46
Open
Description
I can't find any information about getting the current environment of the lua being run. I set my environment when lua loads, but I can't get it when a function is executed. Is this possible?
LuaState state = LuaState.Create();
// I create a specific environment so that different blocks of lua code can run independently.
LuaTable environment = new(0, 1);
enviroment["myfunc"] = new LuaFunction("myfunc", MyFunction);
// And now I will set the environment.
LuaClosure closure = state.Load("myfunc()", "anonymous", enviroment);
_ = await state.ExecuteAsync(closure);private static ValueTask<int> MyFunction(LuaFunctionExecutionContext context, CancellationToken cancellationToken = default)
{
LuaTable environment = /* I need to get the current environment. */
// Some code here...
return new(context.Return());
}I don't understand the concept of environments at all. Standard functions are loaded through the global environment and are linked to LuaState, but during execution, I can specify my own environment, which won't contain any references to the global one.
To run code in isolation, do I need to create unique LuaStates?
Metadata
Metadata
Assignees
Labels
No labels