rename N in arglist to #

master
Daniel Kolesa 2021-04-29 04:15:16 +02:00
parent da7548664c
commit e52720ebb2
8 changed files with 15 additions and 15 deletions

View File

@ -301,7 +301,7 @@ struct LIBCUBESCRIPT_EXPORT state {
* * `b` - bytecode/block
* * `c` - condition (see below)
* * `r` - ident
* * `N` - number of real arguments passed up until now
* * `#` - number of real arguments passed up until now
* * `$` - self ident (the command, except for special hooks)
*
* For condition types, the type of the value is generally kept as is,
@ -342,13 +342,13 @@ struct LIBCUBESCRIPT_EXPORT state {
* printing or setting them using syntax `varname optional_vals` or using
* `varname = value`. Their type signature must always start with `$`
* and can be followed by any user types, generally you will also want
* to terminate the list with `N` to find out whether any values were
* to terminate the list with `#` to find out whether any values were
* passed.
*
* This way you can have custom handlers for printing as well as custom
* syntaxes for setting (e.g. your custom integer var handler may want to
* take up to 4 values to allow setting of RGBA color channels). When no
* arguments are passed (checked using `N`) you will want to print the
* arguments are passed (checked using `#`) you will want to print the
* value using a format you want. When using the `=` assignment syntax,
* one value is passed.
*

View File

@ -539,7 +539,7 @@ lookup_id:
gs.gen_val_ident(id);
++numargs;
break;
case 'N':
case '#':
gs.gen_val_integer(-1);
++numargs;
break;
@ -990,7 +990,7 @@ bool parser_state::parse_call_command(
gs.gen_val_ident(self);
++numargs;
break;
case 'N': /* number of arguments */
case '#': /* number of arguments */
gs.gen_val_integer(numargs - fakeargs);
++numargs;
break;
@ -1271,7 +1271,7 @@ static bool parse_assign_var(
ps.gs.gen_val_ident(var);
++nargs;
break;
case 'N':
case '#':
ps.gs.gen_val_integer(nargs);
++nargs;
break;

View File

@ -121,7 +121,7 @@ state::state(alloc_func func, void *data) {
/* default handlers for variables */
statep->cmd_ivar = &new_command("//ivar_builtin", "$iN", [](
statep->cmd_ivar = &new_command("//ivar_builtin", "$i#", [](
auto &cs, auto args, auto &
) {
auto &iv = static_cast<integer_var &>(args[0].get_ident(cs));
@ -134,7 +134,7 @@ state::state(alloc_func func, void *data) {
}
});
statep->cmd_fvar = &new_command("//fvar_builtin", "$fN", [](
statep->cmd_fvar = &new_command("//fvar_builtin", "$f#", [](
auto &cs, auto args, auto &
) {
auto &fv = static_cast<float_var &>(args[0].get_ident(cs));
@ -152,7 +152,7 @@ state::state(alloc_func func, void *data) {
}
});
statep->cmd_svar = &new_command("//svar_builtin", "$sN", [](
statep->cmd_svar = &new_command("//svar_builtin", "$s#", [](
auto &cs, auto args, auto &
) {
auto &sv = static_cast<string_var &>(args[0].get_ident(cs));
@ -599,7 +599,7 @@ LIBCUBESCRIPT_EXPORT command &state::new_command(
case 'f':
case 'a':
case 'c':
case 'N':
case '#':
case 's':
case 'b':
case 'r':

View File

@ -108,7 +108,7 @@ void exec_command(
i += 1;
args[i].set_ident(*self);
break;
case 'N':
case '#':
i += 1;
args[i].set_integer(integer_type(lookup ? -1 : i - fakeargs));
break;

View File

@ -172,7 +172,7 @@ LIBCUBESCRIPT_EXPORT void std_init_list(state &gcs) {
res.set_string(p.get_item());
});
new_cmd_quiet(gcs, "sublist", "siiN", [](auto &cs, auto args, auto &res) {
new_cmd_quiet(gcs, "sublist", "sii#", [](auto &cs, auto args, auto &res) {
integer_type skip = args[1].get_integer(),
count = args[2].get_integer(),
numargs = args[3].get_integer();

View File

@ -152,7 +152,7 @@ LIBCUBESCRIPT_EXPORT void std_init_string(state &cs) {
throw internal_error{"format error"};
});
new_cmd_quiet(cs, "substr", "siiN", [](auto &ccs, auto args, auto &res) {
new_cmd_quiet(cs, "substr", "sii#", [](auto &ccs, auto args, auto &res) {
std::string_view s = args[0].get_string(ccs);
auto start = args[1].get_integer(), count = args[2].get_integer();
auto numargs = args[3].get_integer();

View File

@ -59,7 +59,7 @@ int main(int argc, char **argv) {
});
/* takes a string so we can print it */
gcs.new_command("assert", "ssN", [](auto &s, auto args, auto &ret) {
gcs.new_command("assert", "ss#", [](auto &s, auto args, auto &ret) {
auto val = args[0];
val.force_code(s);
if (!s.run(val.get_code()).get_bool()) {

View File

@ -322,7 +322,7 @@ int main(int argc, char **argv) {
* work equivalently - in this case we want to allow multiple values
* to be set, but you may also not be using standard i/o and so on
*/
gcs.new_command("//ivar", "$iiiN", [](auto &css, auto args, auto &) {
gcs.new_command("//ivar", "$iii#", [](auto &css, auto args, auto &) {
auto &iv = static_cast<cs::integer_var &>(args[0].get_ident(css));
auto nargs = args[4].get_integer();
if (nargs <= 1) {