forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

tables with functions

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Lua Player Development
View previous topic :: View next topic  
Author Message
swordman



Joined: 27 Dec 2005
Posts: 27

PostPosted: Thu Dec 29, 2005 12:13 am    Post subject: tables with functions Reply with quote

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
View user's profile Send private message
romero126



Joined: 24 Dec 2005
Posts: 200

PostPosted: Thu Dec 29, 2005 1:47 pm    Post subject: Re: tables with functions Reply with quote

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
View user's profile Send private message
swordman



Joined: 27 Dec 2005
Posts: 27

PostPosted: Thu Dec 29, 2005 4:25 pm    Post subject: Reply with quote

Thanks!
You offer always simple solutions ;)
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Lua Player Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group