Howto:Extend Nasal: Difference between revisions

m
Line 48: Line 48:


== Intro ==
== Intro ==
In FlightGear, the simplest way to add new extension functions is to look at the existing functions at {{flightgear file|src/Scripting/NasalSys.cxx|l=747}}.
In FlightGear, the simplest way to add new extension functions is to look at the existing functions at {{flightgear file|src/Scripting/NasalSys.cxx|l=774}}.


There is a static table of function pointers (named funcs[]) referencing extension functions, along with their corresponding names in Nasal: {{flightgear file|src/Scripting/NasalSys.cxx|l=482}}.
There is a static table of function pointers (named funcs[]) referencing extension functions, along with their corresponding names in Nasal: {{flightgear file|src/Scripting/NasalSys.cxx|l=482}}.
The following is a copy of the extension function list, taken in 12/2014:
The following is a copy of the extension function list, taken in 11/2015:


<syntaxhighlight lang="cpp">
<syntaxhighlight lang="cpp">
  // Table of extension functions. Terminate with zeros.
// Table of extension functions. Terminate with zeros.
static struct { const char* name; naCFunction func; } funcs[] = {
static struct { const char* name; naCFunction func; } funcs[] = {
  { "getprop", f_getprop },
    { "getprop",   f_getprop },
  { "setprop", f_setprop },
    { "setprop",   f_setprop },
  { "print", f_print },
    { "print",     f_print },
  { "logprint", f_logprint },
    { "logprint", f_logprint },
  { "_fgcommand", f_fgcommand },
    { "_fgcommand", f_fgcommand },
  { "settimer", f_settimer },
    { "settimer", f_settimer },
  { "maketimer", f_makeTimer },
    { "maketimer", f_makeTimer },
  { "_setlistener", f_setlistener },
    { "_setlistener", f_setlistener },
  { "removelistener", f_removelistener },
    { "removelistener", f_removelistener },
  { "addcommand", f_addCommand },
    { "addcommand", f_addCommand },
  { "removecommand", f_removeCommand },
    { "removecommand", f_removeCommand },
  { "_cmdarg", f_cmdarg },
    { "_cmdarg", f_cmdarg },
  { "_interpolate", f_interpolate },
    { "_interpolate", f_interpolate },
  { "rand", f_rand },
    { "rand", f_rand },
  { "srand", f_srand },
    { "srand", f_srand },
  { "abort", f_abort },
    { "abort", f_abort },
  { "directory", f_directory },
    { "directory", f_directory },
  { "resolvepath", f_resolveDataPath },
    { "resolvepath", f_resolveDataPath },
  { "finddata", f_findDataDir },
    { "finddata", f_findDataDir },
  { "parsexml", f_parsexml },
    { "parsexml", f_parsexml },
  { "parse_markdown", f_parse_markdown },
    { "parse_markdown", f_parse_markdown },
  { "md5", f_md5 },
    { "md5", f_md5 },
  { "systime", f_systime },
    { "systime", f_systime },
  { 0, 0 }
    { 0, 0 }
};
};
</syntaxhighlight>
</syntaxhighlight>