2015年4月23日 星期四

[Corona SDK] How to call those functions in other .lua files?

Corona SDK APIs are classified according to their purposes, such as display.*,  os.*, and so on.
If we have functions with similar purposes, we can also put them in the same .lua file.
How can we call them after that?

Assume that we have one file named GameScenario.lua, which is used to configure the setting for each round:
gameScenario = {}

local function configureGameScenario(round)
 print("configureGameScenario():"..round)
end--local function configureGameScenario()

gameScenario.configureGameScenario = configureGameScenario
return gameScenario
configureGameScenario() will decide the setting according to the input parameter round.

To call it from other file:
local gameScenario = require("GameScenario")
gameScenario.configureGameScenario(1)

The above method is to utilize the powerful table of lua.

沒有留言:

張貼留言