Skip to content
Extraits de code Groupes Projets
Sélectionner une révision Git
  • 61d42c85bfa3b026ccc2f72df50b34035ffcc099
  • develop par défaut protégée
  • implement-discord-markdown-update
  • matrix-attachments-order-fix
  • fix-oversized-file-transfer
  • matrix-attachment-order-fix
  • matrix-answer-modified-fix
  • cherry-pick-moise
8 résultats

matrixcommandhandler.ts

Blame
  • Bifurcation depuis ARISE / matrix-appservice-discord
    Le projet source a une visibilité limitée.
    lib.lua 2,50 Kio
    --[[
        Utility script written in lua for Vivy.
        These functions are meant to be used internaly to expose some objects and
        enums to the user without having to write this code in C/C++. It also
        includes some exposed Vivy API things, enums and object to the user.
    ]]
    
    function getrometatable(tbl, tablename)
        local errormsg = tablename ~= nil
            and "attempt to update " .. tablename .. " table"
            or  "attempt to update a read only table"
        return {
            __index     = tbl,
            __metatable = false,
            __newindex  = function (t, k, v)
                error(errormsg, 2)
            end
        }
    end
    
    function setrometatable(tbl, tblname) setmetatable(tbl, getrometatable(tbl, tblname)) end
    function generalize(tbl) for k, v in pairs(tbl) do _G[k] = v end end
    
    -- Create an enum
    function enum(tbl)
        local length = #tbl
        for i = 1, length do
            local v = tbl[i]
            tbl[v]  = v
        end
        setrometatable(tbl, "an enum")
        return tbl
    end
    
    -- Enums
    Iterable = enum {
        "LINE",
        "SYLLABE",
    }
    
    StdType = enum {
        "NUMBER",
        "COLOR",
        "BOOLEAN",
        "STRING",
    }
    
    -- Vivy global object construction
    os, io, debug   = nil, nil, nil
    Vivy            = { }
    Version         = { MAJOR = 0, MINOR = 1, PATCH = 0, LABEL = "alpha" }
    Vivy["___Fun"]  = FreeFunctions()
    
    Vivy["Version"] = setmetatable(Version, {
        __tostring = function ()
            return string.format("%d.%d.%d-%s",
            Version.MAJOR,
            Version.MINOR,
            Version.PATCH,
            Version.LABEL)
        end,
        __index     = Version,
        __metatable = false,
        __newindex  = function (t, k, v)
            error("attempt to update the version table", 2)
        end
    })
    
    function Vivy:global () return Vivy.___Fun end
    
    function Vivy:module (tbl)
        if type(tbl) == "table" and #tbl == 1 then
            return Vivy.___Fun.getModule(tbl[1])
        elseif type(tbl) == "string" then
            return Vivy.___Fun.getModule(tbl)
        else
            error("Invalid argument, you should pass a single string", 2)
        end
    end
    
    function Vivy:newColor (colorString)
        -- Not implemented
        return false
    end
    
    function Vivy:start  () return Vivy.___Fun:start()  end
    function Vivy:finish () return Vivy.___Fun:finish() end
    function Vivy:width  () return Vivy.___Fun:width()  end
    function Vivy:height () return Vivy.___Fun:height() end
    
    -- In case we are able to do the _ENV <- Vivy one day...
    Vivy["Vivy"] = Vivy
    
    -- Protect the content of Vivy, for now we are unable to protect the
    -- Vivy keyword...
    setrometatable(Vivy)
    generalize(Iterable)
    print = Vivy.___Fun.print