15 #include "../../bscript/berror.h" 16 #include "../../bscript/impstr.h" 17 #include "../../clib/clib.h" 18 #include "../../clib/random.h" 25 using namespace Module;
37 using namespace Bscript;
52 return new BError(
"RandomInt() expects a positive integer" );
56 return new BError(
"RandomInt() expects a positive integer" );
72 return new BError(
"RandomIntMinMax() expects an integer" );
75 return new BError(
"RandomIntMinMax() expects an integer" );
87 return new BError(
"RandomFloat() expects a Real parameter" );
98 if ( dice.
load( dicestr->
data(), &errormsg ) )
104 return new BError( errormsg.c_str() );
109 return new BError(
"RandomDiceRoll() expects a String as parameter" );
115 const String* format_string;
117 return new BError(
"No time string passed." );
118 else if ( format_string->
length() > 100 )
119 return new BError(
"Format string exceeded 100 characters." );
122 if ( !
getParam( 1, time_stamp, 0, INT_MAX ) )
128 if ( time_stamp <= 0 )
129 seconds = time(
nullptr );
131 seconds = time_stamp;
136 size_t len = format_string->
length();
137 const char* str = format_string->
data();
143 return new BError(
"Invalid Format string." );
173 return new BError(
"Invalid Format string." );
179 if ( strftime( buffer,
sizeof buffer, format_string->
data(), &time_struct ) > 0 )
180 return new String( buffer );
182 return new BError(
"Format string too long." );
std::vector< FunctionDef > FunctionTable
Bscript::BObjectImp * mf_RandomFloat()
unsigned short roll(void) const
std::tm localtime(const std::time_t &t)
threadsafe version of localtime
bool getParam(unsigned param, int &value)
Bscript::BObjectImp * mf_RandomInt()
Bscript::BObjectImp * mf_RandomDiceRoll()
UtilExecutorModule(Bscript::Executor &exec)
bool getRealParam(unsigned param, double &value)
Bscript::BObjectImp * mf_RandomIntMinMax()
const String * getStringParam(unsigned param)
Bscript::BObjectImp * mf_StrFormatTime()
const String * getStringParam(unsigned param)
int random_int_range(int minI, int maxI)
double random_double(double f)
bool load(const char *dice, std::string *errormsg)
const char * data() const
bool getParam(unsigned param, int &value)