lua-users home
lua-l archive

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


* On Sun Mar 10 11:32:51 +0100 2013, 199 ini wrote:
 
> Such as:
>   T={element1, element2, element3,}
> Why the last comma is allowed?

This allows easier generating of valid source code. For example, writing
out an array in valid lua from C:

  int val[3] = { 10, 20, 30) }
  int i;
  
  printf("local list = { ";
  for(i=0; i<3; i++) {
  	printf("%d, ", val[i]);
  }
  printf("}\n");

results in

  local list = { 10, 20, 30, }

So there is no need for detecting the special case of the last element
and omitting the comma.

(As a side note: this last comma is one of my annoyances with
json/javascript, I have numerous times made the same error when trying
to call some http API with JSON which I generated from Lua)
-- 
:wq
^X^Cy^K^X^C^C^C^C