Best way to structure code to work on Android AND iOS for leaderboards and monetization

I need to add leaderboards as well as monetization code to my game.  I’m trying to figure out the best way to structure the code since Android and iOS are different.  

Can someone who has experience in this just give me a high level overview of the easiest way to set up the code?  

Do I create modules like   appleLeaderboard.lua, androidLeaderboard.lua, etc… and then just require and use functions based on if it’s running on iOS or android?

Any other tips/tricks I should be aware of before?

The best practice tends to be that you write a single module that handles leaderboards for both OS, same with IAPs.

Then in the modules, all you need is system.getInfo( “platform” ) to identify which OS you are on. As you write functions like “purchase( args )”, you’ll need a simple if statement and then you run OS specific code.

The benefit in this sort of approach is that you’ll be able to use the same function calls regardless of the OS, which makes implementing the module into your projects a lot easier. Now, there are some features that only exists for a specific OS (see https://docs.coronalabs.com/guide/monetization/IAP/index.html#store-specific) that you’d also need to take into account.

Ok, that makes sense.   Thanks XeduR @Spyric!

If it helps at all, my Puggle library allows you to register achievements, leaderboards, and iaps for all platforms and then just call one function to unlock/purchase them regardless of platform - https://gitlab.com/grahamranson/Puggle
 

puggle.store:add( "removeAdverts", { apple = "com.website.removeads", google = "com.website.removeads", amazon = "com.website.removeads" } ) puggle.leaderboards:add( "hiScore", { android = "id", ios = "id" } ) puggle.achievements:add( "completedFirstLevel", { android = "id", ios = "id" } ) -- LATER ON puggle.store:purchase( "removeAdverts" ) puggle.leaderboards:setHighScore( "hiScore", currentScore ) puggle.achievements:unlock( "completedFirstLevel" )