Libprimis
Imprimis' 3D destroyable world engine
Loading...
Searching...
No Matches
command.h File Reference

Script binding functionality. More...

Go to the source code of this file.

Classes

struct  identval
 
struct  tagval
 
struct  identstack
 
struct  ident
 An object representing all Cubescript objects. More...
 
union  ident::identvalptr
 

Macros

#define VAR_(name, global, min, cur, max, persist)
 
#define VARN(name, global, min, cur, max)
 
#define VARNP(name, global, min, cur, max)
 
#define VARNR(name, global, min, cur, max)
 
#define VAR(name, min, cur, max)
 
#define VARP(name, min, cur, max)
 
#define VARR(name, min, cur, max)
 
#define VARF_(name, global, min, cur, max, body, persist)
 
#define VARFN(name, global, min, cur, max, body)
 
#define VARF(name, min, cur, max, body)
 
#define VARFP(name, min, cur, max, body)
 
#define VARFR(name, min, cur, max, body)
 
#define VARFNP(name, global, min, cur, max, body)
 
#define HVAR_(name, global, min, cur, max, persist)
 
#define HVARP(name, min, cur, max)
 
#define HVARF_(name, global, min, cur, max, body, persist)
 
#define CVAR_(name, cur, init, body, persist)
 
#define CVARP(name, cur)
 
#define CVARR(name, cur)
 
#define CVARFP(name, cur, body)
 
#define CVAR0_(name, cur, body, persist)
 
#define CVAR0R(name, cur)
 
#define CVAR1_(name, cur, body, persist)
 
#define CVAR1R(name, cur)
 
#define CVAR1FR(name, cur, body)
 
#define FVAR_(name, global, min, cur, max, persist)
 
#define FVARNP(name, global, min, cur, max)
 
#define FVAR(name, min, cur, max)
 
#define FVARP(name, min, cur, max)
 
#define FVARR(name, min, cur, max)
 
#define FVARF_(name, global, min, cur, max, body, persist)
 
#define FVARF(name, min, cur, max, body)
 
#define FVARFP(name, min, cur, max, body)
 
#define FVARFR(name, min, cur, max, body)
 
#define SVAR_(name, global, cur, persist)
 
#define SVAR(name, cur)
 
#define SVARP(name, cur)
 
#define SVARR(name, cur)
 
#define SVARF_(name, global, cur, body, persist)
 
#define SVARF(name, cur, body)
 
#define SVARFR(name, cur, body)
 

Typedefs

typedef void(__cdecl * identfun) (ident *id)
 

Enumerations

enum  {
  Value_Null = 0 , Value_Integer , Value_Float , Value_String ,
  Value_Any , Value_Code , Value_Macro , Value_Ident ,
  Value_CString , Value_CAny , Value_Word , Value_Pop ,
  Value_Cond
}
 
enum  {
  Id_Var , Id_FloatVar , Id_StringVar , Id_Command ,
  Id_Alias , Id_Local , Id_Do , Id_DoArgs ,
  Id_If , Id_Result , Id_Not , Id_And ,
  Id_Or
}
 
enum  {
  Idf_Persist = 1<<0 , Idf_Override = 1<<1 , Idf_Hex = 1<<2 , Idf_ReadOnly = 1<<3 ,
  Idf_Overridden = 1<<4 , Idf_Unknown = 1<<5 , Idf_Arg = 1<<6
}
 

Functions

void intret (int v)
 Returns an integer value from a Cubescript command.
 
const char * floatstr (float v)
 
void floatret (float v)
 Returns a float value from a Cubescript command.
 
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.
 
int parseint (const char *s)
 Returns the string passed as an integer.
 
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.
 
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.
 
char * svariable (const char *name, const char *cur, char **storage, identfun fun, int flags)
 Registers a C string variable in the Cubescript ident table.
 
void setvar (const char *name, int i, bool dofunc=true, bool doclamp=true)
 Sets a Cubescript integer value to the given value.
 
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.
 
bool addcommand (const char *name, identfun fun, const char *narg="", int type=Id_Command)
 Registers a command in the Cubescript ident table.
 
identgetident (const char *name)
 Returns the pointer to the ident object with the given CS alias.
 
int execute (const uint *code)
 
int execute (const char *p)
 Executes the contents of the string passed.
 
int execident (const char *name, int noid=0, bool lookup=false)
 Executes the contents of an ident, searched by name.
 
bool executebool (const uint *code)
 
bool execfile (const char *cfgfile, bool msg=true)
 Executes the contents of the referenced file.
 
const char * escapestring (const char *s)
 Replaces C style excape characters with Cubescript ones.
 
void printvar (const ident *id, int i)
 Prints out the formatted variable.
 
int clampvar (bool hex, std::string name, int i, int minval, int maxval)
 Modifies the value passed to fall within the boundaries passed.
 
void loopiter (ident *id, identstack &stack, int i)
 
void loopend (ident *id, identstack &stack)
 
const char * escapeid (const char *s)
 Escapes a string unless it is null.
 
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 checksleep (int millis)
 Processes the cubescript sleep queue.
 
bool initidents ()
 Initializes the CubeScript preset argument idents.
 
void clear_command ()
 Clears all aliases from the ident map.
 

Variables

std::queue< ident * > triggerqueue
 
int identflags
 

Detailed Description

Script binding functionality.

This file describes the CubeScript API for binding and executing code from within the engine's CubeScript context.

Macro Definition Documentation

◆ CVAR0_

#define CVAR0_ ( name,
cur,
body,
persist )
Value:
CVAR_(name, cur, { if(!_##name) _##name = cur; }, body, persist)

◆ CVAR0R

#define CVAR0R ( name,
cur )
Value:
CVAR0_(name, cur, , Idf_Override)

◆ CVAR1_

#define CVAR1_ ( name,
cur,
body,
persist )
Value:
CVAR_(name, cur, { if(_##name <= 255) _##name |= (_##name<<8) | (_##name<<16); }, body, persist)

◆ CVAR1FR

#define CVAR1FR ( name,
cur,
body )
Value:
CVAR1_(name, cur, body, Idf_Override)

◆ CVAR1R

#define CVAR1R ( name,
cur )
Value:
CVAR1_(name, cur, , Idf_Override)

◆ CVAR_

#define CVAR_ ( name,
cur,
init,
body,
persist )
Value:
bvec name = bvec::hexcolor(cur); HVARF_(name, _##name, 0, cur, 0xFFFFFF, { init; name = bvec::hexcolor(_##name); body; }, persist)
three dimensional Cartesian byte vector
Definition geom.h:637

◆ CVARFP

#define CVARFP ( name,
cur,
body )
Value:
CVAR_(name, cur, , body, Idf_Persist)

◆ CVARP

#define CVARP ( name,
cur )
Value:
CVAR_(name, cur, , , Idf_Persist)

◆ CVARR

#define CVARR ( name,
cur )
Value:
CVAR_(name, cur, , , Idf_Override)

◆ FVAR

#define FVAR ( name,
min,
cur,
max )
Value:
FVAR_(name, name, min, cur, max, 0)

◆ FVAR_

#define FVAR_ ( name,
global,
min,
cur,
max,
persist )
Value:
float global = fvariable(#name, min, cur, max, &global, nullptr, persist)
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.

◆ FVARF

#define FVARF ( name,
min,
cur,
max,
body )
Value:
FVARF_(name, name, min, cur, max, body, 0)

◆ FVARF_

#define FVARF_ ( name,
global,
min,
cur,
max,
body,
persist )
Value:
float global = fvariable(#name, min, cur, max, &global, [] (ident *) { body; }, persist); /* assign variable, needs fxn prototype declared above */ \
An object representing all Cubescript objects.
Definition command.h:114

◆ FVARFP

#define FVARFP ( name,
min,
cur,
max,
body )
Value:
FVARF_(name, name, min, cur, max, body, Idf_Persist)

◆ FVARFR

#define FVARFR ( name,
min,
cur,
max,
body )
Value:
FVARF_(name, name, min, cur, max, body, Idf_Override)

◆ FVARNP

#define FVARNP ( name,
global,
min,
cur,
max )
Value:
FVAR_(name, global, min, cur, max, Idf_Persist)

◆ FVARP

#define FVARP ( name,
min,
cur,
max )
Value:
FVAR_(name, name, min, cur, max, Idf_Persist)

◆ FVARR

#define FVARR ( name,
min,
cur,
max )
Value:
FVAR_(name, name, min, cur, max, Idf_Override)

◆ HVAR_

#define HVAR_ ( name,
global,
min,
cur,
max,
persist )
Value:
int global = variable(#name, min, cur, max, &global, nullptr, persist | Idf_Hex)
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.

◆ HVARF_

#define HVARF_ ( name,
global,
min,
cur,
max,
body,
persist )
Value:
int global = variable(#name, min, cur, max, &global, [] (ident *) { body; }, persist | Idf_Hex); /* assign variable, needs fxn prototype declared above */

◆ HVARP

#define HVARP ( name,
min,
cur,
max )
Value:
HVAR_(name, name, min, cur, max, Idf_Persist)

◆ SVAR

#define SVAR ( name,
cur )
Value:
SVAR_(name, name, cur, 0)

◆ SVAR_

#define SVAR_ ( name,
global,
cur,
persist )
Value:
char *global = svariable(#name, cur, &global, nullptr, persist)
char * svariable(const char *name, const char *cur, char **storage, identfun fun, int flags)
Registers a C string variable in the Cubescript ident table.

◆ SVARF

#define SVARF ( name,
cur,
body )
Value:
SVARF_(name, name, cur, body, 0)

◆ SVARF_

#define SVARF_ ( name,
global,
cur,
body,
persist )
Value:
char *global = svariable(#name, cur, &global, [] (ident *) { body; }, persist); /* assign variable, needs fxn prototype declared above */

◆ SVARFR

#define SVARFR ( name,
cur,
body )
Value:
SVARF_(name, name, cur, body, Idf_Override)

◆ SVARP

#define SVARP ( name,
cur )
Value:
SVAR_(name, name, cur, Idf_Persist)

◆ SVARR

#define SVARR ( name,
cur )
Value:
SVAR_(name, name, cur, Idf_Override)

◆ VAR

#define VAR ( name,
min,
cur,
max )
Value:
VAR_(name, name, min, cur, max, 0)

◆ VAR_

#define VAR_ ( name,
global,
min,
cur,
max,
persist )
Value:
int global = variable(#name, min, cur, max, &global, nullptr, persist)

◆ VARF

#define VARF ( name,
min,
cur,
max,
body )
Value:
VARF_(name, name, min, cur, max, body, 0)

◆ VARF_

#define VARF_ ( name,
global,
min,
cur,
max,
body,
persist )
Value:
int global = variable(#name, min, cur, max, &global, [] (ident *) { body; }, persist); /* assign variable, needs fxn prototype declared above */

◆ VARFN

#define VARFN ( name,
global,
min,
cur,
max,
body )
Value:
VARF_(name, global, min, cur, max, body, 0)

◆ VARFNP

#define VARFNP ( name,
global,
min,
cur,
max,
body )
Value:
VARF_(name, global, min, cur, max, body, Idf_Persist)

◆ VARFP

#define VARFP ( name,
min,
cur,
max,
body )
Value:
VARF_(name, name, min, cur, max, body, Idf_Persist)

◆ VARFR

#define VARFR ( name,
min,
cur,
max,
body )
Value:
VARF_(name, name, min, cur, max, body, Idf_Override)

◆ VARN

#define VARN ( name,
global,
min,
cur,
max )
Value:
VAR_(name, global, min, cur, max, 0)

◆ VARNP

#define VARNP ( name,
global,
min,
cur,
max )
Value:
VAR_(name, global, min, cur, max, Idf_Persist)

◆ VARNR

#define VARNR ( name,
global,
min,
cur,
max )
Value:
VAR_(name, global, min, cur, max, Idf_Override)

◆ VARP

#define VARP ( name,
min,
cur,
max )
Value:
VAR_(name, name, min, cur, max, Idf_Persist)

◆ VARR

#define VARR ( name,
min,
cur,
max )
Value:
VAR_(name, name, min, cur, max, Idf_Override)

Function Documentation

◆ addcommand()

bool addcommand ( const char * name,
identfun fun,
const char * narg = "",
int type = Id_Command )
extern

Registers a command in the Cubescript ident table.

The arguments of the function passed are cast away, so they are reconstructed using the char * string passed to narg.

Parameters
nameof the command in Cubescript
funa function pointer to be called when the command is executed
nargstring containing the arguments of the function
typethe type of the command to create

◆ checksleep()

void checksleep ( int millis)
extern

Processes the cubescript sleep queue.

At most, one sleep command is removed from the queue per cycle. Removes queued sleep commands as they expire, which stops CS commands from executing for a certain period of time.

Parameters
millisthe current timestamp

◆ clampvar()

int clampvar ( bool hex,
std::string name,
int i,
int minval,
int maxval )
extern

Modifies the value passed to fall within the boundaries passed.

Clamps the value i to within minval and maxval. If hex is passed, warns in hex mode, otherwise decimal. If the values are not within bounds, issued aformentioned warning, refering to the passed name in the console message.

Parameters
hextoggles whether to display hex warning instead of decimal
namethe name
ithe value to clamp
minvalthe lowest value to clamp to
maxvalthe largest value to clamp to
Returns
the clamped value

◆ clear_command()

void clear_command ( )
extern

Clears all aliases from the ident map.

All aliases, aka objects created from within CubeScript, have their contents (the names and code values associated with them) freed. Does not remove the ident object itself from the global ident map.

◆ escapeid()

const char * escapeid ( const char * s)

Escapes a string unless it is null.

If an empty string is passed, escapestring() is not called. Otherwise, the same behavior as in escapestring() is executed.

Parameters
sthe string to convert
Returns
a string containing the potentially applied escape changes

◆ escapestring()

const char * escapestring ( const char * s)
extern

Replaces C style excape characters with Cubescript ones.

The resulting string is also wrapped in quotes ("").

Parameters
sthe string to convert
Returns
a string containing the escaped changes

◆ execfile()

bool execfile ( const char * cfgfile,
bool msg = true )
extern

Executes the contents of the referenced file.

Parameters
cfgfilethe relative director of the file to execute
msgwhether to print to console a failure message
Returns
true if the file was successfully loaded
false if the file was not found

◆ execident()

int execident ( const char * name,
int noid = 0,
bool lookup = false )
extern

Executes the contents of an ident, searched by name.

Attempts to find in the ident table an ident with the given name, and if found executes it.

Parameters
namethe name of the ident to look for
noidthe value to return if no ident is found
lookupif a command, and parameters are of format 'N', sets to -1

◆ execute()

int execute ( const char * p)
extern

Executes the contents of the string passed.

Parses and executes the line of Cubescript given.

Parameters
pthe C string containing the code to execute
Returns
an int from the results of the execution

◆ floatret()

void floatret ( float v)
extern

Returns a float value from a Cubescript command.

When writing a CS command, this function returns a float value to the inheriting CS environment.

Parameters
vthe value to return

◆ fvariable()

float fvariable ( const char * name,
float min,
float cur,
float max,
float * storage,
identfun fun,
int flags )
extern

Registers a float variable in the Cubescript ident table.

Adds a float variable to the Cubescript ident table. The name of the Cubescript variable does not necessarily need to correspond to the C++ variable's name.

Parameters
namethe name of the aliased variable in Cubescript
minthe minimum value the variable can be set at
curthe starting value of the variable
maxthe maximum value the variable can be set at
storagethe pointer to the variable to be aliased to Cubescript
funa function pointer to be called upon modification of the variable
flagsthe handling flags for the variable
Returns
the value cur passed

◆ getident()

ident * getident ( const char * name)
extern

Returns the pointer to the ident object with the given CS alias.

Parameters
thename of the cubescript object to get
Returns
The address of the ident object.

◆ initidents()

bool initidents ( )
extern

Initializes the CubeScript preset argument idents.

Intitializes the argument parameters (arg1, arg2, ..., arg<Max_Args>) as CS ident objects. Required to use of $argN variables. Also initializes the dummy ident, //dummy.

Returns
always returns true

◆ intret()

void intret ( int v)
extern

Returns an integer value from a Cubescript command.

When writing a CS command, this function returns an integer value to the inheriting CS environment.

Parameters
vthe value to return

◆ parseint()

int parseint ( const char * s)
inline

Returns the string passed as an integer.

Parses the entire string, returning the value of the passed value as an integer. The value of this value will always be greater than zero unless there is an overflow beyond the size of int. The output may be converted by a trailing radix digit as described in strtoul.

Parameters
sthe string to turn into an integer

◆ printvar()

void printvar ( const ident * id,
int i )
extern

Prints out the formatted variable.

The param is intended to represent the value the ident object represents.

Parameters
idthe ident object to print out
ithe value to print out the variable equalling.

◆ result()

void result ( const char * s)
extern

Returns an alias' name from a Cubescript command.

When writing a CS command, this functions a string value representing the name of a Cubescript object to the inheriting CS environment.

Parameters
sthe name of the ident to return

◆ setfvar()

void setfvar ( const char * name,
float f,
bool dofunc = true,
bool doclamp = true )
extern

Sets a Cubescript float value to the given value.

Parameters
namethe name of the cubescript alias to change
ithe value to set
dofuncwhether to run the onchange function
doclampwhether to clamp the value to the specified limits

◆ setsvar()

void setsvar ( const char * name,
const char * str,
bool dofunc = true )
extern

Sets a Cubescript string value to the given value.

Parameters
namethe name of the cubescript alias to change
ithe value to set
dofuncwhether to run the onchange function

◆ setvar()

void setvar ( const char * name,
int i,
bool dofunc = true,
bool doclamp = true )
extern

Sets a Cubescript integer value to the given value.

Parameters
namethe name of the cubescript alias to change
ithe value to set
dofuncwhether to run the onchange function
doclampwhether to clamp the value to the specified limits

◆ stringret()

void stringret ( char * s)
extern

Returns a string value from a Cubescript command.

When writing a CS command, this function returns a string value to the inheriting CS environment.

Parameters
vthe value to return

◆ svariable()

char * svariable ( const char * name,
const char * cur,
char ** storage,
identfun fun,
int flags )
extern

Registers a C string variable in the Cubescript ident table.

Parameters
namethe name of the aliased variable in Cubescript
curthe starting value of the variable
storagethe pointer to the pointer to the variable to be aliased to Cubescript
funa function pointer to be called upon modification of the variable
flagsthe handling flags for the variable
Returns
the value cur passed

◆ variable()

int variable ( const char * name,
int min,
int cur,
int max,
int * storage,
identfun fun,
int flags )
extern

Registers an int variable in the Cubescript ident table.

Parameters
namethe name of the aliased variable in Cubescript
minthe minimum value the variable can be set at
curthe starting value of the variable
maxthe maximum value the variable can be set at
storagethe pointer to the variable to be aliased to Cubescript
funa function pointer to be called upon modification of the variable
flagsthe handling flags for the variable
Returns
the value cur passed

◆ writecfg()

void writecfg ( const char * savedconfig,
const char * autoexec = nullptr,
const char * defaultconfig = nullptr,
const char * name = nullptr )
extern

Writes out the state of the CubeScript idents to a file.

Parameters
savedconfigthe path to write to if name is nullptr
autoexecthe path for the autoexec file for user modification, for display in top of file comment
defaultconfigthe path for the master copy of the configuration file, for display in top of file comment
namethe path to write to, if nullptr savedconfig is used instead

Variable Documentation

◆ identflags

int identflags
extern

The flags to automatically set on ident objects

◆ triggerqueue

std::queue<ident *> triggerqueue
extern

A queue of game events for the engine to process