1
0
Fork 0

Add ‘makesingleshot’ helper to Nasal.

Makes a timer object, but set to single shot mode and starts it.
This commit is contained in:
James Turner 2020-06-01 11:16:37 +01:00
parent 26b0148747
commit 9cc9a8a197

View file

@ -590,6 +590,28 @@ static naRef f_makeTimer(naContext c, naRef me, int argc, naRef* args)
return nasal::to_nasal(c, timerObj); return nasal::to_nasal(c, timerObj);
} }
static naRef f_makeSingleShot(naContext c, naRef me, int argc, naRef* args)
{
if (!naIsNum(args[0])) {
naRuntimeError(c, "bad interval argument to makesingleshot");
}
naRef func, self = naNil();
if (naIsFunc(args[1])) {
func = args[1];
} else if ((argc == 3) && naIsFunc(args[2])) {
self = args[1];
func = args[2];
} else {
naRuntimeError(c, "bad function/self arguments to makesingleshot");
}
auto timerObj = new TimerObj(c, nasalSys, func, self, args[0].num);
timerObj->setSingleShot(true);
timerObj->start();
return nasal::to_nasal(c, timerObj);
}
static naRef f_maketimeStamp(naContext c, naRef me, int argc, naRef* args) static naRef f_maketimeStamp(naContext c, naRef me, int argc, naRef* args)
{ {
TimeStampObj* timeStampObj = new TimeStampObj(c); TimeStampObj* timeStampObj = new TimeStampObj(c);
@ -946,33 +968,34 @@ static naRef f_systime(naContext c, naRef me, int argc, naRef* args)
} }
// 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;
{ "getprop", f_getprop }, } funcs[] = {
{ "setprop", f_setprop }, {"getprop", f_getprop},
{ "print", f_print }, {"setprop", f_setprop},
{ "logprint", f_logprint }, {"print", f_print},
{ "_fgcommand", f_fgcommand }, {"logprint", f_logprint},
{ "settimer", f_settimer }, {"_fgcommand", f_fgcommand},
{ "maketimer", f_makeTimer }, {"settimer", f_settimer},
{ "_setlistener", f_setlistener }, {"maketimer", f_makeTimer},
{ "removelistener", f_removelistener }, {"makesingleshot", f_makeSingleShot},
{ "addcommand", f_addCommand }, {"_setlistener", f_setlistener},
{ "removecommand", f_removeCommand }, {"removelistener", f_removelistener},
{ "_cmdarg", f_cmdarg }, {"addcommand", f_addCommand},
{ "_interpolate", f_interpolate }, {"removecommand", f_removeCommand},
{ "rand", f_rand }, {"_cmdarg", f_cmdarg},
{ "srand", f_srand }, {"_interpolate", f_interpolate},
{ "abort", f_abort }, {"rand", f_rand},
{ "directory", f_directory }, {"srand", f_srand},
{ "resolvepath", f_resolveDataPath }, {"abort", f_abort},
{ "finddata", f_findDataDir }, {"directory", f_directory},
{ "parsexml", f_parsexml }, {"resolvepath", f_resolveDataPath},
{ "parse_markdown", f_parse_markdown }, {"finddata", f_findDataDir},
{ "md5", f_md5 }, {"parsexml", f_parsexml},
{ "systime", f_systime }, {"parse_markdown", f_parse_markdown},
{ "maketimestamp", f_maketimeStamp}, {"md5", f_md5},
{ 0, 0 } {"systime", f_systime},
}; {"maketimestamp", f_maketimeStamp},
{0, 0}};
naRef FGNasalSys::cmdArgGhost() naRef FGNasalSys::cmdArgGhost()
{ {