-- a bot that can be turned on and off. and report its status. function loadFunctionOnInput(sID) local env = {} setmetatable(env, {__index=function(o, k) return _G[k] end }) assert(input, 'no input') assert(_G.input, 'no input in _G') assert(env.input, 'no input in sub-env') return assert(loadSnippet(sID, env)) end function loadOneArgFunction(sID) local env = {} setmetatable(env, {__index=function(o, k) return _G[k] end }) local f = assert(loadSnippet(sID, env)) f() for k, v in pairs(env) do if type(v) == 'function' then return v end end error('no function found in '..sID) end is_TURN_ON = loadFunctionOnInput("#55") is_TURN_OFF = loadFunctionOnInput("#56") is_ARE_YOU_ON = loadFunctionOnInput("#62") renderIntention = loadOneArgFunction("#63") if is_TURN_ON() then state.on = true elseif is_TURN_OFF() then state.on = false elseif is_ARE_YOU_ON() then -- proceed else return '' end return renderIntention(state.on and 'I AM ON' or 'I AM OFF')