Lua question: Refer to a Table row by name?

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Lua question: Refer to a Table row by name?

Post by bartbes »

It might be removed in the future, or rather, it will be.
The new syntax is pretty simple, and works for strings too:

Code: Select all

t = {"a", "b", "c", "d"}
print(#t) --> 4
s = "abc"
print(#s) --> 3
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Lua question: Refer to a Table row by name?

Post by Robin »

Note that "setting something to nil" doesn't destroy it, it just lowers the reference count by 1, if the rc reaches 0 the object is destroyed.
Help us help you: attach a .love.
User avatar
Jasoco
Inner party member
Posts: 3726
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: Lua question: Refer to a Table row by name?

Post by Jasoco »

bartbes wrote:It might be removed in the future, or rather, it will be.
The new syntax is pretty simple, and works for strings too:

Code: Select all

t = {"a", "b", "c", "d"}
print(#t) --> 4
s = "abc"
print(#s) --> 3
Doesn't seem to work in 0.5.0 (Yes, I'm still using it. I haven't had the time to screw around and get it working in 0.6.0 yet.). Is it a new feature of Lua that only 0.6.0 has installed?
Robin wrote:Note that "setting something to nil" doesn't destroy it, it just lowers the reference count by 1, if the rc reaches 0 the object is destroyed.
But does it still remove the row from memory? Or at least from view of the program as if it doesn't exist anymore? Since I can't use table.remove anymore with the method I need to use, I need an equivalent. And setting it to nil seems to work.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Lua question: Refer to a Table row by name?

Post by Robin »

Jasoco wrote:
bartbes wrote:It might be removed in the future, or rather, it will be.
The new syntax is pretty simple, and works for strings too:

Code: Select all

t = {"a", "b", "c", "d"}
print(#t) --> 4
s = "abc"
print(#s) --> 3
Doesn't seem to work in 0.5.0 (Yes, I'm still using it. I haven't had the time to screw around and get it working in 0.6.0 yet.). Is it a new feature of Lua that only 0.6.0 has installed?
That should work. I'm not sure what is going on, but 0.5.0 uses Lua 5.1.
Jasoco wrote:But does it still remove the row from memory? Or at least from view of the program as if it doesn't exist anymore? Since I can't use table.remove anymore with the method I need to use, I need an equivalent. And setting it to nil seems to work.
Well, it does if there is only one reference. Example:

Code: Select all

sometable = {'hello'}
otherref = sometable
sometable = nil
print(otherref[1]) --prints hello
Because the table had another reference, it was not deleted when the name sometable was pointed to nil.
Help us help you: attach a .love.
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Lua question: Refer to a Table row by name?

Post by bartbes »

Well, unless you had some weird black magic setup the version of lua hasn't changed.
Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 10 guests