How to use a table as a function argument?

[Cross-posted from Developer Support in case any Lua experts know this.]

Now that OpenFeint has been updated, we can implement the new OF syntax:

openfeint.setHighScore( { leaderboardID=“abc123”, score=82342, displayText=“82,342 pts” } )

But the useful OpenFeint wrapper code:

safeopenfeint.setHighScore( lbID, points )
–which calls to…
function setHighScore( leaderboardId, score )
if not isOFSupported then return end

openfeint.setHighScore(leaderboardId, score)
end

uses individual arguments. ***To make it accept a table, how would you write the call in main.lua?***

safeopenfeint.setHighScore( { leaderboardID=lbID, score=points} )

and then in the safeopenfeint module:

function setHighScore( {} )
if not isOFSupported then return end

openfeint.setHighScore({})
end

or do you have to supply values in the table that’s in the module? [import]uid: 1560 topic_id: 3563 reply_id: 303563[/import]

hi,

if you wrap your code in <lua> … </lua>

it makes it easier to read! eg

[lua]openfeint.setHighScore( { leaderboardID=“abc123”,
score=82342,
displayText=“82,342 pts” } )[/lua] But the useful OpenFeint wrapper code: [lua]safeopenfeint.setHighScore( lbID, points )
–which calls to…
function setHighScore( leaderboardId, score )
if not isOFSupported then return end

openfeint.setHighScore(leaderboardId, score)
end[/lua] uses individual arguments. ***To make it accept a table, how would you write the call in main.lua?***
[lua]safeopenfeint.setHighScore( { leaderboardID=lbID, score=points} )[/lua] and then in the safeopenfeint module:
[lua]function setHighScore( {} )
if not isOFSupported then return end

openfeint.setHighScore({})
end[/lua] [import]uid: 6645 topic_id: 3563 reply_id: 10761[/import]

If I understand you correctly, you want to wrap openfeint.setHighScore() in your own wrapper function?

So, in this case, it’s pretty simple. You simply make the wrapper have the same arguments as the original:

[lua]safeopenfeint.setHighScore = function( params )
if not isOFSupported then return end

openfeint.setHighScore( params )
end

– create params table
local myParams = { leaderboardID=myId, score = points }

– call wrapper
safeopenfeint.setHighScore( myParams )[/lua] [import]uid: 26 topic_id: 3563 reply_id: 11465[/import]