loading a table from a string?

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
Mr. Strange
Party member
Posts: 101
Joined: Mon Aug 11, 2008 5:19 am

loading a table from a string?

Post by Mr. Strange »

Alright, I want to do the following:

Code: Select all

x = "temp"
temp = {1,2,3}

function silly(t)
for i,v in pairs(t) do something end
end
I want to pass x to my function, and have it call the function on table temp. That is, I want to take a string, and find a table with that name. Maybe use loadstring() ? gettable ? I've tried a few random things with no success.

--Mr. Strange
User avatar
Dr. Magnusson
Prole
Posts: 22
Joined: Sun Jul 20, 2008 6:10 pm

Re: loading a table from a string?

Post by Dr. Magnusson »

I'd suggest using _G[t], provided the table is global.
Mr. Strange
Party member
Posts: 101
Joined: Mon Aug 11, 2008 5:19 am

Re: loading a table from a string?

Post by Mr. Strange »

Just that easy! It totally worked.

--Mr. Strange
Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests