📄 mata_mosave.hlp
字号:
{smcl}
{* 31mar2005}{...}
{cmd:help mata mosave}
{hline}
{* index mata tt}{...}
{* index mosave tt}{...}
{* index .mo file}{...}
{title:Title}
{p 4 4 2}
{bf:[M-3] mata mosave -- Save function's compiled code in object file}
{title:Syntax}
{p 8 16 2}
: {cmd:mata} {cmd:mosave}
{it:fcname}{cmd:()}
[{cmd:,}
{cmd:dir(}{it:path}{cmd:)}
{cmd:replace}
]
{p 4 4 2}
This command is for use in Mata mode following Mata's colon prompt.
To use this command from Stata's dot prompt, type
. {cmd:mata: mata mosave} ...
{title:Description}
{p 4 4 2}
{cmd:mata} {cmd:mosave} saves the object code for the specified
function in the file {it:fcnname}{cmd:.mo}.
{title:Options}
{p 4 8 2}
{cmd:dir(}{it:path}{it:)} specifies the directory (folder) into which the file
should be written. {cmd:dir(.)} is the default, meaning that
if {cmd:dir()} is not specified, the file is written
into the current (working) directory. {it:path} may be a directory name
or may be the sysdir shorthand {cmd:STATA}, {cmd:UPDATES}, {cmd:BASE},
{cmd:SITE} {cmd:PLUS}, {cmd:PERSONAL}, or {cmd:OLDPLACE}; see
{bf:{help sysdir:[P] sysdir}}.
{cmd:dir(PERSONAL)} is recommended.
{p 4 8 2}
{cmd:replace} specifies that the file may be replaced if it already exists.
{title:Remarks}
{p 4 4 2}
See {bf:{help m1_how:[M-1] how -- How Mata works}} for an explanation of
object code.
{p 4 4 2}
Remarks are presented under the headings
{bf:Example of use}
{bf:Where to store .mo files}
{bf:Use of .mo files versus .mlib files}
{title:Example of use}
{p 4 4 2}
{cmd:.mo} files contain the object code for a single function. If you store a
function's object code in an {cmd:.mo} file, then in future Mata sessions, you
can use the function without recompiling the source. The function will
appear to become a part of Mata just as all the other functions documented in
this manual are. The function can be used because the object code will be
automatically found and loaded when needed.
{p 4 4 2}
For example,
: {cmd:function add(a,b) return(a+b)}
: {cmd:add(1,2)}
3
: {cmd:mata mosave add()}
(file add.mo created)
: {cmd:mata clear}
: {cmd:add(1,2)}
3
{p 4 4 2}
In the example above, function {cmd:add()} was saved in file {cmd:add.mo}
stored in the current directory. After clearing Mata, we could still use the
function because Mata found the stored object code.
{title:Where to store .mo files}
{p 4 4 2}
Mata could find {cmd:add()} because file {cmd:add.mo} was in the current
directory, and our adopath included {cmd:.}:
. {cmd:adopath}
{txt} [1] (UPDATES) "{res}C:\stata\ado\updates\{txt}"
[2] (BASE) "{res}C:\stata\ado\base\{txt}"
[3] (SITE) "{res}C:\stata\ado\site\{txt}"
[4] "{res}.{txt}"
[5] (PERSONAL) "{res}C:\ado\personal\{txt}"
[6] (PLUS) "{res}C:\ado\sjplus\{txt}"
[7] (OLDPLACE) "{res}C:\ado\{txt}"
{p 4 4 2}
If later we were to change our current directory,
. {cmd:cd ..\otherdir}
{p 4 4 2}
Mata would no longer be able to find the file {cmd:add.mo}. Thus
the best place to store your personal {cmd:.mo} files is in your
{cmd:PERSONAL} directory. Thus rather than typing
: {cmd:mata mosave example()}
{p 4 4 2}
we would have been better off typing
: {cmd:mata mosave example(), dir(PERSONAL)}
{title:Use of .mo files versus .mlib files}
{p 4 4 2}
Use of .mo files is heartily recommended. The alternative for saving
compiled object code are .mlib libraries; see
{bf:{help mata_mlib:[M-3] mata mlib}}
and
{bf:{help m1_ado:[M-1] ado}}.
{p 4 4 2}
Libraries are useful when you have lots of functions and want to tie them
together into a single file, especially if you want to share those functions
with others, because then you have only a single file to distribute. The
disadvantage of libraries is that you must rebuild them whenever you wish to
remove or change the code of a single function. If you have only a few object
files, or if you have lots but sharing is not an issue, .mo libraries are
easier to manage.
{title:Also see}
{p 4 13 2}
Manual: {hi:[M-3] mata mosave}
{p 4 13 2}
Online: help for
{bf:{help mata_mlib:[M-3] mata mlib}};
{bf:{help m3_intro:[M-3] intro}}
{p_end}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -