From 38c563dfd6d543f18da3b7b77c80cbb9c3c6bbc5 Mon Sep 17 00:00:00 2001 From: ac-stef Date: Sat, 13 Jun 2015 22:16:52 +0200 Subject: [PATCH] add command getvarrange getvarrange Gets range attribute for builtin variable . what one of "min", "max" or "default" varname name of any builtin variable (integer or float) DOCREF getvarrange --- config/scripts.cfg | 1 + source/src/command.cpp | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/config/scripts.cfg b/config/scripts.cfg index 1806a16a..cffab358 100644 --- a/config/scripts.cfg +++ b/config/scripts.cfg @@ -83,6 +83,7 @@ looplist [ edittexturestack texturestacktypes ] [ cmd options ] [ listcomplete $cmd (listoptions $options) ] +listcomplete getvarrange "min max default" // set up list of skymaps push skies "" diff --git a/source/src/command.cpp b/source/src/command.cpp index d68bc4d9..010a5f77 100644 --- a/source/src/command.cpp +++ b/source/src/command.cpp @@ -364,6 +364,30 @@ void _getalias(char *name) } COMMANDN(getalias, _getalias, "s"); +void getvarrange(char *_what, char *name) +{ + ident *id = idents->access(name); + const char *attrs[] = { "min", "max", "default", "" }; + int what = getlistindex(_what, attrs, false, -1); + if(id) + { + int *i = NULL; + switch(what) + { + case 0: i = &(id->minval); break; + case 1: i = &(id->maxval); break; + case 2: i = &(id->defaultval); break; + } + if(i) switch(id->type) + { + case ID_VAR: intret(*i); return; + case ID_FVAR: floatret(*((float *) i), true); return; + } + } + result(""); +} +COMMAND(getvarrange, "ss"); + COMMANDF(isIdent, "s", (char *name) { intret(identexists(name) ? 1 : 0); }); bool addcommand(const char *name, void (*fun)(), const char *sig)