Hi everybody,
Does anyone know how to rename a table name with a string that you define earlier in a script?
local tab1={}
local myString ="mystrtable"
--here this string will be changed in script with other string so I want to have a dynamic table name.
--[[
how to rename tab1 with the value of myString ???
]]--
I don't think you can rename a table after you have created it, if you can, someone will correct me.
I would suggest creating a new table with the appropriate name, copying the data from the original to the new table, then setting the original table to nil, so it gets GC'd.
Just add a name field to your table.
1
2
3
| tab1 = {}
...
tab1.name = "mystrtable" |
I think this is what you want to accomplish :
1
2
3
4
5
6
7
| Lua 5.1.4 Copyright (C) 1994-2008 Lua.org, PUC-Rio
> table = {test = "value"}
> str = "myString"
> func = assert(loadstring(str .. "= table"))
> func()
> print(myString.test)
value |
i think loadstring is disabled in corona.
views:1589 update:2011/10/5 21:23:48