lua-users home
lua-l archive

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


On Thu, Jan 20, 2011 at 9:19 PM, Tang Daogang <daogangtang@gmail.com> wrote:
> anybody has done the work: support '//' ( or '#' )  as lua's one line
> comment identifier? Like it's original '--' .

This should do that:

--- lua-5.1.4/src/llex.c
+++ lua-5.1.4-comment//src/llex.c
@@ -357,6 +357,14 @@
           next(ls);
         continue;
       }
+      case '/': {
+        next(ls);
+        if (ls->current != '/') return '/';
+        /* else short comment */
+        while (!currIsNewline(ls) && ls->current != EOZ)
+          next(ls);
+        continue;
+      }
       case '[': {
         int sep = skip_sep(ls);
         if (sep >= 0) {

Example:

  > print(1/2) // 3
  0.5

Most would probably not recommend that though.  The standard '--'
works just fine after all.  Using '#' as a comment character is
problematic in Lua because Lua already uses it as a table length
operator:

  > return # {1,2}

BTW, I'm not entirely fond of Lua's "linenoise" block comments --[=[
]=] relative to [1].

[1] http://en.wikipedia.org/wiki/Comparison_of_programming_languages_(syntax)#Block_comments