Lua 5.2 (was: modules, require, magic)

classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

Lua 5.2 (was: modules, require, magic)

Stefan Reich
Hmm. I'd like to say a general thing about Lua 5.2.

On Mon, Oct 17, 2011 at 1:22 AM, Petite Abeille
<[hidden email]> wrote:

> No. _ENV is the latest iteration of many attempt to get ride of setfenv/getfenv in 5.2.

I must say that, so far, I cannot really see the value in some of the
proposed changes of 5.2.

So Lua 5.2 breaks the most fundamental function I need for making
sandboxes (setfenv). There's new code to replace it, but people do not
seem 100% sure if it really does the same thing as setfenv. (Or do
they?)

Overall, the way I see it now, I think I'll prefer to stick to 5.1.
It's a widely accepted standard, and all the programs, libraries,
extensions out there are built for it.

Agreeing on a stable standard library (like stdlib) and shipping it
with Lua, IMO, would be a nice addition to 5.1. But other than that:
Just leave it be. Keep the standard. Everything is good.

(OK, I read through the list of changes in 5.2 again and some
improvements do sound nice and non-problematic, like __len, __pairs
and so on. Fair enough! Still I'm not a 5.2 convertee as of now.)

> And 5.2 is a work of fiction as it hasn't been released.

Is there any kind of date yet for when they might plan to release it?
What's the development process here? I'm very curious. Roberto...?

-Stefan

Reply | Threaded
Open this post in threaded view
|

Re: Lua 5.2 (was: modules, require, magic)

Patrick Donnelly
On Wed, Oct 19, 2011 at 12:51 PM, Stefan Reich
<[hidden email]> wrote:

> Hmm. I'd like to say a general thing about Lua 5.2.
>
> On Mon, Oct 17, 2011 at 1:22 AM, Petite Abeille
> <[hidden email]> wrote:
>
>> No. _ENV is the latest iteration of many attempt to get ride of setfenv/getfenv in 5.2.
>
> I must say that, so far, I cannot really see the value in some of the
> proposed changes of 5.2.
>
> So Lua 5.2 breaks the most fundamental function I need for making
> sandboxes (setfenv). There's new code to replace it, but people do not
> seem 100% sure if it really does the same thing as setfenv. (Or do
> they?)

loadin will be what you want.

For those of us who've made complicated sandboxes where setfenv and
the debug library can still exist, you will appreciate the
introduction of _ENV. setfenv was and is a huge PITA to sandbox.

The _ENV griping is a real joke to be honest. Everything you used to
do you can still do. Moving the environment to an upvalue makes sense
and is quite elegant. People are just mad their silly designs that
relied on heavy use of setfenv are "broken". They will grow up or use
debug.setupvalue.

>> And 5.2 is a work of fiction as it hasn't been released.
>
> Is there any kind of date yet for when they might plan to release it?
> What's the development process here? I'm very curious. Roberto...?

"When it's done".

--
- Patrick Donnelly

Reply | Threaded
Open this post in threaded view
|

Re: Lua 5.2 (was: modules, require, magic)

Petite Abeille

On Oct 19, 2011, at 8:48 PM, Patrick Donnelly wrote:

> The _ENV griping is a real joke to be honest. Everything you used to
> do you can still do.

Right.  Requires a bit of a rethink, but yes, _ENV is a workable substitute for setfenv() .

> Moving the environment to an upvalue makes sense
> and is quite elegant. People are just mad their silly designs that
> relied on heavy use of setfenv are "broken".

Well, the use of setfenv is not necessarily silly. It's just that the mechanism would have to change in 5.2.

> They will grow up

Again, using setfenv is not, hmmm, infantile... it's a mechanism that serves a purpose... same as _ENV...

> or use debug.setupvalue.

debug.upvaluejoin, no?

http://dev.alt.textdrive.com/browser/HTTP/debugx.lua#L66




Reply | Threaded
Open this post in threaded view
|

Re: Lua 5.2 (was: modules, require, magic)

Patrick Donnelly
On Wed, Oct 19, 2011 at 3:02 PM, Petite Abeille
<[hidden email]> wrote:
>> They will grow up
>
> Again, using setfenv is not, hmmm, infantile... it's a mechanism that serves a purpose... same as _ENV...

I don't know how you got that I was referring to setfenv when I said
"they". All I'm saying is the childish whining being done on the
mailing list will cease eventually. Everyone here is becoming
aggravated by it.

>> or use debug.setupvalue.
>
> debug.upvaluejoin, no?

Nope.

--
- Patrick Donnelly

Reply | Threaded
Open this post in threaded view
|

Re: Lua 5.2 (was: modules, require, magic)

Petite Abeille

On Oct 19, 2011, at 9:19 PM, Patrick Donnelly wrote:

> All I'm saying is the childish whining being done on the
> mailing list will cease eventually. Everyone here is becoming
> aggravated by it.

Toughen up. Killfiles are girls' best friend, or so I heard.


Reply | Threaded
Open this post in threaded view
|

Re: Lua 5.2 (was: modules, require, magic)

Ben Kelly
In reply to this post by Patrick Donnelly
On Wed, 19 Oct 2011 14:48:17 -0400
Patrick Donnelly <[hidden email]> wrote:
>
> For those of us who've made complicated sandboxes where setfenv and
> the debug library can still exist, you will appreciate the
> introduction of _ENV. setfenv was and is a huge PITA to sandbox.
>
On the other hand, if you don't have access to the source of the thing
you're trying to sandbox, it may be the only way you have available.

Personally, what I'll miss most is DSL creation. The ability to swap
around the caller's environment silently makes it easy to create
"keyword-like" functions that hugely simplify the structure of
configuration and game-behaviour files. Having to tack _ENV in front of
each of those is not only very ugly, it confuses the modders.

Yeah, I can use debug.setupvalue(), but now I'm using the debug library
in release code, which last I checked was considered extremely
inappropriate under any circumstances.

        Ben Kelly

Reply | Threaded
Open this post in threaded view
|

Re: Lua 5.2 (was: modules, require, magic)

Josh Simmons
On Thu, Oct 20, 2011 at 2:03 PM, Ben Kelly <[hidden email]> wrote:

> On Wed, 19 Oct 2011 14:48:17 -0400
> Patrick Donnelly <[hidden email]> wrote:
>>
>> For those of us who've made complicated sandboxes where setfenv and
>> the debug library can still exist, you will appreciate the
>> introduction of _ENV. setfenv was and is a huge PITA to sandbox.
>>
> On the other hand, if you don't have access to the source of the thing
> you're trying to sandbox, it may be the only way you have available.
>
> Personally, what I'll miss most is DSL creation. The ability to swap
> around the caller's environment silently makes it easy to create
> "keyword-like" functions that hugely simplify the structure of
> configuration and game-behaviour files. Having to tack _ENV in front of
> each of those is not only very ugly, it confuses the modders.
>
> Yeah, I can use debug.setupvalue(), but now I'm using the debug library
> in release code, which last I checked was considered extremely
> inappropriate under any circumstances.
>
>        Ben Kelly
>
>

Urgh you don't have to use _ENV to do this.

http://www.lua.org/work/doc/manual.html#pdf-load

Reply | Threaded
Open this post in threaded view
|

Re: Lua 5.2 (was: modules, require, magic)

Josh Simmons
On Thu, Oct 20, 2011 at 2:08 PM, Josh Simmons <[hidden email]> wrote:

> On Thu, Oct 20, 2011 at 2:03 PM, Ben Kelly <[hidden email]> wrote:
>> On Wed, 19 Oct 2011 14:48:17 -0400
>> Patrick Donnelly <[hidden email]> wrote:
>>>
>>> For those of us who've made complicated sandboxes where setfenv and
>>> the debug library can still exist, you will appreciate the
>>> introduction of _ENV. setfenv was and is a huge PITA to sandbox.
>>>
>> On the other hand, if you don't have access to the source of the thing
>> you're trying to sandbox, it may be the only way you have available.
>>
>> Personally, what I'll miss most is DSL creation. The ability to swap
>> around the caller's environment silently makes it easy to create
>> "keyword-like" functions that hugely simplify the structure of
>> configuration and game-behaviour files. Having to tack _ENV in front of
>> each of those is not only very ugly, it confuses the modders.
>>
>> Yeah, I can use debug.setupvalue(), but now I'm using the debug library
>> in release code, which last I checked was considered extremely
>> inappropriate under any circumstances.
>>
>>        Ben Kelly
>>
>>
>
> Urgh you don't have to use _ENV to do this.
>
> http://www.lua.org/work/doc/manual.html#pdf-load
>

Oh you mean changing the environment all through the script. I really
don't understand why people think this is a good idea or that it makes
things more readable.

Reply | Threaded
Open this post in threaded view
|

Re: Lua 5.2 (was: modules, require, magic)

Tony Finch
In reply to this post by Ben Kelly
Ben Kelly <[hidden email]> wrote:

>
> Personally, what I'll miss most is DSL creation. The ability to swap
> around the caller's environment silently makes it easy to create
> "keyword-like" functions that hugely simplify the structure of
> configuration and game-behaviour files. Having to tack _ENV in front of
> each of those is not only very ugly, it confuses the modders.
>
> Yeah, I can use debug.setupvalue(), but now I'm using the debug library
> in release code, which last I checked was considered extremely
> inappropriate under any circumstances.

The way to do this is to wrap the script like this

        script, script_setenv = load(
                [[ return function (...) ]]
                .. source ..
                [[ end, function (env) _ENV = env end ]]
                )()

Then your special keyword-like functions can call the relevant
script_setenv function instead of setfenv. You can fake up a replacement
setfenv like this

        script_env_setter[script] = script_setenv

        function setscriptenv(script,env)
                script_env_setters[script](env)
        end

Tony.
--
f.anthony.n.finch  <[hidden email]>  http://dotat.at/
Shannon: Southwest 5 to 7, increasing gale 8 at times. Mainly rough.
Occasional rain. Moderate or good, occasionally poor.

Reply | Threaded
Open this post in threaded view
|

Re: Lua 5.2 (was: modules, require, magic)

Petite Abeille
In reply to this post by Ben Kelly

On Oct 20, 2011, at 5:03 AM, Ben Kelly wrote:

> Yeah, I can use debug.setupvalue(), but now I'm using the debug library
> in release code, which last I checked was considered extremely
> inappropriate under any circumstances.

Contrast:

The Debug Library - circa 5.1

This library provides the functionality of the debug interface to Lua programs. You should exert care when using this library. The functions provided here should be used exclusively for debugging and similar tasks, such as profiling. Please resist the temptation to use them as a usual programming tool: they can be very slow. Moreover, several of these functions violate some assumptions about Lua code (e.g., that variables local to a function cannot be accessed from outside or that userdata metatables cannot be changed by Lua code) and therefore can compromise otherwise secure code.

http://www.lua.org/manual/5.1/manual.html#5.9


The Debug Library - circa 5.2

This library provides the functionality of the debug interface to Lua programs. You should exert care when using this library. Several of these functions violate basic assumptions about Lua code (e.g., that variables local to a function cannot be accessed from outside; that userdata metatables cannot be changed by Lua code; that Lua programs do not crash) and therefore can compromise otherwise secure code. Moreover, some functions in this library may be slow.

http://www.lua.org/work/doc/manual.html#6.10

Feel free to go wild! But only in 5.2 :P