动态分配的表变量? [英] Dynamically assigned table variables?

查看:73
本文介绍了动态分配的表变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Lua中编写一个函数,该函数将创建两个表.我希望将表分配给具有x的值名称,以及具有y的值名称.例如,如果name是line,它将创建两个表linex和liney,但是我不知道该怎么做.以下内容显然不起作用(仅用于显示目的),但是我将如何去做呢?

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,minrand,maxrand,name,length)
  name..x = {}
  name..y = {}

稍后我希望在写入值后访问"linex"和"liney".

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']={}

对于模块,您可以使用_M代替_G.

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

这篇关于动态分配的表变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆