开发者

Dynamically assigned table variables?

开发者 https://www.devze.com 2022-12-18 13:54 出处:网络
Writing a function in Lua, which creates two tables. I want the tables to be assigned to the value name with an x added, and one with a y added. For example if name was line, it would create two table

Writing a function in Lua, which creates two tables. I want the tables to be assigned to the value name with an x added, and one with a y added. For example if name was line, it would create two tables linex and liney, but I can't figure out how to do it. The following obviously doesn't work (and is just for display purposes) but how would I go about doing this?

function makelinep(x,y,minr开发者_JS百科and,maxrand,name,length)
  name..x = {}
  name..y = {}

Later I hope to access "linex" and "liney" after values have been written.


If you want these in the global name space you would use

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

For a module you'd use _M in place of _G.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号