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: Lua 5.2 awesomeness

Previous Thread :: Next Thread 
ColorfulBody is not online. ColorfulBody
Joined: 17 Jun 2012
Total Posts: 2353
16 Apr 2013 05:39 PM
While reading the Lua 5.2 reference manual, I just found out the following in the section about incompatibilities with the previous version:

"Equality between function values has changed. Now, a function definition may not create a new value; it may reuse some previous value if there is no observable difference to the new function."

Excited after reading this, I have done some tests. The Lua demo uses Lua 5.2, but Codepad still uses Lua 5.1, so I ran the following code on both:

a = function() end
b = function() end

c = {}

for i = 1, 5 do
table.insert(c, function() end)
end

for z, g in next, c do
print(z, g)
end

print "---"
print(a, b)

On the demo, I obtained the following:

1 function: 0x1cfc950
2 function: 0x1cfc950
3 function: 0x1cfc950
4 function: 0x1cfc950
5 function: 0x1cfc950
---
function: 0x1cf7780 function: 0x1cf7200

On codepad, I obtained the following:

1 function: 0x806f468
2 function: 0x806f480
3 function: 0x806f4b8
4 function: 0x806f8e0
5 function: 0x806f8f8
---
function: 0x806f580 function: 0x806f598


As you can notice, in the output of the demo, the memory address of all the functions created in the loop are the same, although this is not the case for the functions created outside of it. This is not the case, however, in Codepad.

What this means, concretely, is that function closures inside of loops or other constructs that may be ran repetitively will not be created over and over again, but will instead only be created once. This means that we no longer need to define, for example, functions that will be used in events that are connected in loops outside of these loops in fear of creating a lot of identical functions, which can slow down the code. Instead, Lua figures it all out for us and will only create one actual function.

For code that runs a lot of time and creates function closures, this is a huge optimization. It can also make code more clear, which is a great thing.

_________________________________________________________________________
I possess 4 ROBUX and 174 tickets.
Report Abuse
Guarranteed is not online. Guarranteed
Joined: 06 Dec 2010
Total Posts: 2799
16 Apr 2013 05:40 PM
Would never have noticed that.
Report Abuse
Prehistoricman is not online. Prehistoricman
Joined: 20 Sep 2008
Total Posts: 12490
16 Apr 2013 05:42 PM
This has to improve something.
Report Abuse
ArceusInator is not online. ArceusInator
Joined: 10 Oct 2009
Total Posts: 30553
16 Apr 2013 05:44 PM
That's nice. No one would ever notice, but it's certainly a nice thing to have if you're worried about memory usage.
Report Abuse
8SunTzu8 is not online. 8SunTzu8
Joined: 30 Sep 2011
Total Posts: 8199
16 Apr 2013 07:25 PM
Probably won't make a large difference for most projects, though.

Philosopher, Creator, Clanner, Wiki Writer, and Student
Report Abuse
xSIXx is not online. xSIXx
Joined: 06 Aug 2010
Total Posts: 9202
16 Apr 2013 07:44 PM
>waits for someone to mention goto
Report Abuse
HaxHelper is not online. HaxHelper
Joined: 19 Dec 2009
Total Posts: 1208
16 Apr 2013 07:45 PM
ogm guise goto is teh best thing in el-yew-aye fiev-point-too
Report Abuse
stravant is not online. stravant
Forum Moderator
Joined: 22 Oct 2007
Total Posts: 2893
16 Apr 2013 08:06 PM
Or more interesting:

for i = 1, 4 do
print(function() return i end)
end
local a
for i = 1, 4 do
print(function() return a end)
end

It means that one of the above loops is cheaper than the other.
Report Abuse
Tenal is not online. Tenal
Joined: 15 May 2011
Total Posts: 18684
16 Apr 2013 08:43 PM
lol but 5.2 has le goto's and I DONT EVEN KNOW what that means but i hear it is bad so it is bad
xDDDDDDDDDDDDDDDDDDDDDDDD!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! LOL
Report Abuse
18cwatford is not online. 18cwatford
Joined: 08 Oct 2009
Total Posts: 5410
16 Apr 2013 08:44 PM
I now imagine Tenal saying "#yoloswag"

_________________________________________________________________________
I possess 17K+ ROBUX and 601 tickets.
Report Abuse
Guarranteed is not online. Guarranteed
Joined: 06 Dec 2010
Total Posts: 2799
16 Apr 2013 08:44 PM
And Tenal ruined this intelligent thread.
Report Abuse
Tenal is not online. Tenal
Joined: 15 May 2011
Total Posts: 18684
16 Apr 2013 08:45 PM
#yoloswag
Report Abuse
Tenal is not online. Tenal
Joined: 15 May 2011
Total Posts: 18684
16 Apr 2013 08:46 PM
@guarranteed
Um, no. You're just a moron. Never have I found anyone on this forum during the duration of three years that was as unintelligible as you.

Learn to spell your name correctly.
Report Abuse
18cwatford is not online. 18cwatford
Joined: 08 Oct 2009
Total Posts: 5410
16 Apr 2013 08:46 PM
Then "#Gentlemen" or "#GangnamStyle"

_________________________________________________________________________
I possess 17K+ ROBUX and 601 tickets.
Report Abuse
Tenal is not online. Tenal
Joined: 15 May 2011
Total Posts: 18684
16 Apr 2013 08:47 PM
Also, threads can't be intelligent because they are only composed of 1's and 0's. The content of a thread can be intelligent, but either way you haven't contributed to anything anymore than I have.

Now please get the hell out.
Report Abuse
Tenal is not online. Tenal
Joined: 15 May 2011
Total Posts: 18684
16 Apr 2013 08:48 PM
#오빤강남스타일!
Report Abuse
18cwatford is not online. 18cwatford
Joined: 08 Oct 2009
Total Posts: 5410
16 Apr 2013 08:49 PM
Then Tenal tells us the truth.

_________________________________________________________________________
I possess 17K+ ROBUX and 601 tickets.
Report Abuse
Tenal is not online. Tenal
Joined: 15 May 2011
Total Posts: 18684
16 Apr 2013 08:51 PM
The truth is that the majority of the Scripters forum ignorantly and blindly states how GOTO is inefficient when it's sometimes actually a really great tool for maintaining efficiency and time.
Report Abuse
HaxHelper is not online. HaxHelper
Joined: 19 Dec 2009
Total Posts: 1208
16 Apr 2013 08:53 PM
go back to your corner, tenal

Report Abuse
miz656 is not online. miz656
Joined: 19 Jul 2010
Total Posts: 15336
16 Apr 2013 09:05 PM
Now I can't imagine Roblox implementing 5.2
Report Abuse
Guarranteed is not online. Guarranteed
Joined: 06 Dec 2010
Total Posts: 2799
16 Apr 2013 09:19 PM
@Tenal Very unfortunate that the only argument you can come up with is about my name. I'm very sorry that I like this name and the actual word "guaranteed" was taken in 2007. Plus I never intended on this account to be my main but boom, it is now.

Report Abuse
ColorfulBody is not online. ColorfulBody
Joined: 17 Jun 2012
Total Posts: 2353
16 Apr 2013 09:51 PM
@Stravant

It seems to me that both should be as cheap. The only difference is that one returns a local variable and the other one returns a local variable one level higher. Would that make a difference?

_________________________________________________________________________
I possess 4 ROBUX and 174 tickets.
Report Abuse
Tenal is not online. Tenal
Joined: 15 May 2011
Total Posts: 18684
16 Apr 2013 09:52 PM
Did I tell you to have gotten the username with the right spelling? Either way having an -ed verb as a username is quite stupid so even if you were to have a username with the right spelling, it'd still be quite stupid.
Report Abuse
Guarranteed is not online. Guarranteed
Joined: 06 Dec 2010
Total Posts: 2799
16 Apr 2013 09:53 PM
@Tenal I'm still quite confused on why this matters... On the internet. It's a name, deal with it.
Report Abuse
Quenty is not online. Quenty
Joined: 03 Sep 2009
Total Posts: 9316
16 Apr 2013 10:08 PM
Yeah, I realized Lua 5.1 was defining a new function instead of reusing it every time I made a new function a few days ago. I also realize that that means every class I make has a whole lot of memory being taken away. :/

I guess I better switch to Metatables (Which, apparently, crash ROBLOX when I send them over _G)
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