Overwriting Functions from another package in your package

I’m implementing a feature for Javis . Javis is an animation library . To draw every frame it uses
Luxor . Now for this feature to be implemented I need to change the behaviour of a few functions
in Javis. I am overwriting them in Javis .

But I get warnings when using Javis that the functions are overwritten and incremental compilation
may be broken .

For example a function in particular is

which does

function strokepath()
    <call some cairo functions >

what I do in Javis is

function Luxor.strokepath()
        <some code using Javis.global_var and Javis functions>
         <call some cairo functions>

So two questions .

  1. This amounts to type piracy , is there a way to implement something like this without type piracy altogether.
    2)When using Javis I get warnings about the luxor functions being overwritten in Javis and incremental compilation may be fatally broken for this module . How bad is this ?

Why can’t you just have a Javis.strokepath that does:

function strokepath()
    <some code using Javis.global_var and Javis functions>



there are many functions from Luxor that are exported by Javis.

Take line for example which is used to draw a line .

line( O , O +(100,100) , :stroke ) would be one example of how a Javis user would draw a line
this line is defined in Luxor which eventually calls strokepath() to lay down the line on the canvas.
There are many such functions in Luxor to draw various things.

What I want to do is change the behavior of that strokepath() which gets eventually called inside all these drawing functions that Luxor provides.

To give you a little more perspective (if it helps , else ignore this) , my initial attempt was to use Cassette.jl to intercept the calls and replace with my own code, but me (and some of the devs ) think its too hacky and we dont want to have Cassette.jl as a dep just for this feature.

1 Like

There is no way to directly monkey patch functions like this in a good way if the function itself does not provide the flexibility to do so in the first place. One possibility is to suggest some API in Luxor to be able to have enough flexibility to add the extra stuff you need.