Using strings to call tables

Hello, I am having some trouble using a string that changes values to call the different tables with those values as their names.

For example ,

Local tablename = 123
Table.remove(tablename,50,12)

I need this to work because my tablenames are part string part variable . For example table.remove(“tablename” … Value,50,12)

@archistudent is this something like what you are after:

s=[[print("hello world")]]
loadstring(s)()
--prints "hello world"

loadstring basically executes code in a string that is passed to it

Edit: got it now

t={}
    t[1]="an entry in t"
    f={}
    f[1]="first entry in f"
    varname="t"
    a=loadstring("return "..varname)()
    print(a[1])--prints 'an entry in t,
    varname="f"
    a=loadstring("return "..varname)()
    print(a[1])--prints 'first entry in t'

Or maybe put all your tables in an a table and access them with a string

a={"data"}
    b={"more data"}
    t={}
    t["a"]=a
    t["b"]=b
    print(t["a"][1])

Edit:
Try this article

http://www.lua.org/pil/14.1.html

@archistudent you’re welcome(hint,hint)

Edit: sorry to be rude

@archistudent Here’s a routine to remove an entry from a variable table name. I think this is what you were showing above. The function “remove” does all the work, everything else are just examples to show how it works.


function setup()
    -- example tables
    circle123={88,54,67,32,16,78}
    circle554={76,54,63,23,41,94}
    square999={23,45,67,21,89,46}
    
    -- remove 3rd entry from table circle123
    -- print before
    print(table.concat(circle123," "))
    -- remove entry
    remove("circle",123,3)
    -- print after
    print(table.concat(circle123," "))
    
    print()
    
    -- remove 2nd entry from table circle554
    -- print before
    print(table.concat(circle554," "))
    -- remove entry
    remove("circle",554,2)
    -- print after
    print(table.concat(circle554," "))
    
    print()
    
    -- remove 5th entry from table square999
    -- print before
    print(table.concat(square999," "))
    -- remove entry
    remove("square",999,5)
    -- print after
    print(table.concat(square999," "))
end


-- remove entry from variable table name
function remove(tab,ext,pos)
    str=string.format("table.remove(%s%d,%d)",tab,ext,pos)
    a=loadstring(str)
    a()   
end

@archistudent The function “remove” above can be reduced to what I have below.


-- remove entry from variable table name

function remove(tab,ext,pos)
    loadstring(string.format("table.remove(%s%d,%d)",tab,ext,pos))()
end

No need for loadstring in this. If your tables are global then you can refer to them via tye _G table.

table.remove(_G[tablename],pos)

Hello everybody, Thanks for your help , sorry I had missed my own post and did not come check it til now.

Special thanks @coder

Woa triple post