user805687
user805687

Reputation:

How can a variable be part of another variables name in lua?

I want to set dynamic variable names.

such as

function make(name)
local name..bar = "ipsum"
end

make(foo)   

this possible?

Upvotes: 0

Views: 192

Answers (1)

jpjacobs
jpjacobs

Reputation: 9559

For globals it's simply indexing like _G[name..bar]. For locals you could emulate this by setting all globals you use in a local table, and index that one. For an approach to really use a local, I can't help you.

Upvotes: 2

Related Questions