52 Idf_Overridden = 1<<4,
77 void setfloat(
float val);
78 void setnumber(
double val);
79 void setstr(
char *val);
81 void setcode(
const uint *val);
82 void setmacro(
const uint *val);
83 void setcstr(
const char *val);
84 void setident(
ident *val);
86 const char *getstr()
const;
88 float getfloat()
const;
89 double getnumber()
const;
91 void getval(
tagval &r)
const;
103typedef void (__cdecl *identfun)(
ident *id);
151 identval overrideval;
171 ident(
int t,
const char *n,
int m,
int x,
int *s,
void *f =
nullptr,
int flags = 0)
172 :
type(t), flags(flags | (m > x ? Idf_ReadOnly : 0)), name(n),
fun(reinterpret_cast<identfun>(f))
182 ident(
int t,
const char *n,
float m,
float x,
float *s,
void *f =
nullptr,
int flags = 0)
183 :
type(t), flags(flags | (m > x ? Idf_ReadOnly : 0)), name(n),
fun(reinterpret_cast<identfun>(f))
193 ident(
int t,
const char *n,
char **s,
void *f =
nullptr,
int flags = 0)
194 :
type(t), flags(flags), name(n),
fun(reinterpret_cast<identfun>(f))
200 ident(
int t,
const char *n,
char *a,
int flags)
201 :
type(t),
valtype(Value_String), flags(flags), name(n)
203 alias.code =
nullptr;
204 alias.stack =
nullptr;
208 ident(
int t,
const char *n,
int a,
int flags)
209 :
type(t),
valtype(Value_Integer), flags(flags), name(n)
211 alias.code =
nullptr;
212 alias.stack =
nullptr;
216 ident(
int t,
const char *n,
float a,
int flags)
217 :
type(t),
valtype(Value_Float), flags(flags), name(n)
219 alias.code =
nullptr;
220 alias.stack =
nullptr;
224 ident(
int t,
const char *n,
int flags)
225 :
type(t),
valtype(Value_Null), flags(flags), name(n)
227 alias.code =
nullptr;
228 alias.stack =
nullptr;
231 ident(
int t,
const char *n,
const tagval &v,
int flags)
234 alias.code =
nullptr;
235 alias.stack =
nullptr;
242 ident(
int t,
const char *n,
const char *args, uint argmask,
int numargs,
void *f =
nullptr,
int flags = 0)
246 cmd.argmask = argmask;
300 delete[] alias.val.s;
329 const char *getstr()
const;
330 void getval(
tagval &r)
const;
331 void getcstr(
tagval &v)
const;
332 void getcval(
tagval &v)
const;
399 return static_cast<int>(std::strtoul(s,
nullptr, 0));
415extern int variable(
const char *name,
int min,
int cur,
int max,
int *storage, identfun fun,
int flags);
433extern float fvariable(
const char *name,
float min,
float cur,
float max,
float *storage, identfun fun,
int flags);
446extern char *
svariable(
const char *name,
const char *cur,
char **storage, identfun fun,
int flags);
456extern void setvar(
const char *name,
int i,
bool dofunc =
true,
bool doclamp =
true);
466extern void setfvar(
const char *name,
float f,
bool dofunc =
true,
bool doclamp =
true);
475extern void setsvar(
const char *name,
const char *str,
bool dofunc =
true);
488extern bool addcommand(
const char *name, identfun fun,
const char *narg =
"",
int type = Id_Command);
500extern int execute(
const uint *code);
511extern int execute(
const char *p);
523extern int execident(
const char *name,
int noid = 0,
bool lookup =
false);
524extern bool executebool(
const uint *code);
535extern bool execfile(
const char *cfgfile,
bool msg =
true);
573extern int clampvar(
bool hex, std::string name,
int i,
int minval,
int maxval);
597extern void writecfg(
const char *savedconfig,
const char *autoexec =
nullptr,
const char *defaultconfig =
nullptr,
const char *name =
nullptr);
670#define VAR_(name, global, min, cur, max, persist) int global = variable(#name, min, cur, max, &global, nullptr, persist)
671#define VARN(name, global, min, cur, max) VAR_(name, global, min, cur, max, 0)
672#define VARNP(name, global, min, cur, max) VAR_(name, global, min, cur, max, Idf_Persist)
673#define VARNR(name, global, min, cur, max) VAR_(name, global, min, cur, max, Idf_Override)
674#define VAR(name, min, cur, max) VAR_(name, name, min, cur, max, 0)
675#define VARP(name, min, cur, max) VAR_(name, name, min, cur, max, Idf_Persist)
676#define VARR(name, min, cur, max) VAR_(name, name, min, cur, max, Idf_Override)
679#define VARF_(name, global, min, cur, max, body, persist) \
680 int global = variable(#name, min, cur, max, &global, [] (ident *) { body; }, persist);
682#define VARFN(name, global, min, cur, max, body) VARF_(name, global, min, cur, max, body, 0)
683#define VARF(name, min, cur, max, body) VARF_(name, name, min, cur, max, body, 0)
684#define VARFP(name, min, cur, max, body) VARF_(name, name, min, cur, max, body, Idf_Persist)
685#define VARFR(name, min, cur, max, body) VARF_(name, name, min, cur, max, body, Idf_Override)
686#define VARFNP(name, global, min, cur, max, body) VARF_(name, global, min, cur, max, body, Idf_Persist)
689#define HVAR_(name, global, min, cur, max, persist) int global = variable(#name, min, cur, max, &global, nullptr, persist | Idf_Hex)
690#define HVARP(name, min, cur, max) HVAR_(name, name, min, cur, max, Idf_Persist)
694#define HVARF_(name, global, min, cur, max, body, persist) \
695 int global = variable(#name, min, cur, max, &global, [] (ident *) { body; }, persist | Idf_Hex);
698#define CVAR_(name, cur, init, body, persist) bvec name = bvec::hexcolor(cur); HVARF_(name, _##name, 0, cur, 0xFFFFFF, { init; name = bvec::hexcolor(_##name); body; }, persist)
699#define CVARP(name, cur) CVAR_(name, cur, , , Idf_Persist)
700#define CVARR(name, cur) CVAR_(name, cur, , , Idf_Override)
701#define CVARFP(name, cur, body) CVAR_(name, cur, , body, Idf_Persist)
702#define CVAR0_(name, cur, body, persist) CVAR_(name, cur, { if(!_##name) _##name = cur; }, body, persist)
703#define CVAR0R(name, cur) CVAR0_(name, cur, , Idf_Override)
704#define CVAR1_(name, cur, body, persist) CVAR_(name, cur, { if(_##name <= 255) _##name |= (_##name<<8) | (_##name<<16); }, body, persist)
705#define CVAR1R(name, cur) CVAR1_(name, cur, , Idf_Override)
706#define CVAR1FR(name, cur, body) CVAR1_(name, cur, body, Idf_Override)
709#define FVAR_(name, global, min, cur, max, persist) float global = fvariable(#name, min, cur, max, &global, nullptr, persist)
710#define FVARNP(name, global, min, cur, max) FVAR_(name, global, min, cur, max, Idf_Persist)
711#define FVAR(name, min, cur, max) FVAR_(name, name, min, cur, max, 0)
712#define FVARP(name, min, cur, max) FVAR_(name, name, min, cur, max, Idf_Persist)
713#define FVARR(name, min, cur, max) FVAR_(name, name, min, cur, max, Idf_Override)
716#define FVARF_(name, global, min, cur, max, body, persist) \
717 float global = fvariable(#name, min, cur, max, &global, [] (ident *) { body; }, persist); \
719#define FVARF(name, min, cur, max, body) FVARF_(name, name, min, cur, max, body, 0)
720#define FVARFP(name, min, cur, max, body) FVARF_(name, name, min, cur, max, body, Idf_Persist)
721#define FVARFR(name, min, cur, max, body) FVARF_(name, name, min, cur, max, body, Idf_Override)
724#define SVAR_(name, global, cur, persist) char *global = svariable(#name, cur, &global, nullptr, persist)
725#define SVAR(name, cur) SVAR_(name, name, cur, 0)
726#define SVARP(name, cur) SVAR_(name, name, cur, Idf_Persist)
727#define SVARR(name, cur) SVAR_(name, name, cur, Idf_Override)
730#define SVARF_(name, global, cur, body, persist) \
731 char *global = svariable(#name, cur, &global, [] (ident *) { body; }, persist);
733#define SVARF(name, cur, body) SVARF_(name, name, cur, body, 0)
734#define SVARFR(name, cur, body) SVARF_(name, name, cur, body, Idf_Override)
void stringret(char *s)
Returns a string value from a Cubescript command.
void result(const char *s)
Returns an alias' name from a Cubescript command.
const char * floatstr(float v)
Writes the passed float to a formatted string.
const char * escapestring(const char *s)
Replaces C style excape characters with Cubescript ones.
void intret(int v)
Returns an integer value from a Cubescript command.
int variable(const char *name, int min, int cur, int max, int *storage, identfun fun, int flags)
Registers an int variable in the Cubescript ident table.
const char * escapeid(const char *s)
Escapes a string unless it is null.
void floatret(float v)
Returns a float value from a Cubescript command.
void setfvar(const char *name, float f, bool dofunc=true, bool doclamp=true)
Sets a Cubescript float value to the given value.
void setsvar(const char *name, const char *str, bool dofunc=true)
Sets a Cubescript string value to the given value.
void setvar(const char *name, int i, bool dofunc=true, bool doclamp=true)
Sets a Cubescript integer value to the given value.
bool execfile(const char *cfgfile, bool msg=true)
Executes the contents of the referenced file.
int parseint(const char *s)
Returns the string passed as an integer.
Definition command.h:397
bool initidents()
Initializes the CubeScript preset argument idents.
bool addcommand(const char *name, identfun fun, const char *narg="", int type=Id_Command)
Registers a command in the Cubescript ident table.
int clampvar(bool hex, std::string name, int i, int minval, int maxval)
Modifies the value passed to fall within the boundaries passed.
int execident(const char *name, int noid=0, bool lookup=false)
Executes the contents of an ident, searched by name.
void printvar(const ident *id, int i)
Prints out the formatted variable.
void writecfg(const char *savedconfig, const char *autoexec=nullptr, const char *defaultconfig=nullptr, const char *name=nullptr)
Writes out the state of the CubeScript idents to a file.
void clear_command()
Clears all aliases from the ident map.
char * svariable(const char *name, const char *cur, char **storage, identfun fun, int flags)
Registers a C string variable in the Cubescript ident table.
float fvariable(const char *name, float min, float cur, float max, float *storage, identfun fun, int flags)
Registers a float variable in the Cubescript ident table.
ident * getident(const char *name)
Returns the pointer to the ident object with the given CS alias.
void checksleep(int millis)
Processes the cubescript sleep queue.
std::queue< ident * > triggerqueue
An object representing all Cubescript objects.
Definition command.h:114
double getnumber() const
Returns the saved value of the ident as a double.
int min
Definition command.h:141
ident(int t, const char *n, char **s, void *f=nullptr, int flags=0)
Constructor for an ident for a string variable.
Definition command.h:193
void forcenull()
Sets the value type of this ident to null.
Definition command.h:296
void changed()
Calls a change effect for this ident, if one exists.
Definition command.h:255
int max
Definition command.h:142
void setval(const identstack &v)
Sets the value and type of value of this ident given an identstack.
Definition command.h:285
float getfloat() const
Returns the saved value of the ident as a float.
uchar valtype
Definition command.h:127
uchar numargs
Definition command.h:128
ident(int t, const char *n, int m, int x, int *s, void *f=nullptr, int flags=0)
Constructor for an ident for an int variable.
Definition command.h:171
int getint() const
Returns the saved value of the ident as an integer.
uchar type
Definition command.h:124
ident(int t, const char *n, const char *args, uint argmask, int numargs, void *f=nullptr, int flags=0)
Constructor for an ident for a C++ bound command.
Definition command.h:242
identfun fun
Definition command.h:165
void setval(const tagval &v)
Sets the value and type of value of this ident given a tagval.
Definition command.h:271
ident(int t, const char *n, float m, float x, float *s, void *f=nullptr, int flags=0)
Constructor for an ident for a float variable.
Definition command.h:182
char ** s
Definition command.h:121
int * i
Definition command.h:119
float * f
Definition command.h:120
void * p
Definition command.h:118