[03 Mar 2010] Pitfall: table access!
Posted: Sat Jun 13, 2020 5:32 pm
Note: This is an archived post that was originally sent to the Hollywood mailing list on Wed, 03 Mar 2010 16:16:02 -0000
I was hunting a bug in my code and, first, couldn't understand why it was a bug. Now, after tracing back the problem, i thought, i should write about it here, so others don't have to feel the same pain
The hollywood documentation says:
Well, this is not quite true.
For example:
Now see that:
EVEN WORSE IS THIS:
AND ALSO:
So you see, Hollywood *DOES* distinguish between lower and upper case letter. Furthermore, *IF* you have declared a table field *NOT* with the dot method, you cannot even access a table field with the dot mehtod *IF* the field was declared with some upper case letters!
Dunno, if this is a bug in the documentation or in Hollywood 4.5
regards, Tom
I was hunting a bug in my code and, first, couldn't understand why it was a bug. Now, after tracing back the problem, i thought, i should write about it here, so others don't have to feel the same pain
The hollywood documentation says:
Code: Select all
You can access named elementes of a table also in two ways:
b = a["name"]
b = a.name
Both lines will assign the same value to b. The most common way to access and initialize named elements of a table is to use the dot method. *Please* *note* *that* *Hollywood* *does* *not* *distinguish* *between* *upper* *and* *lower* *case* *names*, so you could also access the elements above by using a.NAME or even a.nAmE"
For example:
Code: Select all
test = {}
test.myName = {}
Code: Select all
DebugPrint(RawGet(test,"myname")) --> True
DebugPrint(RawGet(test,"myName")) --> False
DebugPrint(test.myname) --> Table:
DebugPrint(test.myName) --> Table:
DebugPrint(test["myname"]) --> Table:
DebugPrint(test["myName"]) --> Error!
Code: Select all
test2={}
test2["myName"] = "blabla"
DebugPrint(test2["myName"]) --> "blabla"
DebugPrint(test2["myname"]) --> Error!
Code: Select all
DebugPrint(test2.myname) --> Error!
DebugPrint(test2.myName) --> Error!
Dunno, if this is a bug in the documentation or in Hollywood 4.5
regards, Tom