Simplify module structure

This commit is contained in:
nucular 2014-05-07 16:58:37 +02:00
parent a92cc28afd
commit 3cf88e042e
2 changed files with 14 additions and 18 deletions

View File

@ -15,7 +15,7 @@ With Löve2D 0.9:
local sfxr = require("sfxr") local sfxr = require("sfxr")
function love.load() function love.load()
local sound = sfxr.new() local sound = sfxr.newSound()
sound:randomize() sound:randomize()
love.audio.newSource(sound:generateSoundData()):play() love.audio.newSource(sound:generateSoundData()):play()
end end
@ -29,7 +29,7 @@ local sfxr = require("sfxr")
local driverId = ao.defaultDriverId() local driverId = ao.defaultDriverId()
local device = ao.openLive(driverId, {bits = 16, rate = 44100, channels = 1}) local device = ao.openLive(driverId, {bits = 16, rate = 44100, channels = 1})
local sound = sfxr.new() local sound = sfxr.newSound()
sound:randomize() sound:randomize()
local buffer = sound:generateString() local buffer = sound:generateString()

View File

@ -22,13 +22,6 @@ SOFTWARE.
]]-- ]]--
local sfxr = {} local sfxr = {}
sfxr.__index = sfxr
local function new()
local obj = setmetatable({}, sfxr)
obj:__init()
return obj
end
-- Constants -- Constants
@ -63,9 +56,12 @@ local function cpypol(a, b)
end end
end end
-- Class functions -- The main Sound class
function sfxr:__init() sfxr.Sound = {}
sfxr.Sound.__index = sfxr.Sound
function sfxr.Sound:__init()
-- Build tables to store the parameters in -- Build tables to store the parameters in
self.volume = {} self.volume = {}
self.envelope = {} self.envelope = {}
@ -193,12 +189,12 @@ function sfxr:generate()
end end
end end
-- Constructor
sfxr:__init() function sfxr.newSound(...)
local instance = setmetatable({}, sfxr.Sound)
instance:__init(...)
return instance
end
return setmetatable({new = new}, return sfxr
{
__call = function(_, ...)
return new(...)
end
})