| View previous topic :: View next topic |
| Author |
Message |
swordman
Joined: 27 Dec 2005 Posts: 27
|
Posted: Thu Dec 29, 2005 12:13 am Post subject: tables with functions |
|
|
Hi I'm here again.
I would like to know if it possible to crate a table that has functions associated with the keys.
At least I need a way to call different functions like in a switch-case but
I'm tring to do this using the tables to search the case.
This is a possible example of what I want to do (doesn't work):
test = "cane"
versi = {
cane = function bau()
gatto = function miao()
mucca = function mu()
}
function bau()
print "BAU BAU BAU"
end
function miao()
print "MIAO MIAO MIAO"
end
function mu()
print "MU MU MU"
end
versi[test] |
|
| Back to top |
|
 |
romero126
Joined: 24 Dec 2005 Posts: 200
|
Posted: Thu Dec 29, 2005 1:47 pm Post subject: Re: tables with functions |
|
|
| swordman wrote: | Hi I'm here again.
I would like to know if it possible to crate a table that has functions associated with the keys.
At least I need a way to call different functions like in a switch-case but
I'm tring to do this using the tables to search the case.
This is a possible example of what I want to do (doesn't work):
test = "cane"
versi = {
cane = function bau()
gatto = function miao()
mucca = function mu()
}
function bau()
print "BAU BAU BAU"
end
function miao()
print "MIAO MIAO MIAO"
end
function mu()
print "MU MU MU"
end
versi[test] |
Heres what you do there are 2 ways of doing this.
Variable = { }
function Variable:Command(arg1,arg2)
end
or
Variable = {
Command = function (arg1, arg2)
end;
} |
|
| Back to top |
|
 |
swordman
Joined: 27 Dec 2005 Posts: 27
|
Posted: Thu Dec 29, 2005 4:25 pm Post subject: |
|
|
Thanks!
You offer always simple solutions ;) |
|
| Back to top |
|
 |
|