Requiring composer in a module?

Is it possible to use

local composer=require "composer"

in a module without the scene functions of composer, so I have access to (for example) the composer.state tables and values inside the module?

Can this cause problems during a scene change?

With module I mean something like this:

local mod={} local composer=require "composer" loca dostuff=function()     -- code here     composer.state.money=1000 end mod.dostuff=dostuff return mod

I then require the module inside a “normal” composer scene at top of this scene with:

local module=require("module")

Can this be done without “problems” during a scene change, reload of the scene, etc.?

I think that should be okay, I do something similar when catching Runtime errors so I can send some info about the scene to my logging service.

Another alternative is to pass composer into any function that needs to do something with it.

[lua]

local dostuff=function(composer)

    – code here
    composer.state.money=1000

end

[/lua]

[lua]

module.doStuff(composer)

[/lua]

you can safely do this anywhere, as all it does it pull in a reference to the already-loaded* composer module.

*the only time you might encounter something weird is if you include a module (that includes composer) early on, in main.lua, before main.lua itself had required composer.  in that case your module’s require will load composer and main’s require will pull the reference.  even that should work properly for 99% of all “normal” uses.  only if you have some very special requirements about the timing of the composer load (because it does do some work at load time) might this be an issue.  if this makes no sense to you then you’re not in the 1% that needs to even consider it.

Thanks for your help!

I think that should be okay, I do something similar when catching Runtime errors so I can send some info about the scene to my logging service.

Another alternative is to pass composer into any function that needs to do something with it.

[lua]

local dostuff=function(composer)

    – code here
    composer.state.money=1000

end

[/lua]

[lua]

module.doStuff(composer)

[/lua]

you can safely do this anywhere, as all it does it pull in a reference to the already-loaded* composer module.

*the only time you might encounter something weird is if you include a module (that includes composer) early on, in main.lua, before main.lua itself had required composer.  in that case your module’s require will load composer and main’s require will pull the reference.  even that should work properly for 99% of all “normal” uses.  only if you have some very special requirements about the timing of the composer load (because it does do some work at load time) might this be an issue.  if this makes no sense to you then you’re not in the 1% that needs to even consider it.

Thanks for your help!