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
➜ table with ipairs problem...
table with ipairs problem...
|
It is now over 60 days since the last post. This thread is closed.
Refresh page
Posted by
| Maxhrk
USA (76 posts) Bio
|
Date
| Wed 19 Dec 2007 06:13 AM (UTC) |
Message
|
local aliaslist={
[1] = {enable=true,
group="common",
label="common",
alias_rex=rex.new("^Install$"),
alias_func=function () aliases.install(match) return true end
}
}
function aliasline(input)
local bool = false
for id, v in ipairs(aliaslist) do
if aliaslist[id]["enable"] == true then
local match
_, _, match = aliaslist[id].alias_rex:tfind(input)
if match then
bool = aliaslist[id]['alias_func'](match)
return bool
end --if
end --if
end -- for
end -- aliasline
i ran this code.. and it gave the error like this:
[ILua]: ./trigger.lua:36: bad argument #1 to 'tfind' (string expected, got table)
Traceback:
[C]:-1: in function 'tfind'
./trigger.lua:36: in function 'aliasline'
lusternia.lua:19: in a Lua function
Error in the 'client_aliases' callback.
so.. basically i am not good at table thing.. but.. i hope to find solution to this problem soon. thanks! | Top |
|
Posted by
| ThomasWatts
USA (66 posts) Bio
|
Date
| Reply #1 on Wed 19 Dec 2007 06:40 AM (UTC) Amended on Wed 19 Dec 2007 06:45 AM (UTC) by ThomasWatts
|
Message
| Try 'aliaslist[id].alias_rex.tfind(input)' instead. Notice the '.'(dot) versus the ':'(colon), it makes a big difference.
See: http://www.lua.org/manual/5.1/manual.html#2.5.8
The part about syntactical sugar is important.
Also, as a side note, 'id' is the current key of ipairs(aliaslist), and 'v' is the value.
Everywhere inside the for loop you have 'aliaslist[id]' you can safely substitute 'v'. | Top |
|
Posted by
| Maxhrk
USA (76 posts) Bio
|
Date
| Reply #2 on Wed 19 Dec 2007 07:19 AM (UTC) |
Message
| i have tired the dot method.. turn out there is error 'wrong argumative type' on the same line. | Top |
|
Posted by
| Maxhrk
USA (76 posts) Bio
|
Date
| Reply #3 on Wed 19 Dec 2007 07:29 AM (UTC) Amended on Wed 19 Dec 2007 07:32 AM (UTC) by Maxhrk
|
Message
| nevermind..
i tries one higher further.
when i try check type within trigger() function. it show that input is a table. However.. when i change it bit..
voila! the type of 'input' is now string!
harrah.
something to learn. thanks.
edit:
i think alias_rex:tfind is better method because it will result into table. i think. so that way i can get wildcards within (match) table.
| Top |
|
Posted by
| ThomasWatts
USA (66 posts) Bio
|
Date
| Reply #4 on Wed 19 Dec 2007 08:34 PM (UTC) |
Message
| Read what I posted in my previous post and I will try to elaborate a little more here.
In your code listed in the OP, 'aliaslist' is a table.
I am assuming 'alias_rex' is a table as well.
I am also assuming 'input' is a string when passed to 'aliasline'.
Both 'tfind' and 'alias_func' are functions in the 'aliaslist' table.
Now the following are both equal to the same in Lua:
alias_rex:tfind(input) == alias_rex.tfind(alias_rex, input)
Therefore, the first argument to 'tfind' is 'alias_rex' and not 'input' as you wanted to be.
Also, to use your last example:
alias:process(input)
IS ALSO THE SAME AS
alias.process(alias, input)
Notice the order of the arguments. | Top |
|
Posted by
| Maxhrk
USA (76 posts) Bio
|
Date
| Reply #5 on Wed 19 Dec 2007 10:00 PM (UTC) |
Message
| that is very interesting. thanks. | 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.
18,888 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top