Dynamically assigned table variables?

Writing a function in Lua that creates two tables. I want the tables to be assigned a value name with the added x, and one with the addition of y. For example, if the name was a string, it would create two tables, linex and liney, but I cannot figure out how to do this. The following obviously do not work (and are for display only), but how would I do it?

function makelinep(x,y,minrand,maxrand,name,length)
  name..x = {}
  name..y = {}

Later, I hope to get access to "linex" and "liney" after the values ​​are written.

+3
source share
1 answer

If you want them to be in the global namespace, you would use

_G[name..'x']={}
_G[name..'y']={}

_M _G.

+5

Source: https://habr.com/ru/post/1730926/


All Articles