Top posting users this month | |
Latest topics | » Where to go from here.September 14th 2020, 1:20 pm by MrNicNac» Send me an EmailSeptember 14th 2020, 1:16 pm by MrNicNac» [v1.6.0.0] Lua Script Obfuscator [No Bytecode]July 6th 2015, 7:38 pm by m27frogy» New Site PossiblyJuly 6th 2015, 4:16 pm by m27frogy» Ambassador!April 15th 2015, 11:40 pm by naknak» Boop - TagApril 13th 2015, 9:46 pm by naknak» Vip Class ScriptApril 13th 2015, 4:54 pm by naknak» Who's active?!April 13th 2015, 4:52 pm by naknak» Genesis PointJuly 17th 2014, 7:04 pm by branefreez» Reward SystemJuly 17th 2014, 5:41 am by m27frogy» Script RequestJuly 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 hereApril 26th 2014, 4:01 pm by altshiftkey» What's your favorite sport?January 1st 2014, 2:13 pm by m27frogy» FlashLight ScriptJanuary 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 CodingOctober 26th 2013, 1:12 pm by pook03» Simple ButtonSeptember 1st 2013, 6:19 pm by branefreez |
|
| Metatables Tutorial | |
| | Author | Message |
---|
Guest Guest
| Subject: 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. |
| | | naknak Administrator
Posts : 878 Join date : 2010-07-30
| Subject: Re: Metatables Tutorial August 3rd 2010, 10:14 pm | |
| I think it would be better if you were clearer on what everything did | |
| | | Guest Guest
| Subject: 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. |
| | | Prodigy Administrator
Posts : 58 Join date : 2010-07-28
| Subject: 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... | |
| | | Guest Guest
| Subject: 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 |
| | | Guest Guest
| Subject: Re: Metatables Tutorial January 16th 2011, 10:54 pm | |
| this makes sense... but what is userdata? |
| | | naknak Administrator
Posts : 878 Join date : 2010-07-30
| Subject: 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. | |
| | | Guest Guest
| Subject: Re: Metatables Tutorial January 16th 2011, 11:27 pm | |
| Uhhhhhhh... Can you re-clarify? |
| | | naknak Administrator
Posts : 878 Join date : 2010-07-30
| Subject: 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. | |
| | | blueymaddog Administrator
Posts : 1081 Join date : 2010-12-09 Age : 26
| Subject: Re: Metatables Tutorial January 17th 2011, 9:08 am | |
| :P I understand wiki better than this. | |
| | | naknak Administrator
Posts : 878 Join date : 2010-07-30
| Subject: 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. | |
| | | Guest Guest
| Subject: 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? |
| | | naknak Administrator
Posts : 878 Join date : 2010-07-30
| Subject: Re: Metatables Tutorial January 17th 2011, 4:18 pm | |
| It just means everything in roblox is a userdata. | |
| | | Guest Guest
| Subject: Re: Metatables Tutorial January 17th 2011, 4:42 pm | |
| which is? oh come on get to the point. what is userdata? |
| | | naknak Administrator
Posts : 878 Join date : 2010-07-30
| Subject: 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. | |
| | | blueymaddog Administrator
Posts : 1081 Join date : 2010-12-09 Age : 26
| Subject: Re: Metatables Tutorial January 18th 2011, 6:12 am | |
| but wiki had more info than this. lol, i'm working on my own wiki! | |
| | | naknak Administrator
Posts : 878 Join date : 2010-07-30
| Subject: Re: Metatables Tutorial January 18th 2011, 6:48 pm | |
| | |
| | | Supernapalm Expert Scripter
Posts : 393 Join date : 2011-01-17
| Subject: 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. | |
| | | blueymaddog Administrator
Posts : 1081 Join date : 2010-12-09 Age : 26
| Subject: Re: Metatables Tutorial January 19th 2011, 6:47 am | |
| | |
| | | Sponsored content
| Subject: Re: Metatables Tutorial | |
| |
| | | | Metatables Tutorial | |
|
Similar topics | |
|
| Permissions in this forum: | You cannot reply to topics in this forum
| |
| |
| Who is online? | In total there is 1 user online :: 0 Registered, 0 Hidden and 1 Guest
None
Most users ever online was 136 on October 21st 2024, 12:16 pm
|
| Please tell us what time zone you are in here
Got a really good idea? Post it in projects and it might show up here! |
|