/** * [Number] = [other] * * Returns True if the number equals the other number. */ ctr_object* ctr_number_eq(ctr_object* myself, ctr_argument* argumentList) { ctr_object* otherNum = ctr_internal_cast2number(argumentList->object); return ctr_build_bool(myself->value.nvalue == otherNum->value.nvalue); }
/** * [String] toNumber * * Converts string to a number. */ ctr_object* ctr_string_to_number(ctr_object* myself, ctr_argument* argumentList) { return ctr_internal_cast2number(myself); }
/** * [Dice] rollWithSides: [Number] * * Rolls the dice, generates a pseudo random number. */ ctr_object* ctr_dice_sides(ctr_object* myself, ctr_argument* argumentList) { ctr_object* arg = ctr_internal_cast2number(argumentList->object); return ctr_build_number_from_float( (ctr_number) (rand() % ((int)arg->value.nvalue))); }
/** * [Clock] wait * * Waits X seconds. */ ctr_object* ctr_clock_wait(ctr_object* myself, ctr_argument* argumentList) { ctr_object* arg = ctr_internal_cast2number(argumentList->object); int n = (int) arg->value.nvalue; sleep(n); return myself; }
/** * [Command] argument: [Number] * * Obtains an argument from the CLI invocation. */ ctr_object* ctr_command_argument(ctr_object* myself, ctr_argument* argumentList) { ctr_object* numberObject = ctr_internal_cast2number(argumentList->object); int n = (int) numberObject->value.nvalue; if (n >= ctr_argc || n < 0) return CtrStdNil; return ctr_build_string(ctr_argv[n], strlen(ctr_argv[n])); }