Use separate lua_State for different script files.
[screen-lua.git] / src / scripts / cmdcallback.lua
blob3ef43901cf5811f7dde6ee7459724ac0fb4d83a0
1 --[[ For now, this sample function will simply record all the commands executed ]]--
3 function cmd1(name, args)
4 os.execute('mkdir -p /tmp/debug')
5 local f = io.open('/tmp/debug/22', 'a')
6 f:write("Command executed: " .. name)
8 for i, c in pairs(args) do
9 f:write(" " .. c)
10 end
12 f:write("\n")
13 f:close()
14 return 0
15 end
17 function cmd2(name, args)
18 os.execute('mkdir -p /tmp/debug')
19 local f = io.open('/tmp/debug/11', 'a')
20 f:write("Command executed: " .. name)
22 for i, c in pairs(args) do
23 f:write(" " .. c)
24 end
26 f:write("\n")
27 f:close()
28 return 0
29 end
31 ticket1 = screen.hook("cmdexecuted", cmd1)
32 ticket2 = screen.hook("cmdexecuted", "cmd2")
34 screen.hook("cmdexecuted", function(name, args)
35 os.execute('mkdir -p /tmp/debug')
36 local f = io.open('/tmp/debug/33', 'a')
37 f:write("Command executed: " .. name)
39 for i, c in pairs(args) do
40 f:write(" " .. c)
41 end
43 f:write("\n")
44 f:close()
45 return 0
46 end
49 function unhook()
50 ticket1:unhook()
51 ticket2:unhook()
52 end
54 --A second unhook should faild
55 function debug_unhook()
56 ticket1:unhook()
57 end
59 --A second hook should faild
60 function debug_hook()
61 ticket1=screen.hook("cmdexecuted", "cmd1")
62 end