User:Merlin11188/Draft: Difference between revisions

From Legacy Roblox Wiki
Jump to navigationJump to search
>Merlin11188
No edit summary
>Merlin11188
Added a picture; added locations to the descriptions; reordered slightly
 
(49 intermediate revisions by the same user not shown)
Line 1: Line 1:
===Prerequisites===
{{User:Merlin11188/Templates/NoEdit}}
----
{{EmphasisBox|Weak Tables require knowledge of [[Scope]] and [[Metatables]].|red|dark=yes}}
First off, you must understand what ''references'' and ''objects'' are. Tables, functions, threads, and (full)
userdata values are ''objects'': variables do not actually contain these values, only ''references''
to them. Assignment, parameter passing, and function returns always manipulate references to such values;
these operations do not imply any kind of copy.<br/>
===Weak Tables===
Note: all Lua objects in the global environment are ignored and will never be garbage collected, even if they aren't used again.
----
Weak tables are the mechanism that you use to tell Lua that a reference should not prevent the reclamation
of an object by the garbage collector. A weak reference is a reference to an object that is not considered
by the garbage collector. If all references pointing to an object are weak, the object is collected and
somehow these weak references are deleted. Lua implements weak references as weak tables: A weak table is a
table where all references are weak. That means that, if a reference to an object is only held inside weak tables, Lua will
collect the object eventually. Tables have keys and values and both may contain any kind of object. Under normal circumstances, the garbage collector does not collect objects that appear as keys or as values of an accessible table. That is, both keys and values are strong references, as they prevent the reclamation of objects to which they refer. In a weak table, keys and values may be weak. That means that there are three kinds of weak tables: tables with weak keys, tables with weak values, and fully weak tables, where both keys and values are weak. Irrespective of the table kind, when a key or a value is collected the whole entry disappears from the table. <br/>The weakness of a table is controlled by the __mode field of its metatable. If the __mode  field is a string containing the character 'k', the keys in the table are weak. If __mode contains the character 'v' the values  in the table are weak.
===Examples===
----
{{Example|<pre>
a = {}
b = {}
setmetatable(a, b)
b.__mode = "k"        -- now `a' has weak keys
key = {}               -- creates first key
a[key] = 1
key = {}               -- creates second key
a[key] = 2
collectgarbage()      -- forces a garbage collection cycle
for k, v in pairs(a) do
    print(v)
end


Output:
2
</pre>}}
What happened there??? Well, the first key is created, then made into an index in table a. Then, the first key is ''overwritten'' by the second key, meaning the '''only reference''' to the first key is inside table a with a value of 1. Table a has weak keys, so when the garbage collection cycle is forced, it collects the first key because it's only reference is a weak key; however, the second key is still in the global environment, automatically preventing the reclamation of the second key by the garbage collector. So, since the the first key was removed from the table, the whole pair was removed from the table, leaving only the second key and it's corresponding value.


Here's another example, with the value as a reference:
{{Stub}}
{{Example|<pre>
{|
Table={}
|[[File:Home_Subpage.png|frame|A picture of the 'Home' tab on the submenu in 'My ROBLOX'.]] <br/>
setmetatable(Table, {__mode="v"}) -- Set the values as weak
|}
do -- Create a new scope
__TOC__
local ImAPony=newproxy(true) -- Create a new object in this scope, so the object can be garbage collected.
Table[1]=ImAPony
end
collectgarbage()
print(Table[1])


Output:
 
nil
===Character and Notifications===
</pre>}}
{|
Alright, so we create a table and give it weak values. Then we give it an object as a value (at index/key 1). Since the values with reference to an object are weak, the garbage collector goes ahead and collects the ImAPony userdata.<br/>
|On the far left of the page there is a picture of [[My_Character|your character]]. Underneath, there is a link to your system notifications.
Now, what would happen if the line setting Table's metatable was commented out? This would happen:
|[[File:Avatar_Notifications.png|frame|A picture of [[My_Character|your character]] with system notifications beneath it.]]
<pre>
|}
Output:
 
userdata: [hexadecimal numbers]
===Best Friends===
</pre>
{|
The value inside Table is a strong reference, so when the garbage collector made its cycle it didn't pick up the object ImAPony, leaving it at index 1.
|Underneath of your avatar and notification box is your [[Friends#Best_Friends|best friends]] list. Here you can see what your best friends are doing (from their [[My_Home#Status_Update|shout box]]) and whether or not they're online.
|[[File:Best_Friends.png|frame|This a list of your [[Friends#Best_Friends|best friends]] and their most recent shouts!]]
|}
 
===Status Update===
{|
|You can use this so that people who visit your profile can see what you're up to.
|[[File:Status Update.png|frame|This is the status update bar. People who have you as their [[Friends#Best_Friends|best friend]] will see it on their [[My_Home|home]]!]]
|}
 
===Feed===
{|
|Your feed is in the center of the page, just beneath your status update box. Your feed is a way to keep you updated with all of your groups. Every time someone uses the shout box in one of your [[groups]], you're updated here!
|[[File:Feed bar.png|frame|This is for your feed—all of your [[groups]]' shouts go here.]]
|}
 
===Recently Played Games===
{|
|On the far right is the 'Recently Played Games' box. Your most recently played games can be seen here. If you want a larger list, you can click the '''See More''' button.
|[[File:Recently_Played_Games.png|frame|This is a list of your most recently played [[game]]s.]]
|}
 
===Facebook Connect===
{|
|On the far right, underneath of the 'Recently Played Games' box is the Facebook connect box. If you have a Facebook account, you can link it to your ROBLOX account! See [[connecting your account to Facebook]] for more info.
|[[File:FacebookConnect_Unconnected.png|frame|Facebook connect. You can use this to link your Facebook account to your [[Roblox|ROBLOX]] account! Your personal info will '''not''' be shared with other users!]]
|}
 
<!--
{| class="wikitable" style="border-spacing: 0px; padding: 0px;"
|-
|[[File:Avatar + Notifications]]
|[[File:Status_Update.png]]
|[[File:Recently_Played_Games.png|287px]]
|-
|[[File:Best_Friends.png]]
|<div style="top:0px;">[[File:Feed_bar.png]]</div>
|[[File:FacebookConnect_Unconnected.png]]
|}-->

Latest revision as of 03:31, 12 March 2012

Do not edit!
The creator of this subpage does not want it to be edited without permission. Please discuss any changes that you think are relevant on the talk page.


Stub icon Stub
This article is a stub. If you think you know more about this than we do, please help us by contacting a writer.
Thank you!


A picture of the 'Home' tab on the submenu in 'My ROBLOX'.


Character and Notifications

On the far left of the page there is a picture of your character. Underneath, there is a link to your system notifications.
A picture of your character with system notifications beneath it.

Best Friends

Underneath of your avatar and notification box is your best friends list. Here you can see what your best friends are doing (from their shout box) and whether or not they're online.
This a list of your best friends and their most recent shouts!

Status Update

You can use this so that people who visit your profile can see what you're up to.
This is the status update bar. People who have you as their best friend will see it on their home!

Feed

Your feed is in the center of the page, just beneath your status update box. Your feed is a way to keep you updated with all of your groups. Every time someone uses the shout box in one of your groups, you're updated here!
This is for your feed—all of your groups' shouts go here.

Recently Played Games

On the far right is the 'Recently Played Games' box. Your most recently played games can be seen here. If you want a larger list, you can click the See More button.
This is a list of your most recently played games.

Facebook Connect

On the far right, underneath of the 'Recently Played Games' box is the Facebook connect box. If you have a Facebook account, you can link it to your ROBLOX account! See connecting your account to Facebook for more info.
Facebook connect. You can use this to link your Facebook account to your ROBLOX account! Your personal info will not be shared with other users!