lua-users home
lua-l archive

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


On 2012-01-17 15:29, Sandeep Ghai wrote:
Hello Everyone,
I am learning Lua starting from the basics. I am right now doing with
'Tables'.
But I am stuck at some point. I have read upto the tables  having two
columns. Can anybody help me in making table that has more than two coulmns?
like:

*Sr.No     x        y       Constraint     force*
1            0        0         fixed
-
2            0        120      free           sideway
3           120     120       free           twist
4           120      0        fixed             -



I tried with Nested tables,but get nothing. Is nested table a good option?
Thank you in advance.

This is a matrix (2D table). The two canonical ways to store
matrices are row-major order:


{ {"Sr.No","x","y","Constraint","force"},
  {1,0,0,"fixed","-"},
  {2,0,120,"free","sideway"},
  {3,120,120,"free","twist"},
  {4,120,0,"fixed","-"} }

and column-major order:

{ {"Sr.No",1,2,3,4},
  {"x",0,0,120,120},
  {"y",0,120,120,0},
  {"Constraint","fixed","free","free","fixed"},
  {"force","-","sideway","twist","-"} }

In this case it may be better to denormalize though:

{
  {
    ["Sr.No"] = 1,
    x = 0,
    y = 0,
    Constraint = "fixed",
    force = "-",
  },
  {
    ["Sr.No"] = 2,
    x = 0,
    y = 120,
    Constraint = "free",
    force = "sideway",
  },
  -- and so on
}

--
Pierre CHapuis