summaryrefslogtreecommitdiff
path: root/indra/newview/scripts/lua
diff options
context:
space:
mode:
authorMnikolenko Productengine <mnikolenko@productengine.com>2024-06-14 15:39:35 +0300
committerMnikolenko Productengine <mnikolenko@productengine.com>2024-06-14 15:42:43 +0300
commit81a153da87f56e4db0a38ebb94a9c72471e0b002 (patch)
tree6004bb34dd1b8ef25ab0b63257749b038b86ea5d /indra/newview/scripts/lua
parente92689063bdbe34907348a12f1db39bc81132783 (diff)
Add nearby chat listener
Diffstat (limited to 'indra/newview/scripts/lua')
-rw-r--r--indra/newview/scripts/lua/LLChatListener.lua41
-rw-r--r--indra/newview/scripts/lua/test_LLChatListener.lua27
2 files changed, 68 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..d615ae5dbc
--- /dev/null
+++ b/indra/newview/scripts/lua/LLChatListener.lua
@@ -0,0 +1,41 @@
+local fiber = require 'fiber'
+local inspect = require 'inspect'
+
+local LLChatListener = {}
+local waitfor = {}
+
+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)
+ return data
+ end
+
+ fiber.launch(self.name, function()
+ event = waitfor:wait()
+ while event and self:handleMessages(event) do
+ event = waitfor:wait()
+ end
+ end)
+
+ leap.send('LLChatBar', {op='listen'})
+end
+
+function LLChatListener:stop()
+ leap.send('LLChatBar', {op='stopListening'})
+ 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..2c7b1dc3e5
--- /dev/null
+++ b/indra/newview/scripts/lua/test_LLChatListener.lua
@@ -0,0 +1,27 @@
+local LLChatListener = require 'LLChatListener'
+local LLChat = require 'LLChat'
+
+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 LLChatListener.handleMessages(self, event_data)
+end
+
+listener:start()