Add ‘makesingleshot’ helper to Nasal.
Makes a timer object, but set to single shot mode and starts it.
This commit is contained in:
parent
26b0148747
commit
9cc9a8a197
1 changed files with 50 additions and 27 deletions
|
@ -590,6 +590,28 @@ static naRef f_makeTimer(naContext c, naRef me, int argc, naRef* args)
|
|||
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)
|
||||
{
|
||||
TimeStampObj* timeStampObj = new TimeStampObj(c);
|
||||
|
@ -946,7 +968,8 @@ static naRef f_systime(naContext c, naRef me, int argc, naRef* args)
|
|||
}
|
||||
|
||||
// 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},
|
||||
{"setprop", f_setprop},
|
||||
{"print", f_print},
|
||||
|
@ -954,6 +977,7 @@ static struct { const char* name; naCFunction func; } funcs[] = {
|
|||
{"_fgcommand", f_fgcommand},
|
||||
{"settimer", f_settimer},
|
||||
{"maketimer", f_makeTimer},
|
||||
{"makesingleshot", f_makeSingleShot},
|
||||
{"_setlistener", f_setlistener},
|
||||
{"removelistener", f_removelistener},
|
||||
{"addcommand", f_addCommand},
|
||||
|
@ -971,8 +995,7 @@ static struct { const char* name; naCFunction func; } funcs[] = {
|
|||
{"md5", f_md5},
|
||||
{"systime", f_systime},
|
||||
{"maketimestamp", f_maketimeStamp},
|
||||
{ 0, 0 }
|
||||
};
|
||||
{0, 0}};
|
||||
|
||||
naRef FGNasalSys::cmdArgGhost()
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue