Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

41
LINES

< > BotCompany Repo | #61 // ON/OFF BOT

Lua code

1  
-- a bot that can be turned on and off. and report its status.
2  
3  
function loadFunctionOnInput(sID)
4  
  local env = {}
5  
  setmetatable(env, {__index=function(o, k) return _G[k] end })
6  
  assert(input, 'no input')
7  
  assert(_G.input, 'no input in _G')
8  
  assert(env.input, 'no input in sub-env')
9  
  return assert(loadSnippet(sID, env))
10  
end
11  
12  
function loadOneArgFunction(sID)
13  
  local env = {}
14  
  setmetatable(env, {__index=function(o, k) return _G[k] end })
15  
  local f = assert(loadSnippet(sID, env))
16  
  f()
17  
  for k, v in pairs(env) do
18  
    if type(v) == 'function' then
19  
      return v
20  
    end
21  
  end
22  
23  
  error('no function found in '..sID)
24  
end
25  
26  
is_TURN_ON = loadFunctionOnInput("#55")
27  
is_TURN_OFF = loadFunctionOnInput("#56")
28  
is_ARE_YOU_ON = loadFunctionOnInput("#62")
29  
renderIntention = loadOneArgFunction("#63")
30  
31  
if is_TURN_ON() then
32  
  state.on = true
33  
elseif is_TURN_OFF() then
34  
  state.on = false
35  
elseif is_ARE_YOU_ON() then
36  
  -- proceed
37  
else
38  
  return ''
39  
end
40  
41  
return renderIntention(state.on and 'I AM ON' or 'I AM OFF')

test run  test run with input  download  show line numbers   

Travelled to 12 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

Comments [hide]

ID Author/Program Comment Date
827 #1000610 Edit suggestion:
!636
!629

main {
static Object androidContext;
static String programID;

public static void main(String[] args) throws Exception {
-- 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')

}}
2015-08-19 22:47:33  delete 
812 #1000604 (pitcher) 2015-08-18 00:07:22

add comment

Image recognition results

Recognizer Recognition Result Visualize Recalc
#308 1046 [visualize]

Snippet ID: #61
Snippet name: ON/OFF BOT
Eternal ID of this version: #61/1
Text MD5: 568b46a4420eb70b3e6a1c8955494c5a
Author: stefan
Category: bots
Type: Lua code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2013-12-31 20:43:50
Source code size: 1046 bytes / 41 lines
Pitched / IR pitched: Yes / Yes
Views / Downloads: 1590 / 316
Referenced in: [show references]