summaryrefslogtreecommitdiff
path: root/indra/newview/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'indra/newview/scripts')
-rw-r--r--indra/newview/scripts/lua/LLChatListener.lua45
-rw-r--r--indra/newview/scripts/lua/test_LLChatListener.lua28
2 files changed, 73 insertions, 0 deletions
diff --git a/indra/newview/scripts/lua/LLChatListener.lua b/indra/newview/scripts/lua/LLChatListener.lua
new file mode 100644
index 0000000000..b4e90d272c
--- /dev/null
+++ b/indra/newview/scripts/lua/LLChatListener.lua
@@ -0,0 +1,45 @@
+local fiber = require 'fiber'
+local inspect = require 'inspect'
+local leap = require 'leap'
+
+local LLChatListener = {}
+local waitfor = {}
+local listener_name = {}
+
+function LLChatListener:new()
+ local obj = setmetatable({}, self)
+ self.__index = self
+ obj.name = 'Chat_listener'
+
+ return obj
+end
+
+function LLChatListener:handleMessages(event_data)
+ print(inspect(event_data))
+ return true
+end
+
+function LLChatListener:start()
+ waitfor = leap.WaitFor:new(-1, self.name)
+ function waitfor:filter(pump, data)
+ if pump == "LLNearbyChat" then
+ return data
+ end
+ end
+
+ fiber.launch(self.name, function()
+ event = waitfor:wait()
+ while event and self:handleMessages(event) do
+ event = waitfor:wait()
+ end
+ end)
+
+ listener_name = leap.request(leap.cmdpump(), {op='listen', source='LLNearbyChat', listener="ChatListener", tweak=true}).listener
+end
+
+function LLChatListener:stop()
+ leap.send(leap.cmdpump(), {op='stoplistening', source='LLNearbyChat', listener=listener_name})
+ waitfor:close()
+end
+
+return LLChatListener
diff --git a/indra/newview/scripts/lua/test_LLChatListener.lua b/indra/newview/scripts/lua/test_LLChatListener.lua
new file mode 100644
index 0000000000..b9696e7cfc
--- /dev/null
+++ b/indra/newview/scripts/lua/test_LLChatListener.lua
@@ -0,0 +1,28 @@
+local LLChatListener = require 'LLChatListener'
+local LLChat = require 'LLChat'
+local leap = require 'leap'
+
+function openOrEcho(message)
+ local floater_name = string.match(message, "^open%s+(%w+)")
+ if floater_name then
+ leap.send("LLFloaterReg", {name = floater_name, op = "showInstance"})
+ else
+ LLChat.sendNearby('Echo: ' .. message)
+ end
+end
+
+local listener = LLChatListener:new()
+
+function listener:handleMessages(event_data)
+ if string.find(event_data.message, '[LUA]') then
+ return true
+ elseif event_data.message == 'stop' then
+ LLChat.sendNearby('Closing echo script.')
+ return false
+ else
+ openOrEcho(event_data.message)
+ end
+ return true
+end
+
+listener:start()