lua-users home
lua-l archive

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


Is this way to protect a global table a problem? garbage collector/waste
of memory... if function dummy is called very often?

a) it must be a global table
b) it must be filled with new data inside of a function
c) after the function the original data must be available


   data = {day='Sunday'}
   print(data.day)  --> Sunday

   function dummy()
      data,memorize = {day='Monday'},data
      print(data.day)  --> Monday
      data=memorize
   end

   print(data.day)  --> Sunday

I don't like to use this stupid way:

   function dummy()
      local memorizeday = data.day
      data.day='Monday'
      print(data.day) --> Monday
      data.day=memorizeday
   end

And also I don't like to copy the whole table in a for end loop.

Another way? Thanks for your help. Lua is wonderfull!

--
Markus