generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: Where are all of the global functions stored?

Previous Thread :: Next Thread 
1waffle1 is not online. 1waffle1
Joined: 16 Oct 2007
Total Posts: 16381
08 Sep 2013 08:07 PM
getfenv(0) is completely empty. If I change the function environment then all of the global functions are unrecognized, and I don't know how to include all of the global functions in the new environment because I don't know where they are.
Report Abuse
Oysi is not online. Oysi
Joined: 06 Jul 2009
Total Posts: 9058
08 Sep 2013 08:14 PM
[ Content Deleted ]
Report Abuse
blocco is not online. blocco
Joined: 14 Aug 2008
Total Posts: 29474
08 Sep 2013 08:25 PM
`getfenv(0)` is empty to those who don't look past what can be seen normally.
Report Abuse
Oysi is not online. Oysi
Joined: 06 Jul 2009
Total Posts: 9058
08 Sep 2013 08:27 PM
[ Content Deleted ]
Report Abuse
blocco is not online. blocco
Joined: 14 Aug 2008
Total Posts: 29474
08 Sep 2013 08:27 PM
^

Couldn't have said it better myself.
Report Abuse
dekkonot is not online. dekkonot
Joined: 22 Dec 2010
Total Posts: 6685
08 Sep 2013 08:28 PM
^But Roblox is an engine, not a game.

~ Linguam latinam est optimum ~
Report Abuse
oxcool1 is not online. oxcool1
Joined: 05 Nov 2009
Total Posts: 15444
08 Sep 2013 08:28 PM
global functions are storted in getmetatable(getfenv(0)).__index
but getfenv(0) metatable is locked, derfore u cant access it.
Report Abuse
1waffle1 is not online. 1waffle1
Joined: 16 Oct 2007
Total Posts: 16381
08 Sep 2013 08:37 PM
I cheated.

    do
        local g=setmetatable({},{__index=function(t,k)return rawget(t,k)or loadstring('return '..k)()end})
        setfenv(1,setmetatable({print=print},{
                __newindex=function(t,k,v)
                    print('set '..k..' to '..tostring(v))
                    g[k]=v
                end,
                __index=function(t,k)
                    print('get '..k)
                    return g[k]
                end
            }
        ))
    end
    -----------------------------------
Report Abuse
digpoe is not online. digpoe
Joined: 02 Nov 2008
Total Posts: 9092
09 Sep 2013 01:41 PM
Try _G

Lua stores the environment in` _G`, so `_G.print` should equal `print`
Report Abuse
1waffle1 is not online. 1waffle1
Joined: 16 Oct 2007
Total Posts: 16381
09 Sep 2013 02:34 PM
You try _G. It's empty. All it has is gloo GUI Library. Shared is empty. getfenv(0) is empty. oxcool already explained where all of the globals are.
Report Abuse
1waffle1 is not online. 1waffle1
Joined: 16 Oct 2007
Total Posts: 16381
09 Sep 2013 04:06 PM
I made my method considerably shorter:

    setfenv(1,setmetatable({},{
        __newindex=function(t,k,v)
            print('set '..k..' to '..tostring(v))
            rawset(t,k,v)
        end,
        __index=function(t,k)
            print('get '..k)
            return rawget(t,k)or loadstring('return '..k)()
        end
    }))
Report Abuse
1waffle1 is not online. 1waffle1
Joined: 16 Oct 2007
Total Posts: 16381
09 Sep 2013 04:41 PM
It seems like jobro put way too much code into making 2+2=5. this is all I had to do to make that happen:

setfenv(1,setmetatable({print=print},{
__newindex=function(t,k,v)
rawset(t,k,type(v)=='number'and setmetatable({v},{
__add=function(a,b)
return a[1]+b[1]+1
end
})or v)
end
}))

a=2
b=2
print(a+b)
Report Abuse
1waffle1 is not online. 1waffle1
Joined: 16 Oct 2007
Total Posts: 16381
09 Sep 2013 04:55 PM
actually my new method doesn't work quite perfectly

but with my amendment applied to it it does:

setfenv(1,setmetatable({},{
__newindex=function(t,k,v)
print('set '..k..' to '..tostring(v))
getfenv()[k]=v
end,
__index=function(t,k)
print('get '..k)
return getfenv()[k]or loadstring('return '..k)()
end
}));
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image