Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • #16
    Update: I realized that I need to make the code erase old mlib's before creating the new one. Otherwise, the new one can be saved into a different folder from the new one, and the user can end up with two, one possibly out of date. The new version is:
    Code:
    mata st_local("mlibversion", boottestCompileVersion())
        if `mlibversion' != c(stata_version) {
            findfile "lboottest.mlib"
            while !_rc {
                erase "`r(fn)'"
                cap findfile "lboottest.mlib"
            }
            qui findfile "boottest.mata"
            run "`fn'"
        }
    This does however require write access to the directory where the old mlibs are stored...

    Comment


    • #17
      Whoops. That's got bugs. Here's the latest, bestest:
      Code:
          mata st_local("mlibversion", boottestCompileVersion())
          if `mlibversion' != c(stata_version) {
              cap findfile "lboottest.mlib"
              while !_rc {
                  erase "`r(fn)'"
                  cap findfile "lboottest.mlib"
              }
              qui findfile "boottest.mata"
              run "`r(fn)'"
          }

      Comment


      • #18
        A quick bump to this thread to show how I addressed this issue, in case others find it useful:
        • I extend David's mymlibversion(123) trick, by instead running mymlibversion(`ado_version'), where the ado_version local was created by reading the first line of the corresponding ado file.
        • This means we don't have to distribute mlib files at all (which get compiled on the fly by the user), and can instead just share the .mata file
        • It also means we can use locals in the .mata file for precompiling (!). So for instance, instead of selectindex(), my code uses `selectindex`() where the value of the local is decided at the top of the mata file based on the Stata version.
        The two key files (the one that reads the version line and the one that compiles the mlib) are part of the ftools package, but don't have any dependencies so they can be run separately.

        I also wrote a toy package that shows how to use this trick:

        https://github.com/sergiocorreia/stata-foobar

        (Check the .ado and .mata files for a complete example)

        Cheers,
        Sergio

        Comment

        Working...
        X