JanetDocsSourcePlaygroundI'm feeling luckyCommunityGitHub sign in
# To make "stub functions" in an image, solving c interop problems like this: # I hoped that I would be able to unmarshal the runtime.jimage, load my C functions, # and Janet would use my app's functions instead of the stubs. However, during # compilation, Janet seems to precompile all the top-level function calls. This # means hotswapping the functions does nothing, and the Janet code continues to # use the stubs instead. # # I was hoping that there would be some way of telling Janet "don't precompile # this please", either a (defstubn ...) or the ability to do # (defn internal/redraw-ui [opts] (dyn)), where (dyn) is some abstract type that # Janet can't precompute directly. # https://github.com/janet-lang/janet/issues/1642 # pretend this is the stub function we want to replace (defn greet [] (print "hello world")) # make-image-dict determines which values will be filled in at # "deserialization" time (put make-image-dict greet 'greet) (def pretend-env @{ 'some-function (fn [] (greet) (greet))}) (def compiled (make-image pretend-env)) # notice: the string "hello world" does not appear in the compiled result (pp compiled) # if we just try to (load-image compiled) at this point, it will raise, # because we haven't specified what to do about 'greet # we have to make an entry in the load-image-dict. note that # it does not have to be the same value! (put load-image-dict 'greet (fn [] (print "something else!"))) # now we can call load-image (def pretend-env-reparsed (load-image compiled)) # and when we run this, we will see the replacement that we gave ((pretend-env-reparsed 'some-function))