Reputation: 75
local users = {}
table.insert(users, {['uid']= 'xxx'})
How to insert object into table in Lua script. When I try to insert, Lua returns empty array, with empty array inside "[[]]".
table.insert(users, 'xxx')
When I insert string, it is properly returned. "['xxx']"
I'm running Lua inside redis. In node.
JavaScript example would be:
const arr = []
arr.push({uid: 'xxx'})
Upvotes: 3
Views: 5797
Reputation: 2205
try this method to get element : users[1].uid or users[1].['uid']
local users = {}
table.insert(users, { ['uid'] = 'xxx'})
table.insert(users, { uid = 'yyy'})
print(users[1].uid)
print(users[2].uid)
output:
xxx
yyy
Upvotes: 4