A Roblox Community

A community of Robloxians who want to learn to script and build on Roblox Studio.
 
HomeFAQRegisterLog in
If you're a experienced coder make some tutorials! It would really help the site grow.
Make sure you read the rules(Which can be found by clicking here)
If you're a beginner at coding, try some tutorials.
We have many Moderators/Admins watching this site. Contact them with Questions.
Let us know what your favorite sport is. By clicking here to vote (Click here)
This site is becoming inactive. Lets make it active.
Log in
Username:
Password:
Log in automatically: 
:: I forgot my password
Top posters
blueymaddog
 
naknak
 
Supernapalm
 
m27frogy
 
slayer9365
 
myrco919
 
branefreez
 
ninga95
 
CloneTrooper787
 
raboy117
 
Top posting users this month
Latest topics
» Send me an Email
January 8th 2016, 10:14 am by naknak

» [v1.6.0.0] Lua Script Obfuscator [No Bytecode]
July 6th 2015, 7:38 pm by m27frogy

» New Site Possibly
July 6th 2015, 4:16 pm by m27frogy

» Ambassador!
April 15th 2015, 11:40 pm by naknak

» Boop - Tag
April 13th 2015, 9:46 pm by naknak

» Vip Class Script
April 13th 2015, 4:54 pm by naknak

» Who's active?!
April 13th 2015, 4:52 pm by naknak

» Where to go from here.
April 13th 2015, 4:51 pm by naknak

» Genesis Point
July 17th 2014, 7:04 pm by branefreez

» Reward System
July 17th 2014, 5:41 am by m27frogy

» Script Request
July 10th 2014, 11:43 am by naknak

» local scripts?
July 10th 2014, 11:39 am by naknak

» Project: Reconstruction [Died]
July 10th 2014, 11:36 am by naknak

» Hi. I am new here
April 26th 2014, 4:01 pm by altshiftkey

» What's your favorite sport?
January 1st 2014, 2:13 pm by m27frogy

» FlashLight Script
January 1st 2014, 2:11 pm by m27frogy

» Gun Making! [READ DESC]
January 1st 2014, 2:10 pm by m27frogy

» Hi, I am new here!
November 26th 2013, 3:33 pm by Keanu73

» Improve Coding
October 26th 2013, 1:12 pm by pook03

» Simple Button
September 1st 2013, 6:19 pm by branefreez


Share | 
 

 Metatables Tutorial

View previous topic View next topic Go down 
AuthorMessage
Guest
Guest



PostSubject: Metatables Tutorial   August 3rd 2010, 6:23 pm

Okay, a metatable is a table in a table, in simple terms. You can create one in two ways:

Code:
setmetatable({}, {})

or

Code:
Table = {["Tab"] = {}}

Those both make metatables. You cam also use the function newproxy() to create a Userdata with a metatable, but that is almost never needed. Though, it would look like this:

Code:
local USERDATA_VAR = newproxy(true)
--false makes no metatable, just an empty userdata
--Now edit it like any other metatable.

Now, time to edit the metatable. These metatables have functions called metamethods. These functions are the things run when you access a metatable. These are the most common metamethods:

Code:
__index = nil
__newindex = nil
--When you access a metatable ('unlocked'), it looks for this thing called an __index. It will run this function attached, this also holds the objects of the metatable. If this is nil, or there is a __newindex object, and this isn't the first time the metatable is accessed, it will run the __newindex method. When that is nil, it returns nil and runs nothing.

__call = nil
--This is run when the metatable is called. It is much less common, but still used a lot. A fun example is when you use it with getmetatable("").__call

__eq = nil
--The == operation

__lt = nil
--The < operation

__metatable = nil
--Can lock the metatable. If this isn't nil, it is run when the metatable is accessed or called.

__mode = nil
--String: Mode. It will return any weakpoints in the metatable values. Not used commonly.

These are majorly used (or most used) metameathods that I CAN THINK OF! I may be missing some, these are off the top of my head. Also, mind my spelling, I typed this quickly at like 4:00 this morning before I left for the day.

Anyways, using a metatable:
One major use is OOP, which stands for Object-oriented programming. This means that you program using mainly objects you already have. Java is a major OOP language for example. Another example is to add protection to your programs. You can remove harmful code using a metatable. A former person named Meelo (Meeloq on Twitter), also found metatables useful for a Big-number calculator (long story). Though, the point is that metatables are useful at the correct times. If you are advanced enough to create a functional metatable. You should be able to run it.

tl;dr: Metatables are useful at the right times. If you can make an error-free syntax-correct one, you can run it also.
Back to top Go down
naknak
Administrator
Administrator
avatar

Posts : 878
Join date : 2010-07-30

PostSubject: Re: Metatables Tutorial   August 3rd 2010, 10:14 pm

I think it would be better if you were clearer on what everything did
Back to top Go down
Guest
Guest



PostSubject: Re: Metatables Tutorial   August 5th 2010, 5:24 pm

I don't see what's so hard about this i use it all the time its easy to under stand I don't think its really expert work.
Back to top Go down
Prodigy
Administrator
Administrator


Posts : 58
Join date : 2010-07-28

PostSubject: Re: Metatables Tutorial   August 5th 2010, 5:59 pm

naknak wrote:
I think it would be better if you were clearer on what everything did
Expert tutorials don't really need to be too clear. They're made for the experts...
Back to top Go down
http://roblox.youneed.us
Guest
Guest



PostSubject: Re: Metatables Tutorial   August 5th 2010, 7:47 pm

flump, it may not be an expert tutorial, but it isn't advanced either. It is between the two, and I just used the same concept medical staffs use, I bumped it up instead of knocking it down =P
Back to top Go down
Guest
Guest



PostSubject: Re: Metatables Tutorial   January 16th 2011, 10:54 pm

this makes sense... but what is userdata?
Back to top Go down
naknak
Administrator
Administrator
avatar

Posts : 878
Join date : 2010-07-30

PostSubject: Re: Metatables Tutorial   January 16th 2011, 10:58 pm

A userdata is the type Lua uses for data structures in the underlying C program. There aren't native Lua functions for handling those types, they must be handled via Metatables. All Roblox objects and events are userdata Lua type.
Back to top Go down
Guest
Guest



PostSubject: Re: Metatables Tutorial   January 16th 2011, 11:27 pm

Uhhhhhhh... Can you re-clarify?
Back to top Go down
naknak
Administrator
Administrator
avatar

Posts : 878
Join date : 2010-07-30

PostSubject: Re: Metatables Tutorial   January 16th 2011, 11:54 pm

What everything in roblox is. You are indirectly using them all the time if you script.
Back to top Go down
blueymaddog
Administrator
Administrator
avatar

Posts : 1081
Join date : 2010-12-09
Age : 18

PostSubject: Re: Metatables Tutorial   January 17th 2011, 9:08 am

:P I understand wiki better than this.

_________________
blueymaddog
Administrator • Moderator • Expert Scripter
PM: blueymaddog
<+1 post. ujelly?>
Back to top Go down
naknak
Administrator
Administrator
avatar

Posts : 878
Join date : 2010-07-30

PostSubject: Re: Metatables Tutorial   January 17th 2011, 12:57 pm

Time to steal from wiki :P

Btw, the wiki is why we made this site. They never update. We on the other hand update everyday.
Back to top Go down
Guest
Guest



PostSubject: Re: Metatables Tutorial   January 17th 2011, 4:00 pm

Quote :
A userdata is the type Lua uses for data structures in the underlying C program. There aren't native Lua functions for handling those types, they must be handled via Metatables. All Roblox objects and events are userdata Lua type.

what does this mean?
Back to top Go down
naknak
Administrator
Administrator
avatar

Posts : 878
Join date : 2010-07-30

PostSubject: Re: Metatables Tutorial   January 17th 2011, 4:18 pm

It just means everything in roblox is a userdata.
Back to top Go down
Guest
Guest



PostSubject: Re: Metatables Tutorial   January 17th 2011, 4:42 pm

which is? oh come on get to the point. what is userdata?
Back to top Go down
naknak
Administrator
Administrator
avatar

Posts : 878
Join date : 2010-07-30

PostSubject: Re: Metatables Tutorial   January 17th 2011, 5:12 pm

Its the name of a type or class. It isn't really anything, I guess you can call it a set memory.
Back to top Go down
blueymaddog
Administrator
Administrator
avatar

Posts : 1081
Join date : 2010-12-09
Age : 18

PostSubject: Re: Metatables Tutorial   January 18th 2011, 6:12 am

but wiki had more info than this. lol, i'm working on my own wiki!
Back to top Go down
naknak
Administrator
Administrator
avatar

Posts : 878
Join date : 2010-07-30

PostSubject: Re: Metatables Tutorial   January 18th 2011, 6:48 pm

Cool
Back to top Go down
Supernapalm
Expert Scripter
Expert Scripter


Posts : 393
Join date : 2011-01-17

PostSubject: Re: Metatables Tutorial   January 19th 2011, 12:20 am

i kinda get these things, but this tutorial doesn't explain stuff completely. somethings missing. and im going to find out what.
Back to top Go down
http://hackthissite.org
blueymaddog
Administrator
Administrator
avatar

Posts : 1081
Join date : 2010-12-09
Age : 18

PostSubject: Re: Metatables Tutorial   January 19th 2011, 6:47 am

lack of detail

_________________
blueymaddog
Administrator • Moderator • Expert Scripter
PM: blueymaddog
<+1 post. ujelly?>
Back to top Go down
Sponsored content




PostSubject: Re: Metatables Tutorial   

Back to top Go down
 
Metatables Tutorial
View previous topic View next topic Back to top 
Page 1 of 1
 Similar topics
-
» Great Tank and Weathering tutorial
» Power Sword Tutorial (with more to follow)
» Instant Mold Tutorial
» good c++ tutorial series
» After Effects Tutorial - Organic Cell Edges

Permissions in this forum:You cannot reply to topics in this forum
A Roblox Community :: Tutorials and Resources :: Expert-
Jump to: