Assign a function to a Table???

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

Moderators: Shine, Insert_witty_name

Post Reply
CT_Bolt
Posts: 14
Joined: Sat Mar 04, 2006 3:21 am
Location: Computer Chair

Assign a function to a Table???

Post by CT_Bolt »

Well... Hello my fellow PSP Lua coders... OK so I know it's posible to create a table with a function, I just don't know exactlly how to do what I need to do, which is:
1. I am creating a ScrollingCanvas table and I want to assign the function 'Move' to the table, to move the picture(canvas) around the screen using the tables position data (X, Y).
2. The question for you is: How do I create the table, so I can call the move method like this:

Code: Select all

AScrollingCanvas:Move(X, Y)
Please Help.

PS. If I didn't give enough information, plz just PM me.
KawaGeo
Posts: 191
Joined: Sat Aug 27, 2005 6:52 am
Location: Calif Mountains

Post by KawaGeo »

Code: Select all

function foo()
  print "foo"
end

function bar()
  print "bar"
end

my = {f=foo, b=bar} -- by named keys

my.f()
my.b()

-- OR

my = {foo, bar}     -- by indices

my[1]()
my[2]()
Is this what you wanted to know?
Geo Massar
Retired Engineer
CT_Bolt
Posts: 14
Joined: Sat Mar 04, 2006 3:21 am
Location: Computer Chair

Not quite...

Post by CT_Bolt »

Well... I actually knew how to do that(I have pretty good knowledge of Lua now) but, Thank you for replying.

The basic difference between what you have showed me and what I mean is I need to use values from 'AScrollCanvas' ( X & Y ) and then change them accordingly (change only the current table's X & Y values).

Although I might use that way, do you understand what I mean now?

Oh B-T-W Thanks anyway for you're help!!!
Post Reply