myrkos
|
  |
| Joined: 06 Sep 2010 |
| Total Posts: 8072 |
|
|
| 27 Jul 2012 10:16 AM |
x = {1,2,3} print(x[0])
>1
me gusta. and it was surprisingly easy, too. just edit 2 lines (one of which is to make unpack() still work) |
|
|
| Report Abuse |
|
|
Dr01d3k4
|
  |
| Joined: 11 Oct 2007 |
| Total Posts: 17916 |
|
|
| 27 Jul 2012 10:17 AM |
| :D now hack it into Roblox D: D: |
|
|
| Report Abuse |
|
|
agent767
|
  |
| Joined: 03 Nov 2008 |
| Total Posts: 4181 |
|
|
| 27 Jul 2012 11:43 AM |
| Meh I would still prefer tableindexes starting at 1... |
|
|
| Report Abuse |
|
|
stravant
|
  |
 |
| Joined: 22 Oct 2007 |
| Total Posts: 2893 |
|
|
| 27 Jul 2012 12:00 PM |
Quick, make it a compile-time switch!
Also, you might want to edit other utilities such as select() which also have indexing behavior. |
|
|
| Report Abuse |
|
|
|
| 27 Jul 2012 01:52 PM |
>people still complaining of Lua's array indexing
find another language and go away pls
|
|
|
| Report Abuse |
|
|
sncplay42
|
  |
| Joined: 27 Nov 2008 |
| Total Posts: 11891 |
|
|
| 27 Jul 2012 01:54 PM |
"you might want to edit other utilities such as select() which also have indexing behavior."
And the entire API |
|
|
| Report Abuse |
|
|
|
| 27 Jul 2012 02:57 PM |
| How does it affect ipairs and the # operator? |
|
|
| Report Abuse |
|
|
Quenty
|
  |
| Joined: 03 Sep 2009 |
| Total Posts: 9316 |
|
|
| 27 Jul 2012 03:16 PM |
If you do that to me, half my scripts break!
xD
But I do agree it's confusing when working with Java or C++, since Lua is my technically 'Home' programming language. |
|
|
| Report Abuse |
|
|
stravant
|
  |
 |
| Joined: 22 Oct 2007 |
| Total Posts: 2893 |
|
|
| 27 Jul 2012 03:17 PM |
| ipairs isn't in Lua 5.2, which is probably the distribution that he got. And the # operator will behave exactly the same. What indexing style you use does not change lengths, only indices. |
|
|
| Report Abuse |
|
|
myrkos
|
  |
| Joined: 06 Sep 2010 |
| Total Posts: 8072 |
|
|
| 27 Jul 2012 06:23 PM |
Hmm, the # operator seems to be having some trouble:
x = {1,2,3} print(#x)
> 2
It appears the sizearray of the table is 2, also, even though it has 3 elements. Gaah. I'll look further into it later.
But yes, this is in Lua 5.2. |
|
|
| Report Abuse |
|
|
|
| 27 Jul 2012 10:15 PM |
way to go, maestro.
What does `print(#{}, #{1})` output? |
|
|
| Report Abuse |
|
|
|
| 27 Jul 2012 10:18 PM |
| This would be excellent for things using the modulus operator. you could go from using (x-1)%y+1 to x%y c: |
|
|
| Report Abuse |
|
|
myrkos
|
  |
| Joined: 06 Sep 2010 |
| Total Posts: 8072 |
|
|
| 28 Jul 2012 01:56 AM |
@necrobumpist
print(#{},#{1})
> 0 0
|
|
|
| Report Abuse |
|
|
oxcool1
|
  |
| Joined: 05 Nov 2009 |
| Total Posts: 15444 |
|
| |
|
myrkos
|
  |
| Joined: 06 Sep 2010 |
| Total Posts: 8072 |
|
| |
|
oxcool1
|
  |
| Joined: 05 Nov 2009 |
| Total Posts: 15444 |
|
| |
|
nightname
|
  |
| Joined: 10 Jun 2008 |
| Total Posts: 8960 |
|
|
| 28 Jul 2012 10:51 AM |
| Am I the only one here who cannot find a legitimate reason for why this would be useful? |
|
|
| Report Abuse |
|
|
Solotaire
|
  |
| Joined: 30 Jul 2009 |
| Total Posts: 30356 |
|
|
| 28 Jul 2012 10:56 AM |
| I actually like indexes starting at one. |
|
|
| Report Abuse |
|
|
myrkos
|
  |
| Joined: 06 Sep 2010 |
| Total Posts: 8072 |
|
|
| 28 Jul 2012 12:03 PM |
>Am I the only one here who cannot find a legitimate reason for why this would be useful?
Because I like indexes starting at 0. There's a reason. |
|
|
| Report Abuse |
|
|
|
| 28 Jul 2012 12:13 PM |
| I like Lua because the indexes start at 1 :) It makes sense when you haven't used other languages before learning it. |
|
|
| Report Abuse |
|
|
Oysi
|
  |
| Joined: 06 Jul 2009 |
| Total Posts: 9058 |
|
| |
|
|
| 28 Jul 2012 12:23 PM |
^ I haven't notice that before. |
|
|
| Report Abuse |
|
|
Strieken
|
  |
| Joined: 17 Jun 2011 |
| Total Posts: 3058 |
|
|
| 28 Jul 2012 12:31 PM |
Even though Lua was my first language, I still prefer tables to index at 0 first.
Otherwise, it gets confusing if I work with multiple languages in the same time frame. |
|
|
| Report Abuse |
|
|
Quenty
|
  |
| Joined: 03 Sep 2009 |
| Total Posts: 9316 |
|
|
| 28 Jul 2012 12:44 PM |
| I usually use the pairs function, so I don't subtract to much. |
|
|
| Report Abuse |
|
|
Flurite
|
  |
| Joined: 03 Apr 2011 |
| Total Posts: 5386 |
|
|
| 28 Jul 2012 02:58 PM |
| Was there an x - 1 and you took out the - 1? |
|
|
| Report Abuse |
|
|