Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are
spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the
password reset link.
Due to spam on this forum, all posts now need moderator approval.
Entire forum
➜ MUSHclient
➜ Lua
➜ Having trouble with variable number of arguments
Having trouble with variable number of arguments
|
It is now over 60 days since the last post. This thread is closed.
Refresh page
Pages: 1
2
Posted by
| Nick Gammon
Australia (23,133 posts) Bio
Forum Administrator |
Date
| Reply #15 on Thu 11 Sep 2008 09:31 PM (UTC) |
Message
|
Quote:
c = { [xxx] = "a" } -- assigns "a" to c.q
d = { "xxx" = "a" } -- error: '}' expected near '='
I'd expect the last table to work and have (d.xxx == "a") as a result. Why is -that- assignment not supported?
I think the answer would be, it would be ambiguous.
On the face of it, it would seem reasonable to support stuff like:
t = {
"a" = 22, -- t ["a"] = 22
45 = 68, -- t [45] = 68
true = 99, -- t [true] = 99
2 + 2 = 55, -- t [4] = 55
}
Effectively by allowing any sort of constant there. However then you would expect any expression there too (like in the case of 2 + 2).
Now you hit a big problem:
foo = 42
t = {
foo = 99, -- t [42] = 99
}
The entry "foo" is an expression, which happens to be a variable containing 42. However we are already used to that actually meaning:
foo = 42
t = {
foo = 99, -- t ["foo"] = 99
}
So, exceptions would have to be made, to be consistent with what currently happens. The whole thing would probably become a mess. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Worstje
Netherlands (899 posts) Bio
|
Date
| Reply #16 on Thu 11 Sep 2008 11:04 PM (UTC) |
Message
| Good reason, I am satisfied. ^_^
(Although I still say it's the wrong way around.. dum dum.) | Top |
|
Posted by
| David Haley
USA (3,881 posts) Bio
|
Date
| Reply #17 on Thu 11 Sep 2008 11:33 PM (UTC) |
Message
| Well, you wouldn't have to allow arbitrary expressions -- you could stick with identifiers and string literals only. Of course, then you have an inconsistency of sorts of only allowing string constants. |
David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone
http://david.the-haleys.org | Top |
|
The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).
To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.
46,861 views.
This is page 2, subject is 2 pages long:
1
2
It is now over 60 days since the last post. This thread is closed.
Refresh page
top