miz656
|
  |
| Joined: 19 Jul 2010 |
| Total Posts: 15336 |
|
|
| 27 Dec 2011 12:12 AM |
| I know what type is, but why would you use it? |
|
|
| Report Abuse |
|
|
Legend26
|
  |
| Joined: 08 Sep 2008 |
| Total Posts: 10586 |
|
|
| 27 Dec 2011 12:16 AM |
There are a lot of uses. Since Lua is not statically typed, any variable can ave any type. To help prevent undefined behavior, a person can use type to error a function if the type is not correct.
It's essentially used when someone creates an API for others to use. Instead of forcing the users to look in the source code for the error, getting the type and then erroring if it's wrong makes it much easier to catch errors. |
|
|
| Report Abuse |
|
|
|
| 27 Dec 2011 12:16 AM |
print(type("hi")) --> string print(type(4)) --> number print(type({})) --> table print(type(coroutine.create(function() end))) --> thread print(type(function() end)) --> function print(type(newproxy())) --> userdata
Those are all strings, all lowercase letters. Rather simple to use. |
|
|
| Report Abuse |
|
|
miz656
|
  |
| Joined: 19 Jul 2010 |
| Total Posts: 15336 |
|
|
| 27 Dec 2011 12:19 AM |
@legend26
Oh ok, that helps!
And since you guys are here, what is the point of _VERSION? |
|
|
| Report Abuse |
|
|
Legend26
|
  |
| Joined: 08 Sep 2008 |
| Total Posts: 10586 |
|
|
| 27 Dec 2011 12:22 AM |
I'm guessing it's just a fast way for a programmer to know what version of Lua he's using. There's really no use unless you need to know what the version that is being used is.
Or perhaps the program has different versions in use that have different versions of Lua. If you make something that you want to work for both versions you might use it, although I really don't see that happening. |
|
|
| Report Abuse |
|
|
miz656
|
  |
| Joined: 19 Jul 2010 |
| Total Posts: 15336 |
|
| |
|