Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8412117
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T00:35:46+00:00 2026-06-10T00:35:46+00:00

What is the big deal with Lua switching from setfenv() to _ENV ? In

  • 0

What is the big deal with Lua switching from setfenv() to _ENV?

In various “What’s New” sources, this move is mentioned as one of the most important changes between Lua versions 5.1 and 5.2.

However, the examples given in PIL and elsewhere can be trimmed to the following:

-- Lua 5.1                   -- Lua 5.2
function myfunc()            function myfunc()
    setfenv(1, {})               _ENV = {}
end                          end

So far, what we gained here is we have saved five key strokes. (I believe the situation is not much different from the C side.) Moreover, if I got it right, setfenv() can be used both from the outside and from the inside of a function, whereas _ENV can be accessed only from the inside of a function. (Of course, when using the C API, one can access the upvalues directly.) From what I wrote, the 5.2 approach seems much less flexible.

In his The Novelties of Lua 5.2, Roberto writes:

“Being a syntactic sugar, it is much simpler than the old environments”

Where’s the simplicity? What have I overlooked?

I believe this topic is worth better treatment that it is given in the 5.2 User Manual.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T00:35:48+00:00Added an answer on June 10, 2026 at 12:35 am

    Where’s the simplicity?

    It depends on how you define “simplicity”.

    In Lua 5.1, the environment was a magical, mystical setting that was unlike any other setting in the system. It didn’t have an explicit place and it could only be set by using standard library features.

    In Lua 5.2, the environment is a variable, just like any other. It has a name which you can use. So it’s simpler in that it’s more obvious what’s going on.

    Furthermore, in Lua 5.1, the environment of a function can be changed dynamically.

    In Lua 5.2, outside of direct upvalue manipulation, once a function has an environment, that is the environment it will have in perpetuity. The environment for a function is inherited, being lexically scoped like a regular local variable. So if you look at your code, you can easily see what environment a function is in. If there is no local _ENV in the scope of that function’s creation, then the environment shall be the environment of the chunk (which is defined by the load call).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is not a big deal, but is there any way in F# to
Not sure if this is a big deal. But wondering why when the site
This isn't that big of a deal but I was wondering if it can
What is the big deal with HTTP.SYS in IIS 7? From what I understand,
I'm trying to move to Python 2.7 and since Unicode is a Big Deal
Everyone makes a big deal about getting an address from GPS coordinates (reverse geocoding),
Perhaps not such a big deal, but it breaks my heart to follow this:
This isn't a big deal of a question but it bothers me, so I
I'm creating a new Map and pushing strings into it (no big deal) -but
I have a big makefile that I have configured with several phony targets. One

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.