Class CustomEnvironment
Provides the capability of constructing a custom environment separated from the widget infrastructure.
Functions
CustomEnvironment.add (slotName, requirements, valueCreator) | Add a slot to all custom environments under certain conditions. |
CustomEnvironment:New (additionalSlots, additionalCreators) | Creates a new instance of CustomEnvironment |
CustomEnvironment:Create (parameters, additionalSlots) | Creates the environment with the specified parameters. |
Functions
- CustomEnvironment.add (slotName, requirements, valueCreator)
-
Add a slot to all custom environments under certain conditions.
The slot is added only to those custom environments, that have the specified parameters filled-in.
Remarks:
-
If the slots have any requirements, they do not get added to already created environments, only to future ones.
Parameters:
- slotName string The name of the slot to populate
- requirements
{[string]=Any} or {string}
A map (or array) with parameter keys that are required; or
nil
if the slot should be available everywhere - valueCreator func or Any The function that construct the value for given parameters or the value itself
Usage:
CustomEnvironment.add("MathEx", nil, MathEx) CustomEnvironment.add("error", { name = true }, function(p) return createCustomErrorHandler(p.name) end)
- CustomEnvironment:Create (parameters, additionalSlots)
-
Creates the environment with the specified parameters.
You can optionally also specify the values for additional slot, which is equivalent to setting them after you receive the result.
Parameters:
- parameters
- additionalSlots
Usage:
local customEnvironment = CustomEnvironment:New({ mode = 2 }) local environment = customEnvironment:Create({ name = "myEnvironment" }) setfenv(myFunction, environment) return myFunction()
- CustomEnvironment:New (additionalSlots, additionalCreators)
-
Creates a new instance of CustomEnvironment
Parameters:
- additionalSlots
{[string]=Any}
Additional values that should be available in the final environment; or
nil
- additionalCreators
{[string]=func}
Costructors of additional values that should be available in the final environment that utilize the parameters of CustomEnvironment:Create; or
nil
Returns:
- additionalSlots
{[string]=Any}
Additional values that should be available in the final environment; or