Page 2 of 2
Re: Lua question: Refer to a Table row by name?
Posted: Mon Jan 25, 2010 9:34 am
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
Re: Lua question: Refer to a Table row by name?
Posted: Mon Jan 25, 2010 5:12 pm
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.
Re: Lua question: Refer to a Table row by name?
Posted: Mon Jan 25, 2010 7:53 pm
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.
Re: Lua question: Refer to a Table row by name?
Posted: Mon Jan 25, 2010 7:56 pm
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.
Re: Lua question: Refer to a Table row by name?
Posted: Tue Jan 26, 2010 6:50 am
by bartbes
Well, unless you had some weird black magic setup the version of lua hasn't changed.