if not modules then modules = { } end modules ['math-ext'] = {
    version   = 1.001,
    comment   = "companion to math-ini.mkiv",
    author    = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
    copyright = "PRAGMA ADE / ConTeXt Development Team",
    license   = "see context related readme files"
}

-- This is a completely different file from the lua one but the name fits.

-- We actually have a mechanism for this but it has never been used so let's go
-- simple till we have that active again. This kind of trickery only works in
-- controlled situations anyway.

----- texnest     = tex.nest
----- setproperty = nodes.nuts.setprop
local getproperty = nodes.nuts.getprop

local extensibles = { }

function mathematics.registerextensible(specification)
    local unicode = specification.unicode
    if unicode then
        extensibles[unicode] = specification
    end
end

-- function mathematics.setextensibledata(data)
--     local target = texnest[texnest.ptr].tail
--     if target then -- maybe also check type
--         setproperty(target,data)
--     end
-- end

function mathematics.setextensibledata(data)
    context(nodes.upcomingproperties { extensible = data })
end

function mathematics.getextensibledata(target)
    local property = getproperty(target)
    return property and property.extensible
end

local function make_extensible_callback(target,fnt,chr,size,width,height,depth,linewidth,axis,exheight,emwidth)
    local found = extensibles[chr]
    if found then
        local action = found.action
        if action then
            return action(target,fnt,chr,size,width,height,depth,linewidth,axis,exheight,emwidth)
        end
    end
end

callbacks.register {
    name    = "make_extensible",
    action  = make_extensible_callback,
    comment = "construct an extensible glyph",
    frozen  = true,
}

if not nodes.setattrlist then

    local tonut       = nodes.tonut
    local setattrlist = nodes.nuts.setattrlist

    function nodes.setattrlist(target,source)
        setattrlist(tonut(target),tonut(source))
    end

end
