tables with functions

Discuss using and improving Lua and the Lua Player specific to the PSP.

Moderators: Shine, Insert_witty_name

Post Reply
swordman
Posts: 27
Joined: Tue Dec 27, 2005 9:04 pm

tables with functions

Post by swordman »

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]
romero126
Posts: 200
Joined: Sat Dec 24, 2005 2:42 pm

Re: tables with functions

Post by romero126 »

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;
}
swordman
Posts: 27
Joined: Tue Dec 27, 2005 9:04 pm

Post by swordman »

Thanks!
You offer always simple solutions ;)
Post Reply