A Roblox Community
Would you like to react to this message? Create an account in a few clicks or log in to continue.

A Roblox Community

A community of Robloxians who want to learn to script and build on Roblox Studio.
 
HomeLatest imagesRegisterLog 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
Metatables Tutorial Vote_lcapMetatables Tutorial Voting_barMetatables Tutorial Vote_rcap 
naknak
Metatables Tutorial Vote_lcapMetatables Tutorial Voting_barMetatables Tutorial Vote_rcap 
Supernapalm
Metatables Tutorial Vote_lcapMetatables Tutorial Voting_barMetatables Tutorial Vote_rcap 
m27frogy
Metatables Tutorial Vote_lcapMetatables Tutorial Voting_barMetatables Tutorial Vote_rcap 
slayer9365
Metatables Tutorial Vote_lcapMetatables Tutorial Voting_barMetatables Tutorial Vote_rcap 
myrco919
Metatables Tutorial Vote_lcapMetatables Tutorial Voting_barMetatables Tutorial Vote_rcap 
branefreez
Metatables Tutorial Vote_lcapMetatables Tutorial Voting_barMetatables Tutorial Vote_rcap 
ninga95
Metatables Tutorial Vote_lcapMetatables Tutorial Voting_barMetatables Tutorial Vote_rcap 
CloneTrooper787
Metatables Tutorial Vote_lcapMetatables Tutorial Voting_barMetatables Tutorial Vote_rcap 
raboy117
Metatables Tutorial Vote_lcapMetatables Tutorial Voting_barMetatables Tutorial Vote_rcap 
Top posting users this month
No user
Latest topics
» Where to go from here.
Metatables Tutorial EmptySeptember 14th 2020, 1:20 pm by MrNicNac

» Send me an Email
Metatables Tutorial EmptySeptember 14th 2020, 1:16 pm by MrNicNac

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

» New Site Possibly
Metatables Tutorial EmptyJuly 6th 2015, 4:16 pm by m27frogy

» Ambassador!
Metatables Tutorial EmptyApril 15th 2015, 11:40 pm by naknak

» Boop - Tag
Metatables Tutorial EmptyApril 13th 2015, 9:46 pm by naknak

» Vip Class Script
Metatables Tutorial EmptyApril 13th 2015, 4:54 pm by naknak

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

» Genesis Point
Metatables Tutorial EmptyJuly 17th 2014, 7:04 pm by branefreez

» Reward System
Metatables Tutorial EmptyJuly 17th 2014, 5:41 am by m27frogy

» Script Request
Metatables Tutorial EmptyJuly 10th 2014, 11:43 am by naknak

» local scripts?
Metatables Tutorial EmptyJuly 10th 2014, 11:39 am by naknak

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

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

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

» FlashLight Script
Metatables Tutorial EmptyJanuary 1st 2014, 2:11 pm by m27frogy

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

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

» Improve Coding
Metatables Tutorial EmptyOctober 26th 2013, 1:12 pm by pook03

» Simple Button
Metatables Tutorial EmptySeptember 1st 2013, 6:19 pm by branefreez


 

 Metatables Tutorial

Go down 
4 posters
AuthorMessage
Guest
Guest
avatar



Metatables Tutorial Empty
PostSubject: Metatables Tutorial   Metatables Tutorial EmptyAugust 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
naknak


Posts : 878
Join date : 2010-07-30

Metatables Tutorial Empty
PostSubject: Re: Metatables Tutorial   Metatables Tutorial EmptyAugust 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
avatar



Metatables Tutorial Empty
PostSubject: Re: Metatables Tutorial   Metatables Tutorial EmptyAugust 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
avatar


Posts : 58
Join date : 2010-07-28

Metatables Tutorial Empty
PostSubject: Re: Metatables Tutorial   Metatables Tutorial EmptyAugust 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.forumclan.com
Guest
Guest
avatar



Metatables Tutorial Empty
PostSubject: Re: Metatables Tutorial   Metatables Tutorial EmptyAugust 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
avatar



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

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


Posts : 878
Join date : 2010-07-30

Metatables Tutorial Empty
PostSubject: Re: Metatables Tutorial   Metatables Tutorial EmptyJanuary 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
avatar



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

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


Posts : 878
Join date : 2010-07-30

Metatables Tutorial Empty
PostSubject: Re: Metatables Tutorial   Metatables Tutorial EmptyJanuary 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
blueymaddog


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

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

:P I understand wiki better than this.
Back to top Go down
naknak
Administrator
Administrator
naknak


Posts : 878
Join date : 2010-07-30

Metatables Tutorial Empty
PostSubject: Re: Metatables Tutorial   Metatables Tutorial EmptyJanuary 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
avatar



Metatables Tutorial Empty
PostSubject: Re: Metatables Tutorial   Metatables Tutorial EmptyJanuary 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
naknak


Posts : 878
Join date : 2010-07-30

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

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



Metatables Tutorial Empty
PostSubject: Re: Metatables Tutorial   Metatables Tutorial EmptyJanuary 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
naknak


Posts : 878
Join date : 2010-07-30

Metatables Tutorial Empty
PostSubject: Re: Metatables Tutorial   Metatables Tutorial EmptyJanuary 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
blueymaddog


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

Metatables Tutorial Empty
PostSubject: Re: Metatables Tutorial   Metatables Tutorial EmptyJanuary 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
naknak


Posts : 878
Join date : 2010-07-30

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

Cool
Back to top Go down
Supernapalm
Expert Scripter
Expert Scripter
avatar


Posts : 393
Join date : 2011-01-17

Metatables Tutorial Empty
PostSubject: Re: Metatables Tutorial   Metatables Tutorial EmptyJanuary 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
blueymaddog


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

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

lack of detail
Back to top Go down
Sponsored content





Metatables Tutorial Empty
PostSubject: Re: Metatables Tutorial   Metatables Tutorial Empty

Back to top Go down
 
Metatables Tutorial
Back to top 
Page 1 of 1
 Similar topics
-
» My first tutorial ~ Metatables
» Metatables Tutorial
» I understand metatables, but..
» Tutorial on: 'for' loops
» Instance.new() tutorial

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