the best way to create “external” modules is this:
external.lua
-- create a table that holds your functions
local funcs = {}
-- create functions like this:
funcs.myAwesomeFunction1 = function ( param1, param2 )
local p1 = param1
local p2 = param2
local p3 = p1 + p2
return p3
end
funcs.myAwesomeFunction2 = function ( param1, param2 )
local p1 = param1
local p2 = param2
local p3 = p1 - p2
return p3
end
-- at the end of your module return the functions-table
return funcs
if you want to load the module into another module, do
-- require external.lua module
myFunc = require ("external") -- without .lua
-- call a function from external.lua
local newNumber = myFunc.myAwesomeFunction1 ( 3,2 )
-- newNumber is 5
that is in short what is illustrated here
http://blog.anscamobile.com/2011/09/a-better-approach-to-external-modules/
hope that helps
-finefin
[import]uid: 70635 topic_id: 19376 reply_id: 74874[/import]