diff options
author | Nat Goodspeed <nat@lindenlab.com> | 2024-06-11 21:42:10 -0400 |
---|---|---|
committer | Nat Goodspeed <nat@lindenlab.com> | 2024-06-11 21:42:10 -0400 |
commit | 18c4dcc5998e061fe3ab54607665c775dd18c826 (patch) | |
tree | 69d84b90ca249c2a0877c7a368692b64d289be11 /indra/newview/scripts/lua/WaitQueue.lua | |
parent | eae45eefb55410782559b4ace5350b2a99f63234 (diff) |
Allow Python-like 'object = ClassName(ctor args)' constructor calls.
The discussions we've read about Lua classes conventionally use
ClassName:new() as the constructor, and so far we've followed that convention.
But setting metaclass(ClassName).__call = ClassName.new permits Lua to respond
to calls of the form ClassName(ctor args) by implicitly calling
ClassName:new(ctor args).
Introduce util.classctor(). Calling util.classctor(ClassName) sets ClassName's
metaclass's __call to ClassName's constructor method. If the constructor method
is named something other than new(), pass ClassName.method as the second arg.
Use util.classctor() on each of our classes that defines a new() method.
Replace ClassName:new(args) calls with ClassName(args) calls throughout.
Diffstat (limited to 'indra/newview/scripts/lua/WaitQueue.lua')
-rw-r--r-- | indra/newview/scripts/lua/WaitQueue.lua | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/indra/newview/scripts/lua/WaitQueue.lua b/indra/newview/scripts/lua/WaitQueue.lua index 6bcb9d62c2..7e10d03295 100644 --- a/indra/newview/scripts/lua/WaitQueue.lua +++ b/indra/newview/scripts/lua/WaitQueue.lua @@ -4,14 +4,15 @@ local fiber = require('fiber') local Queue = require('Queue') +local util = require('util') local function dbg(...) end -- local dbg = require('printf') -local WaitQueue = Queue:new() +local WaitQueue = Queue() function WaitQueue:new() - local obj = Queue:new() + local obj = Queue() setmetatable(obj, self) self.__index = self @@ -20,6 +21,8 @@ function WaitQueue:new() return obj end +util.classctor(WaitQueue) + function WaitQueue:Enqueue(value) if self._closed then error("can't Enqueue() on closed Queue") |