On Fri, Jan 21, 2011 at 11:24 AM, David Manura
<dm.lua@math2.org> wrote:
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
Works fine! It is originally not a difficult thing. Thank you.
Most would probably not recommend that though. The standard '--'
works just fine after all.
Emm, I understand. Just for our habits.
Using '#' as a comment character is
problematic in Lua because Lua already uses it as a table length
operator:
> return # {1,2}
Yes. Comparing to '#', I prefer '//'.
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