lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Hello, l-lua.

TL;DR: I do 2 proposals, this is the first. Add parenthesis-less
function calls for `nil`/`true`/`false` and `<number>`.

I guess I should give reasoning: It is a simple conveniance.
Calling `os.exit(true)` looks normal and no problem with that.
Calling `os.exit true` looks pretty much the same, but might seem more
easy on the eye to some.

However, where this would really shine are config scripts.
They tend to look more command like, which it would benefit from:
--
section "name"
    version 4
    use_preload false
--

So instead of having all strings, which need error prone parsing at
runtime, we can have them somewhat typesafe at compile-time.

Constant generation could also benefit from this: (bad example but you
might get it)
`local quater_angle <const> = deg 90`
which would also allow for prefix units (tbh I like this one, now that I
write it.)

Maybe also embedded?
`led[8] true`

The only thing I am not sure about is if `nil` should be supported.
It does not hurt... and thats the only reason its in this proposal.

The patch is rather small:

--- lua-5.4.4/src/lparser.c
+++ lua-5.4.4-call/src/lparser.c|
@@ -1047,6 +1047,33 @@
       luaX_next(ls);  /* must use 'seminfo' before 'next' */
       break;
     }
+    case TK_FLT: {  /* funcargs -> FLT */
+      init_exp(&args, VKFLT, 0);
+      args.u.nval = ls->t.seminfo.r;
+      luaX_next(ls);  /* must use 'seminfo' before 'next' */
+      break;
+    }
+    case TK_INT: {  /* funcargs -> INT */
+      init_exp(&args, VKINT, 0);
+      args.u.ival = ls->t.seminfo.i;
+      luaX_next(ls);  /* must use 'seminfo' before 'next' */
+      break;
+    }
+    case TK_TRUE: {  /* funcargs -> TRUE */
+      init_exp(&args, VTRUE, 0);
+      luaX_next(ls);  /* must use 'seminfo' before 'next' */
+      break;
+    }
+    case TK_FALSE: {  /* funcargs -> FALSE */
+      init_exp(&args, VFALSE, 0);
+      luaX_next(ls);  /* must use 'seminfo' before 'next' */
+      break;
+    }
+    case TK_NIL: {  /* funcargs -> NIL */
+      init_exp(&args, VNIL, 0);
+      luaX_next(ls);  /* must use 'seminfo' before 'next' */
+      break;
+    }
     default: {
       luaX_syntaxerror(ls, "function arguments expected");
     }
@@ -1125,7 +1152,9 @@
         funcargs(ls, v, line);
         break;
       }
-      case '(': case TK_STRING: case '{': {  /* funcargs */
+      case TK_NIL: case TK_TRUE: case TK_FALSE:
+      case TK_STRING: case TK_INT: case TK_FLT:
+      case '(': case '{': {  /* funcargs */
         luaK_exp2nextreg(fs, v);
         funcargs(ls, v, line);
         break;