/* ==================================== JUCER_BINARY_RESOURCE ====================================

   This is an auto-generated file: Any edits you make may be overwritten!

*/

#include <cstring>

namespace mods
{

//================== object.lua ==================
static const unsigned char temp_binary_data_3[] =
"--- Define objects with attributes.\n"
"-- @module el.object\n"
"-- @usage\n"
"-- local Animal = object()\n"
"local M = {}\n"
"\n"
"local function lookupmeta (T, name)\n"
"    while T do\n"
"        local mt = getmetatable (T)\n"
"        if mt then\n"
"            local val = rawget (mt, name)\n"
"            if val then return val, T end\n"
"        end\n"
"        T = mt and mt.__base or nil\n"
"    end\n"
"    return nil, nil\n"
"end\n"
"\n"
"--- Create a proxy for userdata.\n"
"-- @tparam table T Derived type\n"
"-- @tparam table U Type table which created userdata\n"
"-- @tparam userdata _impl The userdata to wrap.\n"
"local function UserDataProxy (T, U, _impl)\n"
"    local impl = _impl\n"
"    assert (type(impl) == 'userdata', \"not userdata\")\n"
"    local atts = getmetatable(T).__atts or false\n"
"\n"
"    local props = {}\n"
"    for _,k in ipairs(getmetatable(U).__props or {}) do\n"
"        props[k] = true\n"
"    end\n"
"    \n"
"    local methods = getmetatable(U).__methods or {}\n"
"    local proxy,proxy_mt = {}, {}\n"
"    local exported = {}\n"
"\n"
"    for _, m in ipairs (methods) do\n"
"        exported[m] = function (self, ...)\n"
"            -- print (\"call: \" .. tostring(impl) .. ' self:' .. m .. ' (...): nargs=' .. select (\"#\", ...))\n"
"            return impl[m] (impl, ...)\n"
"        end\n"
"    end\n"
"\n"
"    proxy_mt.__impl = impl\n"
"\n"
"    function proxy_mt.__gc (self)\n"
"        atts = nil\n"
"        exported = nil\n"
"        methods = nil\n"
"        impl = nil\n"
"        proxy_mt.__impl = nil\n"
"        proxy_mt = nil\n"
"        proxy = nil\n"
"    end\n"
"\n"
"    function proxy_mt.__index (self, k)\n"
"        local val = rawget (self, k)\n"
"        if val then return val end\n"
"\n"
"        if atts then\n"
"            val = atts[k];\n"
"            if val and val.get then\n"
"                return val.get (self) \n"
"            end\n"
"        end\n"
"\n"
"        if props[k] then return impl[k] end\n"
"\n"
"        val = T ~= U and T[k] or nil;\n"
"        if val then return val end\n"
"\n"
"        val = exported[k];\n"
"        if val then return val end\n"
"\n"
"        return nil\n"
"    end\n"
"\n"
"    function proxy_mt.__newindex (self, k, v)\n"
"        local a = atts and atts [k] or false\n"
"        if a then\n"
"            if a.set then\n"
"                a.set (self, v)\n"
"            else\n"
"                error (\"cannot modify readonly attribute\")\n"
"            end\n"
"            return\n"
"        end\n"
"\n"
"        if props[k] then impl[k] = v; return end\n"
"\n"
"        rawset (self, k, v)\n"
"    end\n"
"\n"
"    return setmetatable (proxy, proxy_mt)\n"
"end\n"
"\n"
"local function TableProxy (T, impl, expose)\n"
"    expose = expose or false\n"
"    impl = impl or {}\n"
"\n"
"    local atts = getmetatable(T).__atts or false\n"
"    local fallback = expose and impl or T\n"
"\n"
"    return setmetatable ({}, {\n"
"        __impl  = impl or {},\n"
"        __index = atts and function (obj, k)\n"
"            local p = atts [k]\n"
"            if p and p.get then\n"
"                return p.get (obj)\n"
"            else\n"
"                return fallback[k]\n"
"            end\n"
"        end\n"
"        or fallback,\n"
"\n"
"        __newindex = atts and function (obj, k, v)\n"
"            local p = atts [k]\n"
"            if p and p.set then\n"
"                p.set (obj, v)\n"
"            else\n"
"                rawset (obj, k, v)\n"
"            end\n"
"        end\n"
"        or fallback\n"
"    })\n"
"end\n"
"\n"
"local function instantiate (T, ...)\n"
"    local newuserdata, U = lookupmeta (T, '__newuserdata')\n"
"    \n"
"    local proxy = {}\n"
"    if type(newuserdata) == 'function' and\n"
"       type(U) == 'table'\n"
"    then\n"
"        local obj = newuserdata()\n"
"        proxy = UserDataProxy (T, U, obj)\n"
"    else\n"
"        proxy = TableProxy (T, {})\n"
"    end\n"
"\n"
"    if 'function' == type (T['init']) then\n"
"        T.init (proxy, ...)\n"
"    end\n"
"\n"
"    return proxy\n"
"end\n"
"\n"
"local function define_type (...)\n"
"    local nargs = select (\"#\", ...)\n"
"    local B = {}\n"
"    local D = {}\n"
"    local atts = {}\n"
"\n"
"    if nargs == 0 then\n"
"        atts = {}\n"
"\n"
"    elseif nargs == 1 and 'table' == type (select (1, ...)) then\n"
"        local param = select (1, ...)\n"
"        if getmetatable(param) then\n"
"            B = param\n"
"            if getmetatable(B).__atts then\n"
"                for k,v in pairs (getmetatable(B).__atts) do\n"
"                    atts[k] = v\n"
"                end\n"
"            end\n"
"        else\n"
"            atts = param\n"
"        end\n"
"\n"
"    elseif nargs > 1 then\n"
"        B = select (1, ...)\n"
"        if getmetatable(B).__atts then\n"
"            for k,v in pairs (getmetatable(B).__atts) do\n"
"                atts[k] = v\n"
"            end\n"
"        end\n"
"        for k,v in pairs (select (2, ...)) do\n"
"            atts[k] = v\n"
"        end\n"
"    end\n"
"    \n"
"    local result, err = pcall (function()\n"
"        for k, v in pairs (B) do\n"
"            D[k] = v \n"
"        end\n"
"    end)\n"
"    \n"
"    return setmetatable (D, {\n"
"        __atts  = atts,\n"
"        __base  = B\n"
"    })\n"
"end\n"
"\n"
"--- Define a new object type.\n"
"-- Call when you need to define a custom object. You can also invoke the module\n"
"-- directly, which is an alias to `define`.\n"
"-- @class function\n"
"-- @name object.define\n"
"-- @param base\n"
"-- @treturn table The new object type table\n"
"-- @usage\n"
"-- local object = require ('el.object')\n"
"-- -- Verbose method\n"
"-- local Animal = object.define()\n"
"-- -- Calling the module\n"
"-- local Cat = object (Animal)\n"
"M.define = define_type\n"
"\n"
"--- Create a new instance of type `T`.\n"
"-- @tparam table T The object type to create\n"
"-- @tparam any ... Arguments passed to `T:init`\n"
"-- @treturn table The newly created object\n"
"function M.new (T, ...)\n"
"    if type(T) == 'string' then\n"
"        T = require (T)\n"
"    end\n"
"    return instantiate (T, ...)\n"
"end\n"
"\n"
"--- Reference some userdata.\n"
"-- Only call this on userdata allocated outside of lua.\n"
"-- @tparam table T The type of userdata\n"
"-- @tparam userdata obj Instance allocated in C/C++\n"
"-- @bool init Set false to skip calling T.init (default true)\n"
"-- @return table Proxy object for `obj` \n"
"function M.ref (T, obj, init)\n"
"    init = init ~= nil and init or true\n"
"    if type (T)   ~= 'table'    then error (\"param #1 is not a table\") end\n"
"    if type (obj) ~= 'userdata' then error (\"param #2 is not userdata\") end\n"
"    return UserDataProxy (T, T, obj)\n"
"end\n"
"\n"
"setmetatable (M, {\n"
"    __call = function (O, ...)\n"
"        return define_type (...)\n"
"    end\n"
"})\n"
"\n"
"return M\n"
"\n"
"-- SPDX-FileCopyrightText: Copyright (C) Kushview, LLC.\n"
"-- SPDX-License-Identifier: GPL-3.0-or-later\n";

const char* object_lua = (const char*) temp_binary_data_3;
}
