|
it might or might not be exactly what you're looking for but yourOn 20 May 2014 01:31, Marc Lepage <mlepage@antimeta.com> wrote:
> Hi, looking for some thoughts on loading DSL style data.
>
> I have it working but would like to swap out the environment when doing so,
> so it doesn't trample on the global environment.
>
> I have something like:
>
> function load(name)
> local env = getfenv(0)
> setfenv(0, dsl)
> local data = ""> > setfenv(0, env)
> end
>
> Where I get the thread's environment, set the dsl table (with all the DSL
> functions) as the environment, load the data (using require), then restore
> the environment (presumably the _G table). Of course I should really pcall
> the load instead of require, and return the data, but that's the idea.
>
> This is using Lua 5.1.5. I understand that Lua 5.2 changes the way
> environments are handled?
>
> If anyone could offer tips here or even better, point to a page which
> explains a lot of this in this context, that would be super great.
problem reminded me of this:
https://github.com/keplerproject/luarocks/blob/master/src/luarocks/persist.lua#L19-L58
Hope that helps!
-- Hisham